/* 色・寸法・光・文字の定義元。生値はここだけに置く。 */
:root {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color-scheme: light;
  --bg: #f8f8f5; --surface: #fff; --soft: #f0f2ee; --ink: #26332b;
  --muted: #58695f; --line: #e0e6df; --accent: #286f52; --accent-ink: #fff;
  --accent-soft: #e5f2e9; --danger: #a53f3f; --collection-bg: #ecefea;
  /* 写真の台紙。src/services/photo.js の PHOTO_MAT と同じ色に保つ。 */
  --photo-mat: #e9eae6;
  --photo-bg: var(--photo-mat);
  --mark: #c4496c;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 22px; --space-6: 32px;

  --radius-sm: 10px; --radius-md: 14px; --radius-lg: 17px;
  --radius-xl: 21px; --radius-2xl: 24px; --radius-pill: 999px;

  --text-2xs: 11px; --text-xs: 13px; --text-sm: 14px; --text-md: 16px;
  --text-lg: 19px; --text-xl: 22px; --text-2xl: clamp(27px, 7vw, 39px);

  --w-regular: 400; --w-medium: 600; --w-bold: 800;

  /* 明るい面の上では影で層を作る。 */
  --elev-1: 0 1px 2px rgb(39 57 40 / 5%);
  --elev-2: 0 2px 8px rgb(39 57 40 / 7%);
  --elev-3: 0 10px 30px rgb(39 57 40 / 13%);
  --shadow: var(--elev-2);
}

/* 暗い面の上に黒い影は見えない。奥行きは面の明度差と上端1pxの光で作る。 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #171c19; --surface: #2b332e; --soft: #303934; --ink: #f0f4ef;
    --muted: #b6c6b9; --line: #415048; --accent: #8ad5a8; --accent-ink: #14241a;
    --accent-soft: #30483a; --danger: #ffaaa3; --collection-bg: #1a211d;
    --photo-bg: #1e2420;
    --mark: #ef7f9c;
    --elev-1: inset 0 1px 0 rgb(255 255 255 / 5%);
    --elev-2: inset 0 1px 0 rgb(255 255 255 / 6%), 0 4px 14px rgb(0 0 0 / 40%);
    --elev-3: inset 0 1px 0 rgb(255 255 255 / 7%), 0 14px 36px rgb(0 0 0 / 55%);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171c19; --surface: #2b332e; --soft: #303934; --ink: #f0f4ef;
  --muted: #b6c6b9; --line: #415048; --accent: #8ad5a8; --accent-ink: #14241a;
  --accent-soft: #30483a; --danger: #ffaaa3; --collection-bg: #1a211d;
  --photo-bg: #1e2420;
  --mark: #ef7f9c;
  --elev-1: inset 0 1px 0 rgb(255 255 255 / 5%);
  --elev-2: inset 0 1px 0 rgb(255 255 255 / 6%), 0 4px 14px rgb(0 0 0 / 40%);
  --elev-3: inset 0 1px 0 rgb(255 255 255 / 7%), 0 14px 36px rgb(0 0 0 / 55%);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); line-height: 1.45; letter-spacing: .01em; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:focus-visible, input:focus-visible, .choice:focus-within, .photo-picker:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: var(--text-2xl); line-height: 1.2; margin-bottom: var(--space-3); font-weight: var(--w-bold); text-wrap: balance; }
h2 { font-size: var(--text-lg); margin-bottom: var(--space-3); font-weight: var(--w-bold); text-wrap: balance; }
p { line-height: 1.6; text-wrap: pretty; }
/* 起動直後の素の段落。JSが最初の描画をするまでの数十msだけ見える。 */
.boot { padding: var(--space-5); color: var(--muted); }
.shell { max-width: 1050px; margin: auto; padding: 0 var(--space-3) 120px; }
.topbar { position: relative; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); min-height: 64px; margin-bottom: var(--space-2); background: var(--bg); }
.brand { font-weight: var(--w-bold); font-size: var(--text-md); white-space: nowrap; }
.user-badge { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--elev-1); font-size: var(--text-sm); font-weight: var(--w-medium); white-space: nowrap; }
.user-badge-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.user-badge-icon svg { width: 21px; height: 21px; }
.header-actions { display: flex; gap: var(--space-1); align-items: center; }
.theme-button, .text-back, .quiet-button { border: 0; background: transparent; }
.theme-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.theme-button svg { width: 23px; height: 23px; }
.theme-menu { position: fixed; top: 61px; right: max(12px, calc((100vw - 1050px) / 2)); z-index: 30; display: grid; gap: var(--space-1); min-width: 180px; padding: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--elev-3); }
.theme-menu button { border: 0; background: transparent; min-height: 44px; border-radius: var(--radius-sm); text-align: left; padding: var(--space-2) var(--space-3); }
.theme-menu button[aria-pressed="true"] { background: var(--accent-soft); font-weight: var(--w-bold); }
.notice { position: fixed; z-index: 40; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 54px + var(--space-4)); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - var(--space-6)); background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin: 0; font-weight: var(--w-medium); pointer-events: none; box-shadow: var(--elev-3); }
.notice.error { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); }
/* 新しい版が待機していることを伝える。押すまで何も入れ替わらない。 */
.update-banner { position: fixed; z-index: 45; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 54px + var(--space-4)); transform: translateX(-50%); display: flex; align-items: center; gap: var(--space-3); min-height: 48px; max-width: calc(100% - var(--space-6)); padding: var(--space-2) var(--space-4); border: 1px solid var(--accent); border-radius: var(--radius-pill); background: var(--surface); color: var(--ink); font-size: var(--text-sm); font-weight: var(--w-medium); box-shadow: var(--elev-3); }
.update-banner b { color: var(--accent); font-weight: var(--w-bold); white-space: nowrap; }
.update-banner:disabled { opacity: .6; }
.intro, .muted { color: var(--muted); }
.eyebrow { color: var(--accent); font-size: var(--text-xs); font-weight: var(--w-bold); margin-bottom: var(--space-2); }
.text-back { min-height: 44px; padding: 0; color: var(--accent); font-weight: var(--w-bold); }

/* 初回の家族選択 */
.hero { padding: var(--space-5) var(--space-5); background: var(--accent-soft); border-radius: var(--radius-2xl); margin-bottom: var(--space-5); }
.hero p { margin-bottom: 0; color: var(--muted); }
.family-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.family-card { min-height: 145px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); font-size: var(--text-lg); font-weight: var(--w-medium); box-shadow: var(--elev-2); }
.avatar { font-size: 42px; }

/* 置き場所とカテゴリ棚 */
.page-list .topbar { position: sticky; top: 0; margin-bottom: 0; }
.place-switch { position: sticky; top: 64px; z-index: 19; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); margin-bottom: var(--space-3); padding: 5px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--elev-2); isolation: isolate; }
.place-switch::before { content: ""; position: absolute; z-index: -1; top: 5px; bottom: 5px; left: 5px; width: calc((100% - 14px) / 2); border-radius: var(--radius-md); background: var(--accent); box-shadow: var(--elev-2); transform: translateX(0); }
.place-switch[data-location="storage"]::before { transform: translateX(calc(100% + var(--space-1))); background: var(--soft); }
.place-tab { position: relative; min-height: 49px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--muted); font-weight: var(--w-medium); }
.place-tab.active { color: var(--accent-ink); }
.place-switch[data-location="storage"] .place-tab.active { color: var(--ink); }
.closet-stage { display: grid; grid-template-columns: 66px minmax(0, 1fr); gap: var(--space-3); align-items: start; }
.category-sidebar { position: sticky; top: 136px; display: grid; gap: 3px; max-height: calc(100dvh - 225px); overflow-y: auto; padding: 5px var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); scrollbar-width: none; }
.category-sidebar::-webkit-scrollbar { display: none; }
.category-tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 64px; padding: 5px 2px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--muted); }
.category-tab svg { width: 26px; height: 26px; }
.category-tab span { font-size: var(--text-2xs); font-weight: var(--w-medium); line-height: 1.15; }
.category-tab small { position: absolute; top: var(--space-1); right: var(--space-1); min-width: 16px; padding: 0 3px; border-radius: var(--radius-sm); background: var(--soft); color: var(--ink); font-size: var(--text-2xs); font-variant-numeric: tabular-nums; }
.category-track { position: relative; display: grid; gap: 3px; isolation: isolate; }
.category-indicator { position: absolute; z-index: -1; top: 0; left: 0; width: 100%; height: 64px; border-radius: var(--radius-md); background: var(--accent-soft); border: 1px solid var(--accent); pointer-events: none; }
.category-indicator::before { content: ""; position: absolute; left: 0; top: var(--space-3); bottom: var(--space-3); width: 3px; border-radius: var(--radius-pill); background: var(--accent); }
.category-tab.active { color: var(--accent); }
.category-shelf { position: relative; min-width: 0; min-height: calc(100dvh - 225px); container-type: inline-size; container-name: clothing-shelf; }
.category-heading { font-size: clamp(22px, 3.2vw, 27px); margin: var(--space-2) 0 var(--space-4); }
.collection-viewport { position: relative; overflow-anchor: none; }
.shelf-grid { --cols: 2; --gap: var(--space-2); display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: var(--gap); padding: var(--gap); border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--collection-bg); }
/* 1着のときもカードの幅は変えない。トラックを1本に詰めて中央へ寄せるだけ。 */
.shelf-grid.is-single { grid-template-columns: minmax(0, calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols))); justify-content: center; }
.wardrobe-card { position: relative; min-width: 0; overflow: hidden; border: 1px solid color-mix(in srgb, var(--line) 65%, transparent); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--elev-1); transform-origin: center; }
.wardrobe-card:focus-within { z-index: 2; box-shadow: var(--elev-3); }
.card-open { display: block; width: 100%; padding: 0; border: 0; background: transparent; }
.card-open .photo, .card-open .photo-placeholder { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: var(--photo-bg); }
.card-open .photo-placeholder { display: grid; place-items: center; }
.photo-placeholder svg { width: 54px; height: 54px; color: var(--muted); }
.favorite-button { position: absolute; top: 7px; right: 7px; z-index: 2; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); line-height: 1; box-shadow: var(--elev-2); }
.favorite-button svg { width: 23px; height: 23px; }
.favorite-button.active { color: var(--mark); }
.card-meta { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; min-height: 32px; padding: 6px var(--space-2); font-size: var(--text-xs); font-weight: var(--w-medium); }
.card-brand { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-tag { border-radius: var(--radius-sm); padding: 2px 5px; background: var(--accent-soft); color: var(--accent); font-size: var(--text-2xs); font-weight: var(--w-medium); font-variant-numeric: tabular-nums; }
.shelf-empty { display: grid; justify-items: center; gap: var(--space-3); min-height: 220px; align-content: center; border: 1px dashed var(--line); border-radius: var(--radius-lg); color: var(--muted); text-align: center; }
.shelf-empty svg { width: 56px; height: 56px; color: color-mix(in srgb, var(--line) 70%, var(--muted)); }
.shelf-empty p { font-size: var(--text-xs); margin: 0; }
.page-list[data-location="storage"] .shelf-grid { background: var(--soft); }
.page-list[data-location="storage"] .wardrobe-card { box-shadow: none; }
.action-dock { position: fixed; z-index: 15; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - var(--space-6)), 680px); display: grid; gap: var(--space-2); padding: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--elev-3); }
.dock-primary { min-height: 54px; border: 0; border-radius: var(--radius-md); font-weight: var(--w-bold); background: var(--accent); color: var(--accent-ink); }

/* 服の詳細 */
.detail-hero { position: relative; max-width: 570px; margin: 0 auto var(--space-4); }
.detail-photo, .detail-placeholder { display: block; width: 100%; max-height: 600px; aspect-ratio: 3 / 4; object-fit: contain; border: 1px solid var(--line); border-radius: var(--radius-2xl); background: var(--photo-bg); }
.detail-placeholder { display: grid; place-items: center; }
.detail-placeholder svg { width: 100px; height: 100px; color: var(--muted); }
.detail-favorite { top: var(--space-3); right: var(--space-3); width: 48px; height: 48px; }
.detail-favorite svg { width: 26px; height: 26px; }
.detail-heading, .detail-stack { max-width: 650px; margin-left: auto; margin-right: auto; }
.detail-heading h1 { margin-bottom: 5px; }
.storage-note { color: var(--muted); font-size: var(--text-sm); }
.detail-stack { display: grid; gap: var(--space-3); margin-top: var(--space-4); }
.detail-section { padding: var(--space-5) var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); }
.detail-section h2 { margin-bottom: var(--space-3); }
.action-section { padding: var(--space-3); }
.primary-action { width: 100%; min-height: 55px; border: 0; border-radius: var(--radius-md); background: var(--accent); color: var(--accent-ink); font-weight: var(--w-bold); font-size: var(--text-md); }
.decision-panel h2 { margin: 3px 0 var(--space-4); }
.reason-choices, .outcome-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.tap-choice { min-height: 54px; padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--bg); font-weight: var(--w-medium); }
.tap-choice:hover, .brand-chip:hover, .tag-chip:hover { border-color: var(--accent); }
.selected-reason { display: inline-block; margin-bottom: var(--space-4); border-radius: var(--radius-pill); padding: 6px var(--space-3); background: var(--accent-soft); color: var(--accent); font-weight: var(--w-bold); font-size: var(--text-xs); }
.outcome-hint { margin: var(--space-3) 0 0; color: var(--muted); font-size: var(--text-xs); }
.brand-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.brand-chip, .tag-chip { min-height: 47px; border: 1px solid var(--line); border-radius: var(--radius-pill); padding: var(--space-2) var(--space-4); background: var(--bg); font-weight: var(--w-medium); }
.brand-chip.selected, .tag-chip.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.add-brand { min-width: 47px; font-size: var(--text-xl); }
.brand-form { display: flex; gap: var(--space-2); width: 100%; margin-top: var(--space-2); }
.brand-form input { min-width: 0; flex: 1; min-height: 47px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); background: var(--bg); color: var(--ink); }
.brand-form button { min-width: 65px; border: 0; border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-ink); font-weight: var(--w-bold); }
.quiet-button { min-height: 44px; padding: var(--space-2) 0; color: var(--muted); font-weight: var(--w-medium); }
.delete-section { border: 0; background: transparent; padding: var(--space-1) var(--space-4); }
.delete-link, .danger-button { color: var(--danger); }
.delete-confirm { padding: var(--space-4); border: 1px solid var(--danger); border-radius: var(--radius-md); background: var(--surface); }
.confirm-actions { display: flex; gap: var(--space-4); align-items: center; }
.danger-button { min-height: 46px; border: 1px solid var(--danger); border-radius: var(--radius-md); background: transparent; padding: var(--space-2) var(--space-4); font-weight: var(--w-bold); }

/* 服の登録 */
.add-head { padding: 5px 3px var(--space-5); }
.add-form { display: grid; gap: var(--space-5); max-width: 650px; }
.photo-picker { display: block; position: relative; overflow: hidden; aspect-ratio: 3 / 4; border: 2px dashed var(--accent); border-radius: var(--radius-2xl); background: var(--accent-soft); cursor: pointer; }
.photo-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-picker-content { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; height: 100%; }
.photo-picker-icon { font-size: 48px; }
.photo-picker small { color: var(--muted); }
.photo-picker img { width: 100%; height: 100%; object-fit: contain; background: var(--photo-bg); }
.photo-picker img[hidden], .photo-picker.has-photo .photo-picker-content { display: none; }
.choice-field { border: 0; padding: 0; margin: 0; min-width: 0; }
.choice-field legend { padding: 0; font-size: var(--text-lg); font-weight: var(--w-bold); margin-bottom: var(--space-3); text-wrap: balance; }
.choice-grid { display: grid; gap: var(--space-2); }
.category-choices, .location-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.choice-face { min-height: 93px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 2px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); font-weight: var(--w-bold); text-align: center; }
.choice-icon { font-size: 34px; }
.choice-icon svg { width: 36px; height: 36px; }
.choice-face small { font-weight: var(--w-regular); color: var(--muted); }
.choice input:checked + .choice-face { border-color: var(--accent); background: var(--accent-soft); }
.submit-button { min-height: 60px; border: 0; border-radius: var(--radius-lg); background: var(--accent); color: var(--accent-ink); font-weight: var(--w-bold); font-size: var(--text-md); }
.submit-button:disabled { opacity: .55; }
@media (min-width: 700px) {
  .shell { padding-left: var(--space-6); padding-right: var(--space-6); }
  .family-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .closet-stage { grid-template-columns: 82px minmax(0, 1fr); gap: var(--space-5); }
  .category-tab { min-height: 72px; }
  .category-tab svg { width: 31px; height: 31px; }
  .shelf-grid { --gap: var(--space-3); }
}
@container clothing-shelf (max-width: 269px) { .shelf-grid { --cols: 1; } }
@container clothing-shelf (min-width: 510px) { .shelf-grid { --cols: 3; } }
@container clothing-shelf (min-width: 780px) { .shelf-grid { --cols: 4; } }
