:root {
  --bg: #eef3fb;
  --surface: #ffffff;
  --text: #2d2a3e;
  --muted: #6c6985;
  --line: #dfe3ef;
  --accent: #3b7cf5;
  --accent-soft: #e5eeff;
  --red: #e5484d;
  --good: #2f9e57;
  --good-soft: #e3f6ea;
  --bad: #c8333f;
  --bad-soft: #fdeaec;
  --jp: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a26; --surface: #1f2534; --text: #eef0f7; --muted: #a3a9bf; --line: #333b50;
    --accent: #7ea6ff; --accent-soft: #263456; --good: #5fd08a; --good-soft: #1d3a2a; --bad: #ff7d87; --bad-soft: #3b1d26;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151a26; --surface: #1f2534; --text: #eef0f7; --muted: #a3a9bf; --line: #333b50;
  --accent: #7ea6ff; --accent-soft: #263456; --good: #5fd08a; --good-soft: #1d3a2a; --bad: #ff7d87; --bad-soft: #3b1d26;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
[hidden] { display: none !important; }
.kana { font-family: var(--jp); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.bad { color: var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 8px 12px; }

/* top bar */
.hud { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 1.2rem; margin-right: 4px; }
.stat { font-weight: 700; font-variant-numeric: tabular-nums; white-space: pre; }
.needs { display: flex; gap: 12px; flex-wrap: wrap; flex: 1; min-width: 260px; }
.need { min-width: 92px; flex: 1; max-width: 150px; }
.need-label { font-size: .85rem; font-weight: 700; }
.need-bar { height: 9px; background: var(--line); border-radius: 99px; overflow: hidden; }
.need-bar div { height: 100%; background: var(--good); border-radius: 99px; transition: width .3s; }
.need.low .need-bar div { background: var(--red); }
.need.low .need-label { color: var(--red); }
.tools { display: flex; gap: 6px; }
.tool { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 1.2rem; }
.tool:hover { background: var(--accent-soft); }

/* game */
.layout { display: grid; gap: 16px; padding: 16px; max-width: 1320px; margin: 0 auto; }
@media (min-width: 1000px) { .layout { grid-template-columns: 1fr 260px; align-items: start; } }
.stage { position: relative; }
canvas#game { width: 100%; height: auto; display: block; border-radius: 16px; box-shadow: 0 6px 24px rgba(30, 40, 80, .15); image-rendering: auto; background: #9cd47b; }
.side { display: grid; gap: 12px; }
.side-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.side-title { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.place { display: flex; align-items: center; gap: 8px; font-size: 1.6rem; font-weight: 800; }
.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-family: var(--jp); font-size: .95rem; }
.goals .done { color: var(--muted); text-decoration: line-through; }

#banner { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; opacity: 0; }
#banner.show { animation: banner 2.6s ease forwards; }
.banner-k { font-family: var(--jp); font-size: clamp(2rem, 6vw, 3.6rem); font-weight: 800; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.25), 0 0 24px rgba(0,0,0,.35); }
.banner-en { color: #fff; font-weight: 700; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 10px); } 15%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

#toasts { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; pointer-events: none; width: 90%; }
.toast { background: rgba(45, 42, 62, .92); color: #fff; padding: 8px 14px; border-radius: 999px; font-family: var(--jp); font-size: .95rem; transition: opacity .4s; text-align: center; }
.toast.out { opacity: 0; }
.toast-e { font-size: 1.1rem; }

#fade { position: fixed; inset: 0; background: #0d1030; opacity: 0; pointer-events: none; transition: opacity .45s; z-index: 30; }
#fade.on { opacity: 1; }

/* panels */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 40, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.panel { background: var(--surface); border-radius: 20px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 0; position: sticky; top: 0; background: var(--surface); }
.panel-head h2 { margin: 0; font-size: 1.5rem; }
.panel-body { padding: 10px 18px 20px; }
.panel-body h3 { margin: 16px 0 8px; }
.icon-btn { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; min-width: 36px; height: 36px; font-size: 1rem; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 9px 16px; font-weight: 700; font-family: var(--jp); }
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.btn.danger { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; justify-content: center; }
.tabbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.say { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--accent-soft); border-radius: 14px; padding: 10px 12px; margin: 8px 0; }
.say .kana { font-size: 1.25rem; font-weight: 700; flex: 1; }
.say.big .kana { font-size: 1.6rem; }
.hint-en { width: 100%; color: var(--muted); font-style: italic; }
.keeper { display: flex; gap: 12px; align-items: center; }
.keeper .say { flex: 1; }
.big-emoji { font-size: 3rem; line-height: 1.1; }
.hearts { font-size: 1.1rem; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 10px; }
.choice { border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px; font-family: var(--jp); font-size: 1.2rem; font-weight: 700; transition: transform .1s; }
.choice:hover { border-color: var(--accent); }
.choice.big { font-size: 2.4rem; padding: 8px; }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.kana-choice { font-size: 2.2rem; }
.sign { display: inline-block; background: #fff; color: #1d2433; border: 3px solid #2c3446; border-radius: 8px; padding: 2px 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin-top: 10px; }
.card-item { border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; display: grid; gap: 4px; justify-items: center; }
.kana-btn { border: 0; background: none; font-family: var(--jp); font-weight: 800; font-size: 1.15rem; padding: 0; }
.price { font-weight: 700; }
.shop-msg { margin-top: 8px; font-family: var(--jp); }

.metro { width: 100%; height: auto; display: block; background: var(--bg); border-radius: 14px; margin: 8px 0; }
.metro .st circle { fill: #fff; stroke: #2d2a3e; stroke-width: 4; }
.metro .st text { font-family: var(--jp); font-weight: 800; font-size: 19px; fill: var(--text); }
.metro .st.here circle { fill: #ffd54a; }
.metro .st.pickable { cursor: pointer; }
.metro .st.pickable:hover circle { fill: var(--accent); }
.metro .line-label { font-family: var(--jp); font-weight: 800; font-size: 15px; }
.metro .train { font-size: 30px; }
.announce { min-height: 64px; }
.ticket-info { min-height: 40px; }

.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.row-btn { border: 2px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px; font-size: 1.15rem; font-weight: 700; }
.row-btn.done { border-color: var(--good); background: var(--good-soft); }
.kana-cards { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.kana-card { width: 92px; height: 104px; border: 2px solid var(--line); border-radius: 16px; background: var(--surface); font-family: var(--jp); font-size: 3rem; font-weight: 700; }
.kana-card.heard { border-color: var(--accent); background: var(--accent-soft); }
.word-big { font-family: var(--jp); font-size: 2.6rem; font-weight: 800; margin: 6px 0; }

.word-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.word { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; background: var(--surface); }
.word .we { grid-row: span 2; font-size: 1.6rem; }
.word .kana { font-weight: 800; }
.word .wen { font-size: .78rem; color: var(--muted); }
.word.learned { border-color: var(--good); background: var(--good-soft); }
.word.unknown { opacity: .5; }
.kana-chart { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 360px; }
.kc { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; font-family: var(--jp); font-size: 1.4rem; padding: 4px 0; }
.kc.got { border-color: var(--good); background: var(--good-soft); color: var(--good); font-weight: 800; }
.stamps { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; text-align: center; }
.stamp-in { width: 84px; height: 84px; margin: 0 auto 4px; border-radius: 50%; border: 3px dashed var(--line); display: grid; place-items: center; font-family: var(--jp); font-weight: 800; font-size: 1.1rem; color: var(--muted); }
.stamp.got .stamp-in { border: 4px double var(--red); color: var(--red); transform: rotate(-8deg); }
.friends { display: grid; gap: 6px; }
.friend { display: flex; gap: 10px; align-items: center; }
.friend .we { font-size: 1.5rem; }
.friend .kana { min-width: 110px; font-weight: 700; }
.avatars { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.avatar { font-size: 2.6rem; width: 74px; height: 74px; border: 2px solid var(--line); background: var(--surface); border-radius: 18px; }
.avatar:hover { border-color: var(--accent); background: var(--accent-soft); }
.help { padding-left: 1.2em; font-family: var(--jp); }
.help li { margin: 6px 0; }

/* money list */
.money-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 14px; }
.money-sum > div { background: var(--bg); border-radius: 12px; padding: 8px 12px; }
.money-sum b { font-size: 1.2rem; }
.m-in { color: var(--good); }
.m-out { color: var(--bad); }
.ledger { width: 100%; border-collapse: collapse; }
.ledger th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 8px; }
.ledger td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.ledger .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.player-code { font-family: ui-monospace, Menlo, monospace; font-size: 1.3rem; letter-spacing: .08em; background: var(--bg); border-radius: 10px; padding: 6px 12px; display: inline-block; }
.code-input { font: inherit; font-family: ui-monospace, Menlo, monospace; text-transform: uppercase; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); width: 16ch; }
.ledger .when { white-space: nowrap; }
@media (max-width: 520px) { .ledger th, .ledger td { padding: 6px 4px; } .money-sum { gap: 6px; } .money-sum > div { padding: 6px 8px; } }
