/* Cipher Mind Daily — styles. Light/dark, phone-first, no images, no webfonts. */

:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe3ef;
  --line-strong: #b8c4d6;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --slot: #eef2f8;
  --banner-h: 0px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f16;
    --panel: #131a26;
    --ink: #e6edf7;
    --muted: #93a4bb;
    --line: #24303f;
    --line-strong: #33415a;
    --accent: #818cf8;
    --accent-ink: #0b0f16;
    --slot: #182130;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The sheets are laid out with display:flex, which overrides the default
   [hidden] rule — an invisible sheet would then sit on top of the board and
   swallow every tap. This keeps `hidden` authoritative. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: var(--banner-h); }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 12px 18px;
  display: flex;
  flex-direction: column;
  /* The native banner is an overlay: it does not shrink the webview. The app
     column is pinned to the viewport minus the banner (-h is published by
     ads.js) and never scrolls as a whole, so the control row can not slide
     underneath the ad. Only the board absorbs or releases height. */
  height: calc(100vh - var(--banner-h));
  overflow: hidden;
}

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: 0 0 30px; display: block; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-word { font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
.brand-word span { color: var(--accent); }
.about-button {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.about-button:active { background: var(--slot); }

/* ----------------------------------------------------------------- hud */
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 5px 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.hud-item { white-space: nowrap; }
.hud-item strong { color: var(--ink); font-weight: 700; }

.status {
  margin: 7px 2px;
  font-size: 13.5px;
  color: var(--muted);
  min-height: 20px;
}

/* --------------------------------------------------------------- board */
/* The stage owns every pixel between the status line and the controls: the
   board panel grows into it so the feedback legend and the colour palette sit
   directly under the board instead of floating above a dead gap. */
.stage { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.board-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px;
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}
/* Rows keep their natural height; the leftover space is shared out BETWEEN
   them (space-between), so the panel reaches the palette instead of leaving a
   dead gap. If a short screen can not fit every row, the board scrolls on its
   own rather than pushing the controls under the banner. */
.board {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 auto;
  min-height: 0;
  justify-content: space-between;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 4px;
  border-radius: 9px;
  border: 1px solid transparent;
  flex: 0 0 auto;
}
.row-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.row-done { opacity: 0.92; }
.row-no {
  width: 17px;
  flex: 0 0 17px;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.row-pegs { display: flex; gap: 5px; flex: 1 1 auto; }
.row-fb { flex: 0 0 auto; display: flex; align-items: center; min-width: 44px; justify-content: flex-end; }

.peg {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16);
}
.peg-empty {
  background: var(--slot);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.peg-locked { box-shadow: inset 0 0 0 2px var(--ink); }

.fb { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; max-width: 56px; }
.fb-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}
.fb-exact { background: var(--ink); }
.fb-mis { background: transparent; border: 2px solid var(--ink); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 7px 2px 0;
  font-size: 11.5px;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }

/* ------------------------------------------------------------ controls */
.controls { margin-top: 9px; display: flex; flex-direction: column; gap: 9px; }
.palette { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; }
.pal-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid transparent;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16);
}
.pal-btn.sel { border-color: var(--ink); transform: scale(1.06); }

.controls-row { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.ctl-btn {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.ctl-btn:active { background: var(--slot); }
.ctl-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ctl-btn:disabled { opacity: 0.45; }
.ctl-wide { flex: 1 1 auto; }
.ctl-label { font-size: 12.5px; color: var(--muted); }
.ctl-select {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 14px;
}

/* --------------------------------------------------------------- sheet */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  padding: 12px;
  /* The sheets are fixed to the viewport, so the native banner overlay would
     cover the last lines of a long About card. Lift the whole sheet by the
     reserved banner height and cap the card accordingly. */
  padding-bottom: calc(12px + var(--banner-h));
}
.sheet-center { align-items: center; }
.sheet-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  max-width: 420px;
  max-height: calc(88vh - var(--banner-h));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head h2 { margin: 0 0 6px; font-size: 19px; }
.about-body { font-size: 14px; line-height: 1.5; color: var(--ink); margin: 8px 0; }
.about-meta { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.icon-button {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}
.button {
  width: 100%;
  border-radius: 11px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
}
.button-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* The toast sits ABOVE the control buttons (--controls-h is measured in JS),
   never on top of them: a toast that covers Submit/Clear makes the game
   unusable at the moment it appears. It never covers the HUD either. */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--controls-h, 150px) + var(--banner-h) + 12px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13.5px;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 14px rgba(2, 6, 23, 0.3);
}

@media (max-width: 380px) {
  .peg { width: 24px; height: 24px; flex-basis: 24px; font-size: 12px; }
  .pal-btn { width: 38px; height: 38px; font-size: 16px; }
  .row-fb { min-width: 38px; }
}
