:root {
  --navy: #0b2a5b;
  --navy-deep: #071e42;
  --navy-soft: #1b3f78;
  --gold: #c4a04a;
  --gold-soft: #e7d3a1;
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #1a2233;
  --muted: #6b7684;
  --line: #e4e8ee;
  --danger: #c0392b;
  --success: #1e7d5a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 42, 91, .06), 0 6px 20px rgba(11, 42, 91, .07);
  --shadow-lg: 0 12px 40px rgba(11, 42, 91, .18);
  --maxw: 620px;
  --fs: 1;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Font-size scaling (accessibility). OB viewers default to "大". */
body.fs-base { --fs: 1; }
body.fs-lg { --fs: 1.18; }
body.fs-xl { --fs: 1.36; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
#app { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; background: var(--bg); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 13px 18px;
  font-size: calc(15px * var(--fs)); font-weight: 600; line-height: 1;
  transition: transform .05s ease, background .2s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btn--primary { background: var(--navy); color: #fff; }
.btn--primary:hover { background: var(--navy-soft); }
.btn--block { width: 100%; }
.btn--ghost { background: #eef1f6; color: var(--navy); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger-ghost { background: #fbecea; color: var(--danger); }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: transparent; color: #fff;
}
.iconbtn svg { width: 22px; height: 22px; }
.detailbar .iconbtn { color: var(--navy); background: #eef1f6; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(120% 80% at 50% -10%, #17407e 0%, var(--navy) 45%, var(--navy-deep) 100%);
}
.login__card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 22px; padding: 40px 28px 28px; text-align: center;
  box-shadow: var(--shadow-lg);
}
.login__crest {
  width: 66px; height: 66px; margin: 0 auto 18px; border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--navy-soft), var(--navy));
  color: var(--gold-soft); font-weight: 800; font-size: calc(26px * var(--fs)); letter-spacing: 1px;
  box-shadow: inset 0 0 0 2px rgba(196,160,74,.5);
}
.login__title { margin: 0; font-size: calc(22px * var(--fs)); font-weight: 800; letter-spacing: .04em; }
.login__sub { margin: 4px 0 26px; color: var(--muted); font-size: calc(14px * var(--fs)); }
.login__form { text-align: left; }
.login__note { margin: 20px 0 0; font-size: calc(12px * var(--fs)); color: var(--muted); line-height: 1.7; }

/* ---------- Fields ---------- */
.field { display: block; margin-bottom: 14px; }
.field__label { display: block; font-size: calc(12.5px * var(--fs)); font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field__label em { color: var(--danger); font-style: normal; font-size: calc(11px * var(--fs)); margin-left: 4px; }
.input {
  width: 100%; padding: 12px 14px; font-size: calc(16px * var(--fs)); color: var(--ink);
  background: #f6f8fb; border: 1.5px solid var(--line); border-radius: 12px;
  transition: border .15s, background .15s;
}
.input:focus { outline: none; border-color: var(--navy-soft); background: #fff; }

/* password show/hide toggle */
.password-field { position: relative; }
.password-field .input { padding-right: 48px; }
.password-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border: 0; background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center; border-radius: 9px;
}
.password-toggle:hover { color: var(--navy); background: #eef1f6; }
.password-toggle svg { width: 20px; height: 20px; }
.input--area { resize: vertical; min-height: 52px; line-height: 1.6; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%236b7684' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px; }
.check { display: flex; align-items: center; gap: 10px; font-size: calc(15px * var(--fs)); padding: 6px 0 2px; }
.check input { width: 20px; height: 20px; accent-color: var(--navy); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy) 62%, var(--navy-deep) 100%);
  color: #fff; padding: calc(var(--safe-top) + 12px) 16px 12px;
  box-shadow: 0 4px 16px rgba(7, 30, 66, .22);
}
.topbar__row { display: flex; align-items: center; justify-content: space-between; }
.topbar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar__actions { display: flex; align-items: center; gap: 2px; flex: none; }
.fontbtn { flex-direction: column; gap: 0; line-height: 1; }
.fontbtn span { font-size: calc(17px * var(--fs)); font-weight: 700; }
.fontbtn small { font-size: 9px; opacity: .75; margin-top: 1px; }
.topbar__crest {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.08); color: var(--gold-soft);
  font-weight: 800; font-size: calc(16px * var(--fs)); letter-spacing: .5px;
  box-shadow: inset 0 0 0 1.5px rgba(196,160,74,.5);
}
.topbar__title { font-size: calc(17px * var(--fs)); font-weight: 700; letter-spacing: .02em; }
.topbar__sub { font-size: calc(12px * var(--fs)); opacity: .7; }

.segment {
  display: flex; gap: 4px; margin-top: 14px; padding: 4px;
  background: rgba(255,255,255,.1); border-radius: 12px;
}
.segment__item {
  flex: 1; text-align: center; padding: 9px 0; border-radius: 9px;
  font-size: calc(14px * var(--fs)); font-weight: 600; color: rgba(255,255,255,.82); transition: .2s;
}
.segment__item.is-active { background: #fff; color: var(--navy); box-shadow: 0 2px 6px rgba(0,0,0,.12); }

.searchbar { position: relative; margin-top: 12px; }
.searchbar__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; }
.searchbar__icon svg { width: 18px; height: 18px; }
.searchbar__input {
  width: 100%; padding: 11px 14px 11px 40px; font-size: calc(15px * var(--fs));
  border: 0; border-radius: 11px; background: #fff; color: var(--ink);
}
.searchbar__input:focus { outline: 2px solid var(--gold); }

.chips { display: flex; gap: 8px; margin-top: 12px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 20px; border: 1px solid rgba(255,255,255,.28);
  background: rgba(255,255,255,.08); color: #fff; font-size: calc(12.5px * var(--fs)); font-weight: 600; white-space: nowrap;
}
.chip.is-active { background: var(--gold); border-color: var(--gold); color: #3a2c06; }

/* ---------- List ---------- */
.list { padding: 14px 14px calc(96px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 10px; }
.group__head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: calc(13px * var(--fs)); font-weight: 700; color: var(--navy);
  margin: 14px 4px 2px; padding-bottom: 6px; border-bottom: 2px solid var(--gold-soft);
}
.group__head span { font-size: calc(11px * var(--fs)); color: var(--muted); font-weight: 600; }

.card {
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; box-shadow: var(--shadow); transition: transform .06s, box-shadow .2s;
}
.card:active { transform: scale(.99); }
.card__avatar {
  width: 46px; height: 46px; flex: none; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #23508f, var(--navy)); color: #fff;
  font-size: calc(20px * var(--fs)); font-weight: 700;
}
.card__body { flex: 1; min-width: 0; }
.card__name { font-size: calc(16px * var(--fs)); font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.card__blood { font-size: calc(10.5px * var(--fs)); font-weight: 700; color: var(--navy); background: #eaf0f9; border-radius: 6px; padding: 1px 6px; }
.card__sub { font-size: calc(12.5px * var(--fs)); color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.card__chev { color: #c3ccd7; font-size: calc(22px * var(--fs)); flex: none; }

.badge {
  font-size: calc(10.5px * var(--fs)); font-weight: 700; padding: 3px 8px; border-radius: 20px;
  background: #eef1f6; color: var(--navy-soft);
}
.badge--role { background: var(--navy); color: #fff; }
.badge--gold { background: #f6edd6; color: #7a5c14; }
.badge--plain { background: #eef1f6; color: var(--muted); }

/* ---------- FAB ---------- */
.fab {
  position: fixed; z-index: 30;
  right: max(18px, calc(50% - var(--maxw)/2 + 18px));
  bottom: calc(20px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  background: var(--gold); color: #3a2c06; box-shadow: 0 8px 24px rgba(150,116,30,.4);
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.95); }

/* ---------- Detail ---------- */
.detailbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.9); backdrop-filter: saturate(180%) blur(12px);
  padding: calc(var(--safe-top) + 8px) 12px 8px; border-bottom: 1px solid var(--line);
}
.detailbar__title { font-size: calc(16px * var(--fs)); font-weight: 700; }
.detail { padding: 0 14px calc(40px + var(--safe-bottom)); }
.profile { text-align: center; padding: 26px 0 20px; }
.profile__avatar {
  width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 26px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #23508f, var(--navy)); color: #fff;
  font-size: calc(38px * var(--fs)); font-weight: 700; box-shadow: var(--shadow);
}
.profile__name { margin: 0; font-size: calc(24px * var(--fs)); font-weight: 800; letter-spacing: .02em; }
.profile__badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.profile__stat { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin-top: 12px; color: var(--muted); font-size: calc(12.5px * var(--fs)); }
.profile__stat span { position: relative; }

.detail__card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.detail__row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.detail__row:last-child { border-bottom: 0; }
.detail__label { font-size: calc(12.5px * var(--fs)); color: var(--muted); font-weight: 600; padding-top: 1px; }
.detail__value { font-size: calc(14.5px * var(--fs)); word-break: break-word; }
.detail__value--multiline { white-space: pre-wrap; }
.detail__link { display: inline-flex; align-items: center; gap: 7px; color: var(--navy-soft); font-weight: 600; }
.detail__link svg { width: 16px; height: 16px; flex: none; color: var(--gold); }
.detail__actions { display: flex; gap: 10px; margin-top: 18px; }
.detail__actions .btn { flex: 1; }

/* ---------- Form ---------- */
.form-wrap { padding: 14px 14px calc(40px + var(--safe-bottom)); }
.form__group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 15px 4px; margin-bottom: 14px; box-shadow: var(--shadow); }
.form__group-title { font-size: calc(12px * var(--fs)); font-weight: 800; color: var(--gold); letter-spacing: .08em; margin-bottom: 10px; }
.form__actions { margin-top: 6px; }

/* ---------- Utilities ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: calc(14px * var(--fs)); }
.loading { display: flex; justify-content: center; padding: 70px 0; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 100; max-width: 88%; padding: 12px 20px; border-radius: 12px;
  background: #2b3444; color: #fff; font-size: calc(14px * var(--fs)); font-weight: 600;
  box-shadow: var(--shadow-lg); animation: toastIn .2s ease;
}
.toast--error { background: var(--danger); }
.toast--success { background: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(10,20,40,.5); backdrop-filter: blur(2px); }
.modal__card { width: 100%; max-width: 340px; background: #fff; border-radius: 18px; padding: 24px 22px 18px; box-shadow: var(--shadow-lg); }
.modal__msg { margin: 0 0 20px; font-size: calc(15px * var(--fs)); line-height: 1.6; text-align: center; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }

/* ---------- Photo avatars ---------- */
.card__avatar, .profile__avatar { overflow: hidden; }
.card__avatar img, .profile__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photo-edit { display: flex; align-items: center; gap: 16px; padding-bottom: 10px; }
.photo-edit__preview {
  width: 88px; height: 88px; flex: none; border-radius: 24px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #23508f, var(--navy));
  color: #fff; font-size: calc(38px * var(--fs)); font-weight: 700;
}
.photo-edit__preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-edit__actions { display: flex; flex-direction: column; gap: 8px; }
.photo-edit__pick { cursor: pointer; margin: 0; }

@media (min-width: 640px) {
  #app { box-shadow: 0 0 60px rgba(11,42,91,.08); }
}

/* ==================== Desktop layout (wide screens) ==================== */
@media (min-width: 860px) {
  :root { --maxw: 1080px; }
  #app { min-height: 100vh; }

  /* Header: brand + controls laid out across the full width */
  .topbar { padding: 18px 28px 16px; }
  .topbar__title { font-size: calc(19px * var(--fs)); }
  .topbar__controls {
    display: flex; align-items: center; gap: 16px; margin-top: 16px;
  }
  .topbar__controls .segment { flex: 0 0 300px; margin-top: 0; }
  .topbar__controls .searchbar { flex: 1; margin-top: 0; max-width: 560px; }
  .chips { margin-top: 14px; }

  /* Member list becomes a responsive card grid */
  .list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px; align-content: start; padding: 20px 28px 40px;
  }
  .group__head { grid-column: 1 / -1; margin-top: 18px; }
  .empty { grid-column: 1 / -1; }

  /* Subtle hover affordance on pointer devices */
  .card:hover { box-shadow: 0 6px 24px rgba(11,42,91,.13); transform: translateY(-2px); }
  .segment__item, .chip, .btn, .iconbtn { transition: all .18s ease; }

  /* Detail & form keep a comfortable reading column, centred */
  .detailbar, .detail, .form-wrap {
    max-width: 720px; margin-left: auto; margin-right: auto;
  }
  .detailbar { padding: 12px 8px; }
  .detail { padding-top: 8px; }
  .profile { padding-top: 32px; }
  .profile__avatar { width: 104px; height: 104px; border-radius: 30px; }

  /* Floating add button sits at the content column's edge */
  .fab { width: 60px; height: 60px; }
}

/* Two-pane feel on very wide screens: detail/form as a centred sheet */
@media (min-width: 1240px) {
  :root { --maxw: 1200px; }
}
