:root {
  --bg: #0a0e1a;
  --bg-2: #121a30;
  --panel: #0f1830;
  --panel-2: #0d1426;
  --line: #233152;
  --ink: #e8eefc;
  --muted: #8b97b8;
  --accent: #5ee0c0;
  --accent-2: #ff5d8f;
  --glow: 0 0 18px rgba(94, 224, 192, 0.45);
  --font: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo",
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(40, 60, 120, 0.45) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 70%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  margin: 0;
  font-size: 22px;
  letter-spacing: 4px;
  color: var(--accent);
  text-shadow: var(--glow);
}
.brand-sub {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--muted);
  margin-left: 8px;
}
.topbar-game { display: flex; align-items: center; gap: 12px; }
.hud-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
}
.hud-label { font-size: 11px; letter-spacing: 2px; color: var(--muted); margin-right: 6px; }
.hud-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
#lives { color: var(--accent-2); letter-spacing: 2px; }
.ghost-btn {
  font-family: inherit;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.ghost-btn:hover { color: var(--accent-2); border-color: var(--accent-2); }

/* ---------- Home ---------- */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.panel-title {
  margin: 0;
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--accent);
}
.learn-panel .panel-title { color: #7fa6ff; }
.panel-title span { font-size: 13px; letter-spacing: 4px; color: var(--muted); margin-left: 8px; }
.panel-blurb { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.panel-list { display: flex; flex-direction: column; gap: 10px; }
.list-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  font-family: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.list-btn:hover { transform: translateY(-2px); border-color: #7fa6ff; background: #131e3a; }
.list-jp { font-size: 26px; min-width: 56px; color: #7fa6ff; }
.list-en { font-size: 16px; }
.list-en em { color: var(--muted); font-style: normal; font-size: 13px; }

/* ---------- Play config ---------- */
.config-block { display: flex; flex-direction: column; gap: 8px; }
.config-label { font-size: 12px; letter-spacing: 2px; color: var(--muted); }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice {
  font-family: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.choice:hover { transform: translateY(-1px); border-color: var(--accent); }
.choice.active {
  border-color: var(--accent);
  background: rgba(94, 224, 192, 0.12);
  box-shadow: var(--glow);
}
.choice-jp { font-size: 17px; font-weight: 700; }
.choice-en { font-size: 12px; color: var(--muted); }

.start-btn {
  margin-top: 4px;
  font-family: inherit;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: 12px;
  padding: 13px;
  cursor: pointer;
  box-shadow: var(--glow);
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.start-btn:hover:not(:disabled) { transform: translateY(-2px); background: #7df0d4; }
.start-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.play-hint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Game stage ---------- */
.stage-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255,255,255,0.05);
}
#game {
  display: block;
  width: 100%;
  height: auto;
  background:
    radial-gradient(900px 400px at 50% 110%, rgba(94,224,192,0.10), transparent 60%),
    linear-gradient(180deg, #070b16 0%, #0b1326 100%);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: rgba(6, 10, 20, 0.82);
  backdrop-filter: blur(4px);
}
.overlay h2 { margin: 0; font-size: 34px; letter-spacing: 3px; color: var(--accent); text-shadow: var(--glow); }
.overlay h2 .sub { display: block; font-size: 14px; letter-spacing: 4px; color: var(--muted); margin-top: 6px; }
.final-score { font-size: 26px; margin: 0; }
.best-score { font-size: 16px; color: var(--muted); margin: 0; }
.final-score span, .best-score span { color: var(--accent); font-weight: 700; }
.killed-label { margin: 4px 0 0; color: var(--muted); font-size: 13px; letter-spacing: 1px; }
.killed-cards { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.killed-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 120px;
  max-width: 180px;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--accent-2);
  border-radius: 12px;
  box-shadow: 0 0 16px rgba(255, 93, 143, 0.25);
}
.kc-display { font-size: 30px; font-weight: 700; color: var(--ink); }
.kc-read { font-size: 13px; color: var(--accent); font-family: ui-monospace, Menlo, monospace; }
.kc-mean { font-size: 13px; color: var(--muted); text-align: center; }

.overlay-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.mode-btn {
  font-family: inherit;
  font-size: 17px;
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: 10px;
  padding: 11px 26px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 1px;
  transition: transform 0.08s, background 0.2s;
  box-shadow: var(--glow);
}
.mode-btn:hover { transform: translateY(-2px); background: #7df0d4; }
.mode-btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); box-shadow: none; }
.mode-btn.ghost:hover { color: var(--ink); border-color: var(--ink); }

/* ---------- Input bar ---------- */
.input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
}
.input-bar .prompt { color: var(--accent); font-weight: 700; font-size: 20px; }
#answer {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 20px;
  letter-spacing: 1px;
}
#answer::placeholder { color: #4a597a; }
#answer:disabled { opacity: 0.5; }
.foot { min-height: 22px; text-align: center; }
.meaning { color: var(--muted); font-size: 14px; letter-spacing: 1px; }

/* ---------- Reference modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 14, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-box {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: min(820px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 20px; letter-spacing: 2px; color: var(--accent); }
.modal-close {
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 15px;
}
.modal-close:hover { color: var(--accent-2); border-color: var(--accent-2); }
.modal-content { padding: 18px 20px; overflow: auto; }

.grid-group { margin: 18px 0 10px; color: var(--muted); font-size: 13px; letter-spacing: 2px; text-transform: uppercase; }
.grid-group:first-child { margin-top: 0; }
.kana-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
}
.kana-cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kc-kana { font-size: 24px; }
.kc-romaji { font-size: 12px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }

.ref-search {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  outline: none;
}
.ref-search:focus { border-color: var(--accent); }
.table-scroll { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.ref-table th, .ref-table td { text-align: left; padding: 9px 14px; border-bottom: 1px solid rgba(35, 49, 82, 0.6); }
.ref-table thead th {
  position: sticky;
  top: 0;
  background: #16213d;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.ref-table tbody tr:hover { background: rgba(94, 224, 192, 0.06); }
.ref-table td:first-child { font-size: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .home-grid { grid-template-columns: 1fr; }
  .brand { font-size: 17px; letter-spacing: 2px; }
  .brand-sub { display: none; }
}
