/* Nocturne Archive — v0.2.0
 * 雨夜の紫陽花。写真が主役、装飾は退く。
 * コントラスト（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-close { position: absolute; top: calc(var(--safe-top) + 6px); right: 8px; }
.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; }
}
