:root {
  --bg: #08120d;
  --panel: #0d1a14;
  --panel-2: #12241b;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #edf4ef;
  --muted: #8fa39a;
  --accent: #9fe870;
  --accent-dim: rgba(159, 232, 112, 0.16);
  --danger: #ff6b7d;
  --cell: 30px;
  --gap: 2px;
  --covered-a: #37493f;
  --covered-b: #22302a;
  --open: #0e1a15;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at 12% -10%, rgba(159, 232, 112, 0.14), transparent 26rem),
    radial-gradient(circle at 92% 108%, rgba(74, 140, 100, 0.12), transparent 22rem),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; cursor: pointer; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 10px 12px 6px;
  gap: 7px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}

.brand-mark {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.9;
  stroke-linecap: round;
}

.modes {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}

.mode {
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--muted);
  transition: background 0.18s ease, color 0.18s ease;
}

.mode:hover { color: var(--text); }

.mode.is-active {
  background: var(--accent);
  color: #07120b;
}

/* ---------- level bar ---------- */
.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.levels { display: flex; gap: 4px; }

.levels button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 5px 10px;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--muted);
  transition: 0.16s ease;
}

.levels button:hover { color: var(--text); border-color: var(--line-strong); }

.levels button.is-active {
  border-color: rgba(159, 232, 112, 0.5);
  background: var(--accent-dim);
  color: var(--accent);
}

.new-game {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 5px 12px;
  font-size: 0.7rem;
  font-weight: 800;
  transition: 0.16s ease;
}

.new-game:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- daily date picker ---------- */
.daily-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--muted);
}

.daily-bar[hidden] { display: none; }

.daily-bar label { letter-spacing: 0.04em; text-transform: uppercase; }

.daily-bar input,
.daily-bar button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 5px 8px;
  font: inherit;
  color: var(--text);
  color-scheme: dark;
}

.daily-bar button:hover { background: rgba(255, 255, 255, 0.1); }

#daily-hint { font-weight: 600; color: var(--muted); }

/* ---------- hud ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015));
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 74px;
}

.hud-label {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-value {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hud-actions { display: flex; gap: 6px; margin-left: auto; }

.tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 5px 9px;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--muted);
  transition: 0.16s ease;
}

.tool svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool:hover { color: var(--text); border-color: var(--line-strong); }

.tool.is-on {
  border-color: rgba(159, 232, 112, 0.55);
  background: var(--accent-dim);
  color: var(--accent);
}

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 9), var(--cell));
  gap: var(--gap);
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #0b1712, #08110d);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  flex: none;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: calc(var(--cell) * 0.56);
  font-weight: 800;
  line-height: 1;
  overflow: hidden;
  transition: background 0.1s ease, transform 0.06s ease;
}

.cell.covered {
  background: linear-gradient(160deg, var(--covered-a), var(--covered-b));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.13), inset 0 -1px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.cell.covered:hover { background: linear-gradient(160deg, #40564a, #28392f); }
.cell.covered:active { transform: scale(0.94); }

.cell.open {
  background: var(--open);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.035);
  cursor: default;
}

.cell.open.chordable { cursor: pointer; }

.cell[data-n="1"] { color: #7cc4ff; }
.cell[data-n="2"] { color: #6ee7a8; }
.cell[data-n="3"] { color: #ff8a9b; }
.cell[data-n="4"] { color: #c4a7ff; }
.cell[data-n="5"] { color: #ffc46b; }
.cell[data-n="6"] { color: #5ee0d6; }
.cell[data-n="7"] { color: #e8e8e8; }
.cell[data-n="8"] { color: #9aa8a2; }

.cell.cursor { outline: 2px solid rgba(159, 232, 112, 0.8); outline-offset: 1px; }

.cell.hint {
  animation: hint-pulse 0.9s ease 2;
}

@keyframes hint-pulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.13); }
  50% { box-shadow: 0 0 0 3px rgba(159, 232, 112, 0.75), 0 0 18px rgba(159, 232, 112, 0.5); }
}

.cell .icon {
  width: 62%;
  height: 62%;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cell.flagged .icon { stroke: var(--accent); stroke-width: 2; }
.cell.mine { background: #2a1418; box-shadow: inset 0 0 0 1px rgba(255, 107, 125, 0.35); }
.cell.mine .icon { stroke: var(--danger); stroke-width: 1.9; }
.cell.mine-hit { background: #43131b; box-shadow: 0 0 0 2px rgba(255, 107, 125, 0.7); }
.cell.wrong .icon { stroke: var(--danger); stroke-width: 2.2; }
.cell.wrong { background: rgba(255, 107, 125, 0.1); }

/* ---------- result ---------- */
.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(4, 10, 7, 0.55);
  backdrop-filter: blur(6px);
  z-index: 5;
}

.result[hidden] { display: none; }

.result-card {
  width: min(100%, 24rem);
  border: 1px solid rgba(159, 232, 112, 0.22);
  border-radius: 18px;
  background: linear-gradient(180deg, #12211a, #0b1611);
  padding: 20px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: rise 0.22s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.result-kicker {
  margin: 0;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

.result-title {
  margin: 6px 0 14px;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 12px;
}

.result-stats div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 4px;
}

.result-stats dt {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-stats dd {
  margin: 3px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  font-weight: 700;
}

.result-note {
  margin: 0 0 14px;
  min-height: 1.2em;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted);
}

.result-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--accent);
  color: #07120b;
  padding: 8px 14px;
  font-size: 0.76rem;
  font-weight: 900;
  transition: 0.16s ease;
}

.btn:hover { background: #b4f28c; }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn.ghost {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--text);
}

.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------- trainer ---------- */
.trainer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px;
}

.trainer[hidden] { display: none; }

.trainer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 26rem);
}

.trainer-kicker {
  margin: 0;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.trainer-title { margin: 2px 0 0; font-size: 1.35rem; font-weight: 900; letter-spacing: -0.02em; }

.trainer-score { text-align: right; font-size: 0.6rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.trainer-score strong { display: block; font-size: 1.2rem; color: var(--text); letter-spacing: 0; }

.trainer-task { margin: 0; font-size: 0.84rem; font-weight: 700; color: var(--text); }

.trainer-board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), var(--cell));
  gap: 2px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #0b1712, #08110d);
  --cell: 38px;
}

.trainer-board .cell { cursor: pointer; }
.trainer-board .cell.wall { background: transparent; box-shadow: none; cursor: default; }
.trainer-board .cell.correct { box-shadow: 0 0 0 3px rgba(159, 232, 112, 0.8); }
.trainer-board .cell.wrong { box-shadow: 0 0 0 3px rgba(255, 107, 125, 0.8); }

.trainer-feedback {
  margin: 0;
  min-height: 2.6em;
  max-width: 26rem;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--muted);
}

.trainer-feedback.good { color: var(--accent); }
.trainer-feedback.bad { color: var(--danger); }

.trainer-actions { display: flex; gap: 6px; }

/* ---------- footer ---------- */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px;
  font-size: 0.64rem;
  color: var(--muted);
}

.brand-small { font-weight: 800; letter-spacing: 0.12em; opacity: 0.55; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 12px);
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(12, 24, 18, 0.95);
  font-size: 0.74rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 20;
  max-width: calc(100% - 24px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  #app { padding: 8px 8px 4px; gap: 6px; }
  .brand span { display: none; }
  .mode { padding: 6px 9px; font-size: 0.66rem; }
  .levels button { padding: 5px 8px; font-size: 0.64rem; }
  .hud { padding: 5px 8px; gap: 6px; }
  .hud-item { min-width: 62px; }
  .tool { padding: 5px 7px; font-size: 0.62rem; }
  .foot { font-size: 0.58rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
