/* Maths - minimalist dark. Deep blue-green field, one bright accent. */

:root {
  --bg: #070b11;
  --panel: #0d151d;
  --line: #1b2836;
  --text: #e6f4f8;
  --dim: #7b93a6;
  --accent: #2ee6c0;
  --accent-ink: #06231d;
  --bad: #ff5d73;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------------------- HUD */

#hud {
  flex: 0 0 auto;
  align-self: center;      /* width is set to the field's width in relayout() */
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 8px 10px 6px;
  transition: opacity 0.25s ease;
}
#hud.dim { opacity: 0.32; }

.stat {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.lbl {
  font-size: 8px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
  white-space: nowrap;
}
.val {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

#xp-pips { display: inline-flex; gap: 3px; }
.pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1d2b39;
  box-shadow: inset 0 0 0 1px #26384a;
  transition: background 0.18s ease, box-shadow 0.18s ease;
}
.pip.on {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(46, 230, 192, 0.55);
}
#xp-num { font-size: 12px; color: var(--dim); }

.stat.good .val { color: var(--accent); text-shadow: 0 0 14px rgba(46, 230, 192, 0.35); }
.stat.bad .val { color: var(--bad); text-shadow: 0 0 14px rgba(255, 93, 115, 0.3); }

.icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(19, 30, 41, 0.7);
  color: var(--dim);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { color: var(--accent); border-color: rgba(46, 230, 192, 0.4); }

/* ----------------------------------------------------------------- stage */

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 8px;
  /* a wide window leaves space either side of the field; a faint grid there
     keeps it looking like part of the room rather than a hole */
  background-image:
    linear-gradient(rgba(120, 200, 220, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 200, 220, 0.022) 1px, transparent 1px);
  background-size: 46px 46px;
}

#field {
  display: block;
  border-radius: 18px;
  background: #0a1017;
  box-shadow: 0 0 0 1px #16222e, 0 18px 46px rgba(0, 0, 0, 0.55);
  touch-action: none;
  cursor: grab;
}
#field:active { cursor: grabbing; }

/* --------------------------------------------------------------- overlay */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(7, 11, 17, 0.74);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  overflow-y: auto;
  animation: fade 0.18s ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.screen {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}
.screen.hidden { display: none; }

h1 {
  margin: 0;
  font-size: clamp(38px, 13vw, 58px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}
h1::after {
  content: "";
  display: block;
  width: 46px;
  height: 3px;
  border-radius: 2px;
  margin: 12px auto 0;
  background: var(--accent);
}
h2 {
  margin: 0;
  font-size: clamp(20px, 6vw, 26px);
  font-weight: 700;
  letter-spacing: 0.01em;
}
.tag {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--dim);
  max-width: 30ch;
}
.big {
  margin: 0;
  font-size: clamp(46px, 15vw, 68px);
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 34px rgba(46, 230, 192, 0.3);
}

.row {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.btn {
  flex: 1 1 0;
  max-width: 190px;
  min-height: 50px;
  padding: 0 20px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  background: rgba(21, 33, 45, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.btn:hover { border-color: rgba(46, 230, 192, 0.45); }
.btn:active { transform: scale(0.975); }
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  box-shadow: 0 8px 26px rgba(46, 230, 192, 0.24);
}
.btn.primary:hover { background: #4ff0cd; }

.pick {
  margin: 2px 0 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
}
.pick b { color: var(--accent); }
.pick .sub {
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 10px;
  font-weight: 500;
  color: #54708a;
}

.levels { display: flex; gap: 4px; width: 100%; justify-content: center; }
.level-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 42px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--dim);
  background: rgba(21, 33, 45, 0.85);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.level-btn:hover { color: var(--text); }
.level-btn.on {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.level-btn.locked {
  opacity: 0.34;
  cursor: not-allowed;
  color: #4b6076;
}
.level-btn.done::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.level-btn.on.done::after { background: var(--accent-ink); }

.note { margin: -6px 0 0; font-size: 11.5px; color: #5c7183; }
.hint {
  margin: 0;
  font-size: 12px;
  color: var(--dim);
  line-height: 1.9;
}
kbd {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: rgba(21, 33, 45, 0.9);
  color: var(--text);
}
.best { margin: 0; font-size: 12.5px; color: var(--accent); font-weight: 600; }
.best.hidden, .board.hidden { display: none; }

.stats { display: flex; gap: 30px; justify-content: center; }
.stats > div { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.stats b { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }

.board { width: 100%; }
.board ol {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.board li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 13px;
  background: rgba(21, 33, 45, 0.5);
}
.board li.mine { background: rgba(46, 230, 192, 0.13); color: var(--accent); }
.board .rk { width: 16px; color: var(--dim); font-weight: 700; }
.board li.mine .rk { color: var(--accent); }
.board .who { flex: 1 1 auto; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .val { font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-height: 620px) {
  h1 { font-size: 34px; }
  h1::after { margin-top: 8px; }
  .screen { gap: 10px; }
  .btn { min-height: 44px; }
  .tag { font-size: 12px; }
}

/* ---------------------------------------------------------------- debug */

@media (max-width: 380px) {
  #hud { gap: 2px; padding: 7px 6px 5px; }
  .lbl { font-size: 6.5px; letter-spacing: 0.03em; }
  .val { font-size: 12.5px; gap: 3px; }
  #xp-num { font-size: 11px; }
  .icon-btn { width: 30px; height: 30px; border-radius: 9px; }
}

#debug-panel {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 50;
  margin: 0;
  padding: 8px 10px;
  max-width: min(92vw, 440px);
  font: 11px/1.45 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: #9fd8cf;
  background: rgba(6, 12, 16, 0.9);
  border: 1px solid rgba(46, 230, 192, 0.25);
  border-radius: 8px;
  white-space: pre;
  pointer-events: none;
  overflow: hidden;
}
#debug-panel.hidden { display: none; }

