/* Nocturne Archive — v0.5.1
 * 雨夜の紫陽花。写真が主役、装飾は退く。
 * コントラスト（WCAG 2.2）
 *   雨霧の白 #D9E3F1 × サファイア面 #2B5CC4 = 約4.7:1（ボタン文字）
 *   淡い紫陽花 #A79DE8 × 墨紺 #0D1320 = 約7.6:1（小さい文字に使う紫）
 *   鈍い灰青 #8B94A8 × 墨紺 #0D1320 = 約6.1:1
 *   #3F7FE8 と #7A6FCA は線・図形・大きな要素だけに使う
 */

:root {
  --night: #06070B;
  --ink: #0D1320;
  --deep: #111B32;
  --sapphire: #3F7FE8;
  --sapphire-face: #2B5CC4;
  --sapphire-light: #7EABFF;
  --hydrangea: #7A6FCA;
  --hydrangea-text: #A79DE8;
  --hydrangea-blue: #6F91C8;
  --mist: #D9E3F1;
  --muted: #8B94A8;
  --danger: #C96A7A;
  --line: rgba(217, 227, 241, 0.14);
  --line-strong: rgba(217, 227, 241, 0.28);

  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --mincho: "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Yu Mincho", "YuMincho", "BIZ UDMincho", serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: 64px;
  --t-quick: 180ms;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background-color: var(--night);
  background-image:
    radial-gradient(60rem 40rem at 85% -10%, rgba(122, 111, 202, 0.10), transparent 60%),
    radial-gradient(50rem 35rem at -10% 110%, rgba(111, 145, 200, 0.08), transparent 60%);
  background-attachment: fixed;
  color: var(--mist);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--sapphire-light);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 1.4rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-size: 0.97rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-quick) ease, border-color var(--t-quick) ease;
}
.btn:active { background: rgba(217, 227, 241, 0.06); }
.btn-primary {
  background: var(--sapphire-face);
  border-color: rgba(126, 171, 255, 0.45);
}
.btn-primary:active { background: #24509F; }
.btn-quiet { border-color: var(--line); }
.btn-small { min-height: 44px; padding: 0 1rem; font-size: 0.9rem; }
label.btn { user-select: none; -webkit-user-select: none; }

.chip {
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* 表紙 */
.cover {
  min-height: calc(100svh - 4rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(var(--safe-top) + 3rem) 1.5rem 2rem;
}
.cover-emblem { width: 104px; height: 110px; margin-bottom: 1.6rem; }
.cover-title {
  margin: 0;
  font-family: var(--mincho);
  font-weight: 500;
  font-size: 1.9rem;
  letter-spacing: 0.06em;
  line-height: 1.3;
}
.cover-sub { margin: 0.5rem 0 2.6rem; color: var(--muted); font-size: 0.88rem; letter-spacing: 0.08em; }
.cover-actions { display: grid; gap: 0.75rem; width: min(100%, 300px); }
.cover-note { margin: 2.2rem 0 0.8rem; color: var(--muted); font-size: 0.86rem; line-height: 1.8; }

/* 展示室 */
.gallery { min-height: 80svh; padding: calc(var(--safe-top) + 1.2rem) 14px calc(var(--dock-h) + var(--safe-bottom) + 2rem); }
.gallery-head { max-width: 1200px; margin: 0 auto 1.2rem; padding: 0 4px; }
.gallery-title-row { display: flex; align-items: center; gap: 0.6rem; }
.head-emblem { width: 28px; height: 30px; }
.gallery-title { margin: 0; font-family: var(--mincho); font-weight: 500; font-size: 1.35rem; letter-spacing: 0.08em; }
.save-state { display: flex; align-items: center; gap: 0.45rem; margin: 0.6rem 0 0; font-size: 0.9rem; }
.save-state svg { width: 14px; height: 14px; flex: none; }
.save-state.is-dirty { color: var(--mist); }
.save-state.is-dirty svg { color: var(--hydrangea-text); }
.save-state.is-saved { color: var(--muted); }
.save-state.is-saved svg { color: var(--sapphire-light); }
.album-stats { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.82rem; }

.confirm-row {
  margin: 0.8rem 0 0;
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(126, 171, 255, 0.35);
  border-radius: 10px;
  background: var(--deep);
}
.confirm-text { margin: 0 0 0.6rem; font-size: 0.86rem; }
.save-state.is-verified { color: var(--mist); }
.save-state.is-verified svg { color: var(--sapphire-light); }
.save-state.is-warn { color: var(--danger); }

.grid {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 1200px;
  column-count: 2;
  column-gap: 12px;
}
@media (min-width: 720px) { .grid { column-count: 3; column-gap: 16px; } .gallery { padding-left: 24px; padding-right: 24px; } }
@media (min-width: 1080px) { .grid { column-count: 4; column-gap: 20px; } }

.tile { break-inside: avoid; margin: 0 0 14px; }
.tile-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tile-frame {
  display: block;
  border-radius: 3px;
  overflow: hidden;
  background: var(--ink);
  outline: 1px solid var(--line);
  outline-offset: -1px;
}
.tile-img { display: block; width: 100%; height: auto; }
.tile-placeholder {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 3 / 4;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  white-space: pre-line;
  background:
    repeating-linear-gradient(135deg, rgba(122, 111, 202, 0.06) 0 8px, transparent 8px 16px),
    var(--ink);
}
.tile-placeholder.is-broken { color: var(--danger); }
.tile-cap { display: block; margin-top: 0.35rem; font-family: var(--mincho); font-size: 0.78rem; color: var(--muted); letter-spacing: 0.06em; }

.empty { max-width: 360px; margin: 3.5rem auto; text-align: center; }
.empty-emblem { width: 64px; height: 68px; opacity: 0.55; }
.empty-title { margin: 1rem 0 0.2rem; font-family: var(--mincho); font-size: 1.1rem; }
.empty-body { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* 下部の操作（片手で届く位置） */
.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: rgba(13, 19, 32, 0.86);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.dock-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dock-primary { background: var(--sapphire-face); border-color: rgba(126, 171, 255, 0.45); }
.badge {
  margin-left: 0.45rem;
  min-width: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--night);
  color: var(--mist);
  font-size: 0.78rem;
  line-height: 1.5rem;
}

/* 鑑賞（全画面） */
.viewer {
  position: fixed; inset: 0;
  z-index: 30;
  background: var(--night);
  display: grid;
  grid-template-rows: 1fr auto;
}
.viewer-stage {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 56px) 8px 8px;
  min-height: 0;
  touch-action: pan-y pinch-zoom;
}
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-msg { max-width: 300px; color: var(--muted); text-align: center; font-size: 0.92rem; }
.viewer-top {
  position: absolute;
  top: calc(var(--safe-top) + 6px);
  right: 8px;
  left: 8px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}
.viewer-chip { background: rgba(13, 19, 32, 0.8); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--mist);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:disabled { color: rgba(217, 227, 241, 0.25); cursor: default; }

/* 美術館のキャプション */
.plate {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  padding: 10px 10px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}
.plate-text { text-align: center; min-width: 0; }
.plate-no { margin: 0; color: var(--hydrangea-text); font-family: var(--mincho); font-size: 0.78rem; letter-spacing: 0.14em; }
.plate-title {
  margin: 0.1rem 0;
  font-family: var(--mincho);
  font-size: 1.02rem;
  letter-spacing: 0.04em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.plate-meta { margin: 0; color: var(--muted); font-size: 0.78rem; }

/* シート（ダイアログ） */
.sheet {
  width: min(calc(100% - 24px), 420px);
  max-height: calc(100svh - 24px);
  padding: 1.4rem 1.3rem 1.2rem;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--ink);
  color: var(--mist);
  overflow: auto;
}
.sheet::backdrop { background: rgba(6, 7, 11, 0.72); }
.sheet-title { margin: 0 0 0.6rem; font-family: var(--mincho); font-weight: 500; font-size: 1.15rem; }
.sheet-body { margin: 0 0 0.8rem; color: var(--mist); font-size: 0.92rem; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }
.sheet-actions .btn { white-space: nowrap; }
.sheet-actions .btn-primary { flex: 1 1 auto; }
.sheet-actions-stack { flex-direction: column-reverse; }
.sheet-actions-stack .btn { width: 100%; }
.field-label { display: block; margin: 0.8rem 0 0.3rem; font-size: 0.85rem; color: var(--muted); }
.field {
  width: 100%;
  min-height: 48px;
  padding: 0 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--night);
  color: var(--mist);
  font: inherit;
  font-size: 16px; /* iPhone の自動ズームを防ぐ */
}
.select {
  min-height: 44px;
  padding: 0 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--night);
  color: var(--mist);
  font: inherit;
  font-size: 16px;
}
.warn {
  margin: 1rem 0 0;
  padding: 0.7rem 0.9rem;
  border-left: 2px solid var(--hydrangea);
  background: rgba(122, 111, 202, 0.08);
  font-size: 0.86rem;
}
.error { margin: 0.8rem 0 0; color: var(--danger); font-size: 0.88rem; }

/* 処理中 */
.busy {
  position: fixed; inset: 0;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(6, 7, 11, 0.8);
}
.busy-card {
  width: min(100%, 360px);
  padding: 1.3rem 1.3rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--ink);
}
.busy-text { margin: 0 0 0.9rem; font-size: 0.95rem; }
.busy-sub { margin: 0.7rem 0 0; color: var(--muted); font-size: 0.82rem; }
.rain { height: 3px; border-radius: 3px; background: var(--deep); overflow: hidden; }
.rain-fill { height: 100%; width: 0; background: var(--sapphire-light); transition: width var(--t-quick) linear; }
.rain-fill.is-indeterminate { width: 30%; animation: drizzle 1.4s ease-in-out infinite; }
@keyframes drizzle { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* 目隠し */
.veil {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--night);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
}
.veil-mark { width: 56px; height: 60px; opacity: 0.5; margin-bottom: 0.6rem; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--dock-h) + var(--safe-bottom) + 18px);
  z-index: 50;
  width: fit-content;
  max-width: 420px;
  margin: 0 auto;
  padding: 0.65rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--deep);
  font-size: 0.9rem;
}

/* 試験室 */
.lab {
  max-width: 1200px;
  margin: 0 auto calc(var(--dock-h) + var(--safe-bottom) + 1.5rem);
  padding: 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
}
.lab > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.lab-body { padding: 0.5rem 0 1rem; }
.lab-note { margin: 0 0 0.8rem; }
.lab-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.7rem; }
.lab-label { color: var(--mist); }
.diag { width: 100%; border-collapse: collapse; margin: 0.6rem 0; font-size: 0.82rem; }
.diag th, .diag td { padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.diag th { color: var(--muted); font-weight: 400; width: 46%; }
.diag td { color: var(--mist); word-break: break-all; }
.log {
  min-height: 3rem;
  max-height: 16rem;
  overflow: auto;
  margin: 0.6rem 0;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--night);
  color: var(--mist);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}


/* v0.3.0 ─ 部屋・選択・書き出し */
.head-actions { margin-left: auto; display: flex; gap: 6px; }
.head-actions .btn { min-height: 40px; padding: 0 0.8rem; font-size: 0.85rem; }

.rooms {
  display: flex;
  gap: 4px;
  margin: 1rem 0 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.rooms::-webkit-scrollbar { display: none; }
.room-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.room-tab[aria-pressed="true"] { color: var(--mist); border-color: rgba(126, 171, 255, 0.55); background: var(--deep); }
.room-count { font-size: 0.78rem; color: var(--muted); }
.room-tab[aria-pressed="true"] .room-count { color: var(--sapphire-light); }
.room-hint { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.82rem; }

.tile-btn[aria-pressed="true"] .tile-frame { outline: 2px solid var(--sapphire-light); outline-offset: 2px; }
.tile-check {
  display: none;
  position: absolute;
  top: 6px; left: 6px;
  width: 26px; height: 26px;
  border-radius: 999px;
  border: 1.5px solid var(--mist);
  background: rgba(6, 7, 11, 0.55);
}
.is-selecting .tile-check { display: block; }
.tile-btn[aria-pressed="true"] .tile-check { background: var(--sapphire-face); border-color: var(--sapphire-light); }
.tile-btn[aria-pressed="true"] .tile-check::after {
  content: "";
  position: absolute;
  left: 8px; top: 4px;
  width: 6px; height: 11px;
  border: solid var(--mist);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.tile-frame { position: relative; }

.dock-select {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: auto auto;
}
.select-count { grid-column: 1 / -1; margin: 0 0 2px; color: var(--muted); font-size: 0.82rem; text-align: center; }
.dock-danger { color: var(--danger); border-color: rgba(201, 106, 122, 0.45); }
.dock-btn:disabled { opacity: 0.4; cursor: default; }

.sheet-form { margin: 0; }
.warn-text { margin: 0 0 0.5rem; }
.check-row { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.86rem; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin-top: 0.15rem; accent-color: var(--sapphire-face); flex: none; }
.file-name { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.86rem; color: var(--sapphire-light); word-break: break-all; }

/* PC では下の操作を中央にまとめ、横に伸びすぎないようにする */
@media (min-width: 720px) {
  .dock { left: 50%; right: auto; transform: translateX(-50%); width: min(640px, calc(100% - 48px)); bottom: 16px; border: 1px solid var(--line); border-radius: 14px; padding-bottom: 8px; }
  .gallery { padding-bottom: calc(var(--dock-h) + 4rem); }
}

.open-any { margin: 0.2rem 0 0; text-align: center; }
.link-btn { display: inline-flex; align-items: center; min-height: 44px; color: var(--sapphire-light); font-size: 0.85rem; text-decoration: underline; text-underline-offset: 0.2em; cursor: pointer; }

/* 選択中は、知らせを操作の上へずらす */
.is-selecting ~ .toast, body:has(.is-selecting) .toast { bottom: calc(var(--dock-h) + var(--safe-bottom) + 48px); }

/* v0.3.1 */
.key-name { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.82rem; }
.key-name strong { color: var(--sapphire-light); font-weight: 500; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.choices { display: grid; gap: 0.5rem; margin: 0 0 0.9rem; }
.choice-row { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.choice-row:has(input:checked) { border-color: rgba(126, 171, 255, 0.55); background: var(--deep); }
.choice-row input { width: 20px; height: 20px; margin-top: 0.2rem; accent-color: var(--sapphire-face); flex: none; }
.choice-title { display: block; font-size: 0.92rem; }
.choice-body { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.82rem; line-height: 1.6; }
.warn-text { white-space: pre-line; }
.warn-small { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.8rem; }

/* v0.4.0 ─ 探す・並べる・お気に入り・作品の情報 */
.tools { margin: 0.8rem 0 0; display: grid; gap: 0.55rem; }
.search { min-height: 44px; -webkit-appearance: none; appearance: none; }
.scope-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.scope-label { color: var(--muted); font-size: 0.82rem; margin-right: 2px; }
.tool-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  min-height: 40px; padding: 0 0.8rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 0.84rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip-btn[aria-pressed="true"] { color: var(--mist); border-color: rgba(126, 171, 255, 0.55); background: var(--deep); }
.chip-gem { width: 15px; height: 15px; opacity: 0.5; }
.chip-btn[aria-pressed="true"] .chip-gem { opacity: 1; }
.select-small { min-height: 40px; font-size: 14px; max-width: 12.5rem; }
.cols-group { display: inline-flex; margin-left: auto; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cols-btn { min-width: 40px; min-height: 40px; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.88rem; cursor: pointer; }
.cols-btn + .cols-btn { border-left: 1px solid var(--line); }
.cols-btn[aria-pressed="true"] { background: var(--deep); color: var(--mist); }
.result-line { margin: 0; color: var(--mist); font-size: 0.86rem; }

/* 列の切り替え（CSS の段組みをやめ、並び順どおりに置く） */
.grid { columns: auto; display: grid; gap: 0 12px; grid-auto-flow: row; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 4px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; }
.grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
@media (min-width: 720px) {
  .grid.cols-2 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
  .grid.cols-3 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.cols-5 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}
@media (min-width: 1080px) {
  .grid.cols-2 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 20px; }
  .grid.cols-3 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .grid.cols-5 { grid-template-columns: repeat(10, minmax(0, 1fr)); }
}
.tile { margin: 0; min-width: 0; }
.grid.cols-2 .tile-frame { aspect-ratio: var(--ar, 3 / 4); }
.grid.cols-3 .tile-frame, .grid.cols-5 .tile-frame { aspect-ratio: 1 / 1; }
.tile-frame { display: block; }
.tile-img { width: 100%; height: 100%; object-fit: cover; }
.tile-placeholder { aspect-ratio: auto; height: 100%; }
.grid.cols-5 .tile-cap { display: none; }
.grid.cols-5 .tile-frame { border-radius: 1px; }
.grid.cols-3 .tile-cap { font-size: 0.72rem; }
.tile-fav { display: none; position: absolute; right: 6px; bottom: 6px; width: 18px; height: 18px; filter: drop-shadow(0 0 2px rgba(6, 7, 11, 0.7)); }
.is-fav .tile-fav { display: block; }
.grid.cols-5 .tile-fav { width: 12px; height: 12px; right: 3px; bottom: 3px; }
.grid.cols-5 .tile-check { width: 18px; height: 18px; top: 3px; left: 3px; }
.grid.cols-5 .tile-btn[aria-pressed="true"] .tile-check::after { left: 5px; top: 2px; width: 5px; height: 9px; }

.dock-select { grid-template-columns: repeat(3, 1fr); }

.viewer-fav svg { width: 26px; height: 26px; opacity: 0.35; filter: grayscale(0.6); }
.viewer-fav[aria-pressed="true"] svg { opacity: 1; filter: none; }
.plate-tags { margin: 0.15rem 0 0; color: var(--hydrangea-text); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 0.5rem; }
.tag-list:empty { display: none; }
.tag-chip { display: inline-flex; align-items: center; gap: 0.2rem; padding: 0.15rem 0.2rem 0.15rem 0.7rem; border: 1px solid rgba(167, 157, 232, 0.4); border-radius: 999px; color: var(--hydrangea-text); font-size: 0.85rem; }
.tag-x { min-width: 32px; min-height: 32px; border: 0; background: transparent; color: var(--muted); font-size: 1rem; cursor: pointer; }
.tag-add { display: flex; gap: 6px; }
.tag-add .field { flex: 1; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: 0.5rem 0 0; }
.tag-suggest-btn { min-height: 36px; padding: 0 0.7rem; border: 1px dashed var(--line-strong); border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: 0.82rem; cursor: pointer; }
.textarea { min-height: 6.5rem; padding: 0.7rem 0.9rem; line-height: 1.6; resize: vertical; }
.field-hint { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.8rem; }
/* 下の操作に「試験室」が隠れないよう、余白を margin ではなく padding で取る（短いページでもスクロールできる） */
.lab { margin-bottom: 0; padding-bottom: calc(var(--dock-h) + var(--safe-bottom) + 2rem); }


/* ════════ v0.5.0 ─ 夜と朝、額、案内図 ════════
 * 色はすべて変数から。夜（既定）に加えて、朝の三色を html[data-theme] で切り替える。
 * 小さい文字に使う色は、背景に対して 4.5:1 以上になるよう選んでいる（README に計算結果）。
 */
:root {
  --on-accent: #D9E3F1;
  --accent-line: rgba(126, 171, 255, 0.55);
  --accent-line-soft: rgba(126, 171, 255, 0.35);
  --dock-bg: rgba(13, 19, 32, 0.86);
  --chip-bg: rgba(13, 19, 32, 0.8);
  --press: rgba(217, 227, 241, 0.06);
  --disabled: rgba(217, 227, 241, 0.25);
  --stripe: rgba(122, 111, 202, 0.06);
  --warn-bg: rgba(122, 111, 202, 0.08);
  --busy-bg: rgba(6, 7, 11, 0.8);
  --tag-line: rgba(167, 157, 232, 0.4);
  --glow-a: rgba(122, 111, 202, 0.10);
  --glow-b: rgba(111, 145, 200, 0.08);
  --mat: #141B2B;
  --metal-pt: #C8CDD5;
  --metal-pt-hi: #EEF1F5;
  --metal-au: #C9A96E;
  --metal-au-hi: #F1DFB4;
  --wall: rgba(217, 227, 241, 0.5);
  --ear: #12141C;
  --ear-line: #8C82D8;
  --rabbit: #0B0C10;
  --rabbit-line: rgba(217, 227, 241, 0.6);
  --rabbit-tail: #D9E3F1;
  --thumb-fill: #0D1320;
}

html[data-theme="sky"] {
  --night: #F4F9FC; --ink: #FFFFFF; --deep: #E0EDF4;
  --sapphire: #2B5CC4; --sapphire-face: #2B5CC4; --sapphire-light: #2B5CC4;
  --hydrangea: #AEC5D2; --hydrangea-text: #3E6A8A; --hydrangea-blue: #7FA3BD;
  --mist: #2C3D4B; --muted: #5A6B78; --danger: #A3404F;
  --line: rgba(44, 61, 75, 0.14); --line-strong: rgba(44, 61, 75, 0.3);
  --on-accent: #FFFFFF; --accent-line: rgba(43, 92, 196, 0.5); --accent-line-soft: rgba(43, 92, 196, 0.3);
  --dock-bg: rgba(244, 249, 252, 0.92); --chip-bg: rgba(255, 255, 255, 0.88);
  --press: rgba(44, 61, 75, 0.06); --disabled: rgba(44, 61, 75, 0.25);
  --stripe: rgba(62, 106, 138, 0.07); --warn-bg: rgba(62, 106, 138, 0.08); --busy-bg: rgba(244, 249, 252, 0.82);
  --tag-line: rgba(62, 106, 138, 0.35); --glow-a: rgba(174, 197, 210, 0.35); --glow-b: rgba(224, 237, 244, 0.7);
  --mat: #FFFFFF; --metal-pt: #9AA6B2; --metal-pt-hi: #E8EDF1; --metal-au: #B08D57; --metal-au-hi: #EAD7AE;
  --wall: rgba(44, 61, 75, 0.55); --ear: #1D1F29; --ear-line: transparent;
  --rabbit: #1D1F29; --rabbit-line: transparent; --rabbit-tail: #FFFFFF; --thumb-fill: #E0EDF4;
  color-scheme: light;
}
html[data-theme="hydrangea"] {
  --night: #F8F7FB; --ink: #FFFFFF; --deep: #E7E1EF;
  --sapphire: #2B5CC4; --sapphire-face: #2B5CC4; --sapphire-light: #2B5CC4;
  --hydrangea: #8B7CA5; --hydrangea-text: #685A8A; --hydrangea-blue: #8E9BC6;
  --mist: #343442; --muted: #615E70; --danger: #A3404F;
  --line: rgba(52, 52, 66, 0.14); --line-strong: rgba(52, 52, 66, 0.3);
  --on-accent: #FFFFFF; --accent-line: rgba(104, 90, 138, 0.5); --accent-line-soft: rgba(104, 90, 138, 0.3);
  --dock-bg: rgba(248, 247, 251, 0.92); --chip-bg: rgba(255, 255, 255, 0.88);
  --press: rgba(52, 52, 66, 0.06); --disabled: rgba(52, 52, 66, 0.25);
  --stripe: rgba(139, 124, 165, 0.08); --warn-bg: rgba(139, 124, 165, 0.1); --busy-bg: rgba(248, 247, 251, 0.82);
  --tag-line: rgba(104, 90, 138, 0.35); --glow-a: rgba(231, 225, 239, 0.9); --glow-b: rgba(139, 124, 165, 0.12);
  --mat: #FFFFFF; --metal-pt: #A3A6B4; --metal-pt-hi: #EEEEF4; --metal-au: #B08D57; --metal-au-hi: #EAD7AE;
  --wall: rgba(52, 52, 66, 0.5); --ear: #1D1F29; --ear-line: transparent;
  --rabbit: #1D1F29; --rabbit-line: transparent; --rabbit-tail: #FFFFFF; --thumb-fill: #E7E1EF;
  color-scheme: light;
}
html[data-theme="white"] {
  --night: #FAF7F0; --ink: #FFFFFF; --deep: #E8E1D5;
  --sapphire: #2459A6; --sapphire-face: #2459A6; --sapphire-light: #2459A6;
  --hydrangea: #B59B70; --hydrangea-text: #7A5F2E; --hydrangea-blue: #9AA6B2;
  --mist: #343A43; --muted: #6A6458; --danger: #A3404F;
  --line: rgba(52, 58, 67, 0.14); --line-strong: rgba(52, 58, 67, 0.3);
  --on-accent: #FFFFFF; --accent-line: rgba(181, 155, 112, 0.7); --accent-line-soft: rgba(181, 155, 112, 0.45);
  --dock-bg: rgba(250, 247, 240, 0.92); --chip-bg: rgba(255, 255, 255, 0.88);
  --press: rgba(52, 58, 67, 0.06); --disabled: rgba(52, 58, 67, 0.25);
  --stripe: rgba(181, 155, 112, 0.1); --warn-bg: rgba(181, 155, 112, 0.12); --busy-bg: rgba(250, 247, 240, 0.82);
  --tag-line: rgba(122, 95, 46, 0.35); --glow-a: rgba(232, 225, 213, 0.8); --glow-b: rgba(181, 155, 112, 0.1);
  --mat: #FFFFFF; --metal-pt: #A9AFB8; --metal-pt-hi: #F1F2F4; --metal-au: #B59B70; --metal-au-hi: #EFE0BD;
  --wall: rgba(52, 58, 67, 0.5); --ear: #1D1F29; --ear-line: transparent;
  --rabbit: #1D1F29; --rabbit-line: transparent; --rabbit-tail: #FFFFFF; --thumb-fill: #E8E1D5;
  color-scheme: light;
}

/* 固定の色だった所を、変数に置き換える */
body {
  background-image:
    radial-gradient(60rem 40rem at 85% -10%, var(--glow-a), transparent 60%),
    radial-gradient(50rem 35rem at -10% 110%, var(--glow-b), transparent 60%);
}
.btn:active { background: var(--press); }
.btn-primary, .dock-primary { color: var(--on-accent); border-color: var(--accent-line-soft); }
.btn-primary:active { background: var(--sapphire-face); filter: brightness(0.9); }
.confirm-row, .banner { border-color: var(--accent-line-soft); }
.tile-placeholder { background: repeating-linear-gradient(135deg, var(--stripe) 0 8px, transparent 8px 16px), var(--thumb-fill); }
.dock { background: var(--dock-bg); }
.viewer-chip { background: var(--chip-bg); }
.icon-btn:disabled { color: var(--disabled); }
.warn { background: var(--warn-bg); }
.busy { background: var(--busy-bg); }
.room-tab[aria-pressed="true"], .chip-btn[aria-pressed="true"], .choice-row:has(input:checked) { border-color: var(--accent-line); }
.dock-danger { border-color: var(--danger); }
.tag-chip { border-color: var(--tag-line); }
.badge { background: var(--night); color: var(--mist); }

/* 紋章の黒い垂れ耳、案内図のうさぎ */
.em-ear { fill: var(--ear); stroke: var(--ear-line); stroke-width: 0.8; }
.rb-body { fill: var(--rabbit); stroke: var(--rabbit-line); stroke-width: 0.9; }
.rb-tail { fill: var(--rabbit-tail); }

/* ─── 額 ─── 写真の箱（tile-pic）の外側に、額（tile-frame）を巡らせる */
.tile-frame { overflow: visible; background: transparent; outline: none; border-radius: 0; }
.tile-pic { position: relative; display: block; overflow: hidden; aspect-ratio: var(--ar, 3 / 4); background: var(--thumb-fill); border-radius: 2px; }
.grid.cols-3 .tile-pic, .grid.cols-5 .tile-pic { aspect-ratio: 1 / 1; }
.grid.cols-2 .tile-frame { aspect-ratio: auto; }
.tile-pic .tile-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile-pic .tile-placeholder { height: 100%; aspect-ratio: auto; }

html:not([data-frame]) .tile-pic, html[data-frame="line"] .tile-pic { outline: 1px solid var(--line); outline-offset: -1px; }

html[data-frame="mat"] .grid:not(.cols-5) .tile-frame {
  padding: 8%;
  background: var(--mat);
  box-shadow: 0 0 0 1px var(--line), 0 6px 18px -12px rgba(0, 0, 0, 0.5);
}
html[data-frame="mat"] .grid:not(.cols-5) .tile-pic { outline: 1px solid var(--line-strong); outline-offset: 0; }
html[data-frame="mat"] .grid.cols-3 .tile-frame { padding: 6%; }

/* ミル打ち：縁に小さな粒が一列に並ぶ */
html[data-frame="milgrain"] .grid:not(.cols-5) .tile-frame {
  padding: 5px;
  background:
    radial-gradient(circle, var(--metal-pt-hi) 0 0.6px, var(--metal-pt) 0.7px 1.4px, transparent 1.8px) 0 0 / 5px 5px;
}
html[data-frame="milgrain"] .grid:not(.cols-5) .tile-pic { outline: 1px solid var(--metal-pt); outline-offset: 0; }

/* 爪留め：四隅を小さな爪で留める */
html[data-frame="claw"] .grid:not(.cols-5) .tile-frame { padding: 3px; }
html[data-frame="claw"] .grid:not(.cols-5) .tile-pic { outline: 1px solid var(--metal-pt); outline-offset: 0; }
html[data-frame="claw"] .grid:not(.cols-5) .tile-frame::after {
  content: "";
  position: absolute;
  inset: -2px;
  pointer-events: none;
  --claw: radial-gradient(circle at 50% 50%, var(--metal-pt-hi) 0 1.6px, var(--metal-pt) 2px 4.2px, rgba(0, 0, 0, 0.28) 4.6px, transparent 5.2px);
  background: var(--claw) 0 0 / 13px 13px no-repeat, var(--claw) 100% 0 / 13px 13px no-repeat,
              var(--claw) 0 100% / 13px 13px no-repeat, var(--claw) 100% 100% / 13px 13px no-repeat;
}

/* 地金の細枠 */
html[data-frame="pt"] .grid:not(.cols-5) .tile-frame {
  padding: 3px;
  background: linear-gradient(135deg, var(--metal-pt-hi), var(--metal-pt) 40%, var(--metal-pt-hi) 52%, var(--metal-pt) 70%, var(--metal-pt-hi));
}
html[data-frame="au"] .grid:not(.cols-5) .tile-frame {
  padding: 3px;
  background: linear-gradient(135deg, var(--metal-au-hi), var(--metal-au) 40%, var(--metal-au-hi) 52%, var(--metal-au) 70%, var(--metal-au-hi));
}

/* ─── 館内の案内図（絵の上に、名前・作品数・代表の一枚を重ねる） ─── */
.floor { margin: 1rem 0 0; }
.floor-lead { margin: 0 0 0.8rem; color: var(--muted); font-family: var(--mincho); font-size: 0.92rem; letter-spacing: 0.12em; text-align: center; }
.plan { position: relative; width: min(100%, 520px); margin: 0 auto; aspect-ratio: 1024 / 1536; border-radius: 6px; overflow: hidden; box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.6); }
.plan-bg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.plan-bg-night { display: none; }
html:not([data-theme]) .plan-bg-day { display: none; }
html:not([data-theme]) .plan-bg-night { display: block; }
.plan-pic { position: absolute; overflow: hidden; background: rgba(250, 246, 236, 0.9); pointer-events: none; }
.plan-pic img, .plan-pic .plan-empty { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: flex; align-items: center; justify-content: center; }
.plan-empty { color: #6A6458; font-size: 0.7rem; letter-spacing: 0.08em; }
.plan-room { position: absolute; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; border-radius: 4px; }
.plan-room:active, .plan-room:focus-visible { background: rgba(43, 92, 196, 0.08); }
.plan-label { position: absolute; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem; line-height: 1.25; }
.plan-name { font-family: var(--mincho); font-size: clamp(0.78rem, 3.4vw, 1.02rem); letter-spacing: 0.14em; color: #2C3D4B; }
.plan-count { font-size: clamp(0.66rem, 2.8vw, 0.8rem); color: #5A6B78; }
html:not([data-theme]) .plan-name { color: #EEF1F7; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
html:not([data-theme]) .plan-count { color: #C5CDDC; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.plan-all { position: absolute; left: 6%; top: 82%; width: 38%; min-height: 44px; padding: 0 0.6rem; border: 1px solid rgba(181, 155, 112, 0.8); border-radius: 999px; background: rgba(255, 255, 255, 0.88); color: #2C3D4B; font: inherit; font-size: clamp(0.74rem, 3.2vw, 0.88rem); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; }
html:not([data-theme]) .plan-all { background: rgba(13, 19, 32, 0.85); color: #EEF1F7; border-color: rgba(201, 169, 110, 0.8); }
.plan-all .plan-count { color: inherit; opacity: 0.75; }
.plan-here, .plan-entrance { position: absolute; transform: translateX(-50%); pointer-events: none; font-size: clamp(0.62rem, 2.6vw, 0.76rem); letter-spacing: 0.12em; white-space: nowrap; }
.plan-here { left: 66.4%; top: 74.6%; color: #2B5CC4; font-weight: 600; }
.plan-here::after { content: ''; display: block; width: 0; height: 0; margin: 1px auto 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 6px solid currentColor; }
html:not([data-theme]) .plan-here { color: #9DBEFF; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); }
.plan-entrance { left: 66.4%; top: 92.4%; color: #5A6B78; font-family: var(--mincho); letter-spacing: 0.4em; }
html:not([data-theme]) .plan-entrance { color: #C5CDDC; }
.floor-look { display: block; margin: 1.2rem auto 0; }
.chip-look { margin-top: 0.4rem; }
.is-map .rooms, .is-map .room-hint, .is-map .tools, .is-map #grid, .is-map #empty, .is-map #select-btn, .is-map #map-btn { display: none !important; }
.cover-cameo { width: 168px; height: 168px; margin-bottom: 1.2rem; filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.45)); }
.pic-illust { left: 17.29%; top: 14.58%; width: 23.54%; height: 14.52%; }
.pic-photo { left: 61.33%; top: 14.58%; width: 21.48%; height: 14.52%; }
.pic-doc { left: 17.29%; top: 49.48%; width: 27.15%; height: 13.48%; }
.hit-illust { left: 6.64%; top: 6.51%; width: 44.34%; height: 31.25%; }
.hit-photo { left: 53.22%; top: 6.51%; width: 40.23%; height: 31.25%; }
.hit-doc { left: 6.64%; top: 40.10%; width: 48.05%; height: 35.94%; }
.hit-illust .plan-label { top: 1.67%; height: 20.21%; }
.hit-photo .plan-label { top: 1.67%; height: 20.21%; }
.hit-doc .plan-label { top: 4.35%; height: 17.75%; }

/* ─── 表示の設定 ─── */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg-btn { min-height: 44px; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.92rem; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line-strong); }
.seg-btn[aria-checked="true"] { background: var(--deep); color: var(--mist); }
.swatches, .frames-pick { display: grid; gap: 0.5rem; }
.swatches { grid-template-columns: repeat(3, 1fr); }
.frames-pick { grid-template-columns: repeat(3, 1fr); }
.swatch-btn, .frame-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  min-height: 44px; padding: 0.6rem 0.3rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--mist);
  font: inherit; font-size: 0.78rem; line-height: 1.4; cursor: pointer;
}
.swatch-btn[aria-checked="true"], .frame-btn[aria-checked="true"] { border-color: var(--accent-line); background: var(--deep); }
.swatch { width: 44px; height: 30px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.12); }
.sw-sky { background: linear-gradient(135deg, #F4F9FC 0 45%, #AEC5D2 45% 70%, #2B5CC4 70%); }
.sw-hydrangea { background: linear-gradient(135deg, #F8F7FB 0 45%, #8B7CA5 45% 70%, #2B5CC4 70%); }
.sw-white { background: linear-gradient(135deg, #FAF7F0 0 45%, #B59B70 45% 70%, #2459A6 70%); }
.fp { position: relative; width: 38px; height: 46px; background: var(--thumb-fill); }
.fp::after { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, var(--hydrangea-blue), var(--hydrangea)); opacity: 0.8; }
.fp-line { outline: 1px solid var(--line-strong); }
.fp-mat { box-shadow: 0 0 0 6px var(--mat), 0 0 0 7px var(--line-strong); margin: 7px 0; }
.fp-milgrain { box-shadow: 0 0 0 1px var(--metal-pt); outline: 4px dotted var(--metal-pt); outline-offset: 1px; margin: 4px 0; }
.fp-claw { outline: 1px solid var(--metal-pt); }
.fp-claw::before { content: ""; position: absolute; inset: -3px; z-index: 1; --c: radial-gradient(circle, var(--metal-pt) 0 3px, transparent 3.6px); background: var(--c) 0 0 / 8px 8px no-repeat, var(--c) 100% 0 / 8px 8px no-repeat, var(--c) 0 100% / 8px 8px no-repeat, var(--c) 100% 100% / 8px 8px no-repeat; }
.fp-pt { box-shadow: 0 0 0 3px var(--metal-pt); margin: 3px 0; }
.fp-au { box-shadow: 0 0 0 3px var(--metal-au); margin: 3px 0; }
