/*
 * Instagram の内蔵ブラウザで開かれる前提。実測（iPhone 17 / iOS 26.6）で
 *   screen 393x852 に対し window は 393x649（上下のUIが203px食う）
 *   env(safe-area-inset-*) は 0 を返す
 * ＝ 画面下端に置いたボタンはツールバーに隠れる。だから下に余白を自前で確保する。
 */
:root {
  --bg: #141019;
  --panel: #1e1830;
  --line: #322a3f;
  --text: #f2eef7;
  --muted: #a99cbb;
  --accent: #7c5cd6;
  --accent-soft: #3b2f57;
  --good: #6ee7a8;
  --bad: #ff8095;
  --bottom-guard: 64px; /* Instagram のツールバー逃げ（実測 約56px + 余裕） */
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.app { max-width: 520px; margin: 0 auto; padding: 10px 12px calc(var(--bottom-guard) + 96px); }

.head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.head h1 { font-size: 18px; margin: 0; letter-spacing: .02em; }
.meta { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }

.pano-wrap { margin-top: 8px; }
#pano { width: 100%; aspect-ratio: 4 / 3; max-height: 24vh; background: #0e0b13; border-radius: 12px; overflow: hidden; }
.error { color: var(--bad); font-size: 13px; }

.hint {
  margin: 10px 0 0; padding: 8px 12px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}

.answer { margin-top: 8px; }
.chosen { text-align: center; font-size: 18px; font-weight: 800; min-height: 26px; }

.map {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 21px);
  gap: 2px;
  margin-top: 6px;
}
.tile {
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 3px;
  background: var(--accent-soft); color: #cfc3e0;
  font: 700 8.5px/1 inherit; font-family: inherit;
  white-space: nowrap; letter-spacing: -.06em; -webkit-appearance: none; cursor: pointer;
  min-width: 0; min-height: 0; overflow: hidden;
}
.tile.is-selected { background: var(--accent); color: #fff; }
.tile.is-correct { background: var(--good); color: #10331f; }
.tile.is-chosen { background: var(--bad); color: #3a0f18; }
.tile:disabled { cursor: default; opacity: 1; }

.actions[hidden] { display: none; }
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 8px;
  max-width: 520px; margin: 0 auto;
  padding: 12px 12px calc(var(--bottom-guard) + 12px);
  background: linear-gradient(to top, var(--bg) 72%, rgba(20, 16, 25, 0));
}
.btn {
  flex: 1; padding: 15px 12px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font: 700 16px inherit; font-family: inherit;
  -webkit-appearance: none; cursor: pointer;
}
.btn.ghost { background: var(--panel); border: 1px solid var(--line); }
.btn:disabled { opacity: .4; }

.result { margin-top: 18px; text-align: center; }
.score { font-size: 44px; font-weight: 900; }
.score.is-correct { color: var(--good); }
.note { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.note a { color: var(--text); }
.card-preview[hidden] { display: none; }
.card-preview { display: block; width: 46%; margin: 0 auto 12px; border-radius: 10px; border: 1px solid var(--line); }

.archive { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 14px; }
.archive h2 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.archive-list { display: flex; flex-wrap: wrap; gap: 6px; }
.archive-item {
  padding: 8px 12px; border-radius: 999px; font-size: 13px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
}
.foot { margin-top: 22px; font-size: 11px; color: var(--muted); text-align: center; }
