:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #1a222e;
  --line: #2a3645;
  --text: #e8eef5;
  --muted: #8595a8;
  --accent: #4ea1ff;
  --good: #46d39a;
  --warn: #ffb454;
  --bad: #ff6b6b;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Top HUD ---------- */
/* thin life bar pinned to the very top edge */
.stakes-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  z-index: 520;
  background: rgba(255, 255, 255, 0.1);
}

.hud {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  pointer-events: none;
}
.hud .hud-restart { pointer-events: auto; }
.stat .v.pool { color: var(--warn); }

.hud .brand {
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 15px;
}
.hud .brand span { color: var(--accent); }

.hud .spacer { flex: 1; }

/* the stats live in one floating glass pill at the top-right, so they read as a
   distinct control instead of blending into the answer map underneath */
.hud-stats {
  pointer-events: auto;
  display: flex;
  align-items: stretch;
  padding: 6px 2px;
  border-radius: 14px;
  background: rgba(9, 13, 19, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px) saturate(1.3);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  line-height: 1;
  padding: 2px 15px;
}
.stat + .stat { border-left: 1px solid rgba(255, 255, 255, 0.09); }
.stat .k {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.stat .v { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .v.pool { color: var(--warn); }
.stat .v.total { color: var(--good); }

/* ---------- Play area: two full-height square panes ---------- */
.play-panels {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;                 /* breathing room between the two squares */
  padding: 58px 22px 22px;   /* top reserves the HUD; sides/bottom frame it */
}
.play-pane {
  position: relative;
  width: var(--pane, 600px);
  height: var(--pane, 600px);
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--line), 0 12px 48px rgba(0, 0, 0, 0.5);
  background: #07131d;
}
/* the puzzle (clue) map fills its pane */
#puzzle-map {
  position: absolute;
  inset: 0;
  background: #07131d; /* dark ocean — softens any tile-load flash */
  cursor: default;
}
/* hide leaflet attribution flag overlap a touch */
.leaflet-control-attribution { font-size: 10px !important; opacity: 0.6; }

/* caption tab on each pane (top-left, clear of the Leaflet attribution) */
.pane-cap {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 460;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text);
  background: rgba(7, 11, 16, 0.8);
  border-bottom-right-radius: 8px;
  pointer-events: none;
}

/* action buttons overlaid on each pane (引く on the clue, 確定 on the map) */
.pane-action {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 470;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 20px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(14, 21, 30, 0.66);
  backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease,
    border-color 0.18s ease, opacity 0.15s ease;
}
.pane-action:hover {
  transform: translateX(-50%) translateY(-2px);
  background: rgba(22, 31, 43, 0.8);
  border-color: rgba(255, 255, 255, 0.22);
}
.pane-action:active { transform: translateX(-50%) translateY(0); }
.pane-action:disabled {
  opacity: 0.4;
  transform: translateX(-50%);
  box-shadow: none;
}
.pane-action .lbl { font-size: 15px; }

/* 確定 — bright primary call to action with a soft accent glow */
.pane-action.primary {
  border-color: rgba(255, 255, 255, 0.28);
  background: linear-gradient(135deg, #6fb4ff 0%, #4ea1ff 60%, #3d8ef0 100%);
  color: #03101c;
  box-shadow: 0 10px 28px rgba(78, 161, 255, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.pane-action.primary:hover {
  background: linear-gradient(135deg, #8cc4ff 0%, #5aa9ff 60%, #4ea1ff 100%);
  box-shadow: 0 12px 32px rgba(78, 161, 255, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* 引く — small cost chip after the label */
.btn-zoom .sub {
  font-size: 11px;
  font-weight: 800;
  color: var(--warn);
  background: rgba(255, 180, 84, 0.16);
  border: 1px solid rgba(255, 180, 84, 0.34);
  padding: 3px 8px;
  border-radius: 999px;
  line-height: 1;
}

/* the thin top life-bar fill */
.stakes-fill {
  height: 100%;
  width: 100%;
  background: var(--good);
  transition: width 0.28s ease, background 0.28s ease;
}

/* flash the 持ち点 number when it drops */
.stat .v.drop { animation: pooldrop 0.45s ease; }
@keyframes pooldrop {
  0% { color: var(--bad); transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* restart chip in the HUD */
.hud-restart {
  pointer-events: auto;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(7, 11, 16, 0.5);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.hud-restart:hover { color: var(--text); background: rgba(7, 11, 16, 0.7); }

/* first-visit coach tooltip (teaches 引く → 回答 by doing) */
.coach {
  position: absolute;
  bottom: 150px;
  left: 50%;
  z-index: 510;
  transform: translateX(-50%);
  background: var(--accent);
  color: #04121f;
  font-weight: 700;
  font-size: 13px;
  padding: 9px 15px;
  border-radius: 11px;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  animation: coachpulse 1.4s ease-in-out infinite;
}
.coach::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--accent);
}
.coach[hidden] { display: none; }
@keyframes coachpulse {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

/* the point you must locate — fixed at the puzzle frame centre */
.puzzle-target {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  z-index: 400;
  pointer-events: none;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.55), 0 0 10px rgba(0, 0, 0, 0.5);
}
.puzzle-target::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 13px 22px;
  border-radius: 12px;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease,
    opacity 0.15s ease;
}
button:hover { background: #222d3c; border-color: #38465a; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  background: linear-gradient(135deg, #6fb4ff, #4ea1ff);
  border-color: rgba(255, 255, 255, 0.25);
  color: #04121f;
  box-shadow: 0 8px 22px rgba(78, 161, 255, 0.35);
}
button.primary:hover {
  background: linear-gradient(135deg, #8cc4ff, #5aa9ff);
  border-color: rgba(255, 255, 255, 0.35);
}

/* X (旧Twitter) share button */
.btn-x {
  background: #000;
  border-color: #2f2f33;
  color: #fff;
  font-weight: 700;
}
.btn-x:hover { background: #15171a; border-color: #45474d; }

kbd {
  font-family: "SFMono-Regular", ui-monospace, "Cascadia Mono", Menlo, monospace;
  font-size: 0.82em;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: #0d141d;
  color: var(--muted);
  vertical-align: baseline;
  white-space: nowrap;
}
button kbd {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.18);
  color: inherit;
  margin-left: 6px;
}
button.primary kbd {
  background: rgba(0, 0, 0, 0.18);
  border-color: rgba(0, 0, 0, 0.25);
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 8, 12, 0.72);
  backdrop-filter: blur(3px);
}
.overlay.show { display: flex; }

.card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card h2 {
  margin: 0;
  padding: 18px 22px;
  font-size: 17px;
  border-bottom: 1px solid var(--line);
}
.card .body { padding: 18px 22px; }
.card .foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
}

/* answer map fills the right pane */
#answer-map {
  position: absolute;
  inset: 0;
  background: #aadaff;
  outline: none;
}

/* grid of selectable blocks over the answer map */
.answer-grid {
  position: absolute;
  inset: 0;
  z-index: 455;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(20, 30, 50, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(20, 30, 50, 0.16) 1px, transparent 1px);
  background-size: var(--cw, 40px) 100%, 100% var(--ch, 40px);
}
.grid-sel {
  position: absolute;
  z-index: 456;
  pointer-events: none;
  box-sizing: border-box;
  border: 2px solid var(--accent);
  background: rgba(78, 161, 255, 0.28);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 16px rgba(78, 161, 255, 0.55);
  transition: left 0.08s ease, top 0.08s ease;
}
/* directional chevrons on the selector — show it moves with the arrow keys */
.grid-sel .nub {
  position: absolute;
  font-size: 10px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.9), 0 1px 2px rgba(0, 0, 0, 0.7);
  animation: nubpulse 1.6s ease-in-out infinite;
}
.grid-sel .nub.up    { top: -13px;    left: 50%; transform: translateX(-50%); }
.grid-sel .nub.down  { bottom: -13px; left: 50%; transform: translateX(-50%); }
.grid-sel .nub.left  { left: -12px;   top: 50%;  transform: translateY(-50%); }
.grid-sel .nub.right { right: -12px;  top: 50%;  transform: translateY(-50%); }
@keyframes nubpulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* movement key legend on the answer pane (bottom-left, mirrors 確定) */
.move-hint {
  position: absolute;
  left: 12px;
  bottom: 16px;
  z-index: 470;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(13, 20, 29, 0.78);
  border: 1px solid var(--line);
  backdrop-filter: blur(2px);
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}
.move-hint .keys { display: inline-flex; gap: 3px; }
.move-hint kbd {
  margin: 0;
  padding: 1px 4px;
  font-size: 11px;
  font-family: inherit;
}
.move-hint .lbl { letter-spacing: 0.04em; }
/* result */
.result-band {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 14px;
}
.result-band.band-full { color: var(--good); }
.result-band.band-area { color: var(--accent); }
.result-band.band-near { color: var(--warn); }
.result-band.band-miss { color: var(--bad); }
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.result-grid .cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.result-grid .cell .k { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }
.result-grid .cell .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-truth { font-size: 15px; }
.result-truth b { color: var(--accent); }
.result-pts { color: var(--good); }

/* lean start card — one line, then play */
.start-card {
  width: min(380px, 100%);
  padding: 30px 26px 26px;
  text-align: center;
}
.start-brand {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.start-brand span { color: var(--accent); }
.start-tag {
  margin: 6px 0 22px;
  color: var(--muted);
  font-size: 15px;
  letter-spacing: 0.04em;
}
.mode-pick {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.mode-btn {
  flex: 1;
  max-width: 150px;
  padding: 15px 0;
  font-size: 16px;
  font-weight: 700;
}

.final-score {
  text-align: center;
  font-size: 56px;
  font-weight: 800;
  color: var(--good);
  font-variant-numeric: tabular-nums;
  margin: 6px 0 2px;
}
.final-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.final-pattern {
  text-align: center;
  font-size: 22px;
  letter-spacing: 3px;
  line-height: 1.3;
  word-break: break-all;
}

@media (max-width: 560px) {
  .hud .brand { font-size: 15px; }
  .stat .v { font-size: 15px; }
}
