/* A 90s desktop: grey windows with blue title bars on a teal desktop,
   raised tiles that sink when dug, red LED counters and the classic number
   colours. Frames and tiles are all bevels: two light and two dark 1px
   edges, swapped for "sunken".

   game.js and endless.js size the board from these measurements: tiles
   touch (--gap 0), .board-scroll / .runner have a 3px border, .field is
   padded 6px and .window 3px. Change them together. */
:root {
  --desk: #008080;
  --face: #c0c0c0;       /* window and tile grey */
  --hi: #ffffff;
  --lite: #dfdfdf;
  --shadow: #808080;
  --dark: #0a0a0a;
  --navy: #000080;
  --text: #000;
  --good: #006b00;
  --bad: #c00000;
  --led: #ff1a1a;
  --gap: 0px;
  --cell: 30px;
  --cols: 9;
  --raised: inset -1px -1px var(--dark), inset 1px 1px var(--hi), inset -2px -2px var(--shadow), inset 2px 2px var(--lite);
  --sunken: inset -1px -1px var(--hi), inset 1px 1px var(--shadow), inset -2px -2px var(--lite), inset 2px 2px var(--dark);
  --ui: Tahoma, "MS Sans Serif", "Microsoft Sans Serif", "Segoe UI", Geneva, Verdana, sans-serif;
}

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

html,
body {
  margin: 0;
  background: var(--desk);
  color: var(--text);
  font-family: var(--ui);
  font-size: 13px;
}

.wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* top room for the fixed back / FX / mute buttons */
  padding: 60px 10px 2rem;
  gap: 14px;
}

/* ---- windows ------------------------------------------------------------- */
.window {
  max-width: 100%;
  padding: 3px;
  background: var(--face);
  box-shadow: var(--raised);
}
.titlebar {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 2px 3px 2px 4px;
  background: linear-gradient(90deg, var(--navy), #1084d0);
  color: #fff;
}
.titlebar .title {
  flex: 1;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
}
.tb-icon {
  font-size: 13px;
  line-height: 1;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
/* the one title-bar button, and it's real: back to the games list */
.tb-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 16px;
  padding-bottom: 2px;
  background: var(--face);
  color: var(--text);
  box-shadow: var(--raised);
  font: 700 14px/1 var(--ui);
  text-decoration: none;
}
.tb-close:active {
  box-shadow: var(--sunken);
}
.window-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 8px;
}

/* ---- Classic | Endless: the menu bar (both pages) ------------------------ */
.modes {
  display: flex;
  gap: 2px;
  padding: 2px 2px 3px;
}
.mode {
  padding: 3px 8px;
  color: var(--text);
  text-decoration: none;
}
.mode:hover {
  box-shadow: inset -1px -1px var(--shadow), inset 1px 1px var(--hi);
}
.mode.sel {
  background: var(--navy);
  color: #fff;
}
.mode.sel:hover {
  box-shadow: none;
}

/* ---- field: HUD + board ------------------------------------------------ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
  padding: 6px;
  box-shadow: inset 1px 1px var(--hi), inset -1px -1px var(--shadow);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 5px 6px;
  box-shadow: var(--sunken);
}

.led {
  font-family: "Courier New", ui-monospace, Consolas, monospace;
  font-weight: 700;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--led);
  background: #000;
  padding: 3px 4px 2px;
  min-width: 3.6ch;
  text-align: center;
  box-shadow: inset -1px -1px var(--hi), inset 1px 1px var(--shadow);
}

.face {
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
  border: none;
  background: var(--face);
  box-shadow: var(--raised);
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.face:active {
  box-shadow: inset 1px 1px var(--shadow), inset -1px -1px var(--shadow);
  padding: 2px 0 0 2px;
}
.face:focus-visible {
  outline: 1px dotted var(--text);
  outline-offset: -5px;
}

/* the sunken frame is a real border: tiles would cover an inset shadow */
.board-scroll {
  max-width: 100%;
  overflow: auto;
  background: var(--face);
  border: 3px solid;
  border-color: var(--shadow) var(--hi) var(--hi) var(--shadow);
}

/* raised-tile bevel, scaled a little with the tile; also the "from" state
   of the reveal animation. Declared here, not on :root, because the scripts
   set --cell on these two elements and a :root value would never see it. */
.board,
.runner {
  --bw: max(2px, calc(var(--cell) * 0.1));
  --bevel: inset calc(var(--bw) * -1) calc(var(--bw) * -1) 0 var(--shadow), inset var(--bw) var(--bw) 0 var(--hi);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  padding: 0;
  width: max-content;
  margin: 0 auto;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* long-press flags, it must not open the iOS callout */
  touch-action: manipulation;
}
/* .mouse: mousedown focuses the board so keys work straight after a click,
   and Chrome would otherwise treat that as :focus-visible. An outline, not an
   inset shadow, because the tiles would paint over the shadow. */
.board:focus-visible:not(.mouse) {
  outline: 2px dotted var(--navy);
  outline-offset: -2px;
}

.c {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--face);
  box-shadow: var(--bevel);
  color: var(--text);
  font-weight: 700;
  font-size: calc(var(--cell) * 0.62);
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
}
@media (hover: hover) {
  .c:not(.open):hover {
    background: #c8c8c8;
  }
}
/* dug (or held down): flat, with the thin grey grid line of an open field */
.c.down,
.c.open {
  background: var(--face);
  box-shadow: inset 1px 1px 0 var(--shadow);
}
.c.open {
  cursor: default;
}
.c.open.num {
  cursor: pointer; /* numbers chord */
}
.c.flag,
.c.mine,
.c.wrong {
  font-size: calc(var(--cell) * 0.52);
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.c.q {
  color: var(--text);
}
.c.boom {
  background: #ff0000;
}
/* a cleared board, in both FX modes: every mine, now flagged, sits on green,
   the colour endless mode gives a cleared row */
.field.won .c.flag {
  background: #9fd49f;
}
.c.cur {
  outline: 2px dotted var(--text);
  outline-offset: -4px;
}

/* the classic number colours */
.n1 { color: #0000ff; }
.n2 { color: #007b00; }
.n3 { color: #ff0000; }
.n4 { color: #00007b; }
.n5 { color: #7b0000; }
.n6 { color: #007b7b; }
.n7 { color: #000000; }
.n8 { color: #7b7b7b; }

/* Reveal ripple: each cell starts looking like a covered tile and opens
   after --d. JS only adds this class (and the delay) when Visual FX is on. */
.c.reveal {
  animation: open 0.2s ease-out var(--d, 0ms) backwards;
}
@keyframes open {
  from {
    background-color: var(--face);
    box-shadow: var(--bevel);
    font-size: 0;
  }
}
.c.pop {
  animation: pop 0.28s ease-out var(--d, 0ms) backwards;
}
@keyframes pop {
  0% { font-size: 0; }
  70% { font-size: calc(var(--cell) * 0.66); }
}

.field.shake {
  animation: shake 0.42s ease-out;
}
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-7px, 2px); }
  30% { transform: translate(6px, -3px); }
  45% { transform: translate(-4px, 2px); }
  60% { transform: translate(3px, -1px); }
  80% { transform: translate(-1px, 1px); }
}

/* pause: the shared overlay is see-through, so hide the numbers too */
.field.paused .board,
.field.paused .runner {
  filter: blur(9px);
  pointer-events: none;
}

/* ---- status bar ----------------------------------------------------------- */
/* #status, not a class: setStatus() replaces its className with the tone.
   contain: inline-size stops a long message widening the window. */
#status {
  contain: inline-size;
  margin: 3px 0 0;
  min-height: 1.6em;
  padding: 3px 6px;
  line-height: 1.3;
  box-shadow: inset 1px 1px var(--shadow), inset -1px -1px var(--hi);
}
#status:empty::before {
  content: attr(data-idle);
  color: #404040;
}
#status.good { color: var(--good); font-weight: 700; }
#status.bad { color: var(--bad); font-weight: 700; }

/* ---- controls ----------------------------------------------------------- */
.levels {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.lvl,
.btn {
  cursor: pointer;
  background: var(--face);
  color: var(--text);
  border: none;
  border-radius: 0;
  box-shadow: var(--raised);
  font-family: inherit;
  font-size: 13px;
}
.lvl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 6.4rem;
  padding: 6px 10px;
  font-weight: 700;
  line-height: 1.1;
}
.lvl small {
  font-weight: 400;
  font-size: 11px;
  color: #404040;
}
/* the chosen level stays pushed in */
.lvl.sel,
.lvl:active,
.btn:active,
#modeBtn[aria-pressed="true"] {
  box-shadow: var(--sunken);
  background:
    repeating-conic-gradient(var(--face) 0 25%, #dcdcdc 0 50%) 0 0 / 2px 2px;
}
.lvl:focus-visible,
.btn:focus-visible,
.mode:focus-visible,
.rules summary:focus-visible {
  outline: 1px dotted var(--text);
  outline-offset: -4px;
}

.custom {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  box-shadow: inset 1px 1px var(--shadow), inset -1px -1px var(--hi), inset 2px 2px var(--hi), inset -2px -2px var(--shadow);
}
.custom[hidden] {
  display: none;
}
.custom label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
}
.custom input {
  width: 4.6rem;
  padding: 4px 5px;
  border: none;
  border-radius: 0;
  background: #fff;
  color: var(--text);
  box-shadow: var(--sunken);
  font-family: inherit;
  font-size: 13px;
}
.custom input:focus {
  outline: 1px dotted var(--text);
  outline-offset: -4px;
}

.opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.btn {
  padding: 6px 14px;
  min-width: 5.5rem;
}
/* the default button gets the extra black outline */
.btn.primary {
  box-shadow: inset 0 0 0 1px var(--dark), inset -2px -2px var(--dark), inset 2px 2px var(--hi), inset -3px -3px var(--shadow), inset 3px 3px var(--lite);
  font-weight: 700;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.check input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 13px;
  height: 13px;
  background: #fff;
  box-shadow: var(--sunken);
  cursor: pointer;
}
.check input:checked {
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 13 13'%3E%3Cpath d='M3 6l2 2 5-5v2l-5 5-2-2z' fill='%23000'/%3E%3C/svg%3E") center / 13px 13px no-repeat;
}
.check input:focus-visible + span {
  outline: 1px dotted var(--text);
}

#stats {
  contain: inline-size;
  width: 100%;
  margin: 0;
  color: #202020;
  font-size: 12px;
  text-align: center;
}

/* ---- how to play: a window you can roll up --------------------------------- */
.rules {
  width: 100%;
  max-width: 520px;
  line-height: 1.45;
}
.rules summary {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
}
.rules summary::-webkit-details-marker {
  display: none;
}
.rules summary::before {
  content: "▸";
  width: 1em;
  font-size: 12px;
}
.rules[open] summary::before {
  content: "▾";
}
.rules p {
  margin: 8px 10px 0;
}
.rules p:last-child {
  margin-bottom: 10px;
}

/* ---- keycaps: little raised keys, like the buttons ----------------------- */
/* (in the windows only: the corner buttons and the pause card keep the shared
   keycaps) */
.window .gs-kbd {
  margin: 0 1px;
  padding: 2px 4px;
  border: none;
  border-radius: 0;
  background: var(--face);
  color: var(--text);
  box-shadow: var(--raised);
  font: 700 11px/1 var(--ui);
}

#byline {
  color: #d8f0f0;
  font-size: 11px;
  margin: 0;
}

/* ---- the shared pause overlay, as a dialog box ----------------------------- */
body > .gs-pause {
  background: rgba(0, 64, 64, 0.35);
  font-family: var(--ui);
}
.gs-pause .gs-pause-card {
  padding: 3px 3px 14px;
  border: none;
  border-radius: 0;
  background: var(--face);
  color: var(--text);
  box-shadow: var(--raised), 3px 3px 0 rgba(0, 0, 0, 0.35);
  min-width: 240px;
}
.gs-pause .gs-pause-card h2 {
  margin: 0 0 12px;
  padding: 4px 6px;
  background: linear-gradient(90deg, var(--navy), #1084d0);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}
.gs-pause .gs-pause-card p {
  margin: 0 12px 14px;
  color: var(--text);
  font-size: 13px;
}
.gs-pause .gs-pause-card button {
  min-height: 0;
  padding: 6px 18px;
  border: none;
  border-radius: 0;
  background: var(--face);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--dark), inset -2px -2px var(--dark), inset 2px 2px var(--hi), inset -3px -3px var(--shadow), inset 3px 3px var(--lite);
  font: 700 13px var(--ui);
}
.gs-pause .gs-pause-card button:hover {
  background: var(--face);
}
.gs-pause .gs-pause-card button:active {
  box-shadow: var(--sunken);
}
/* the copy box (GameShell.copyBox): the result in a white sunken field, the
   buttons in a row inside the window's margins; only Copy is the default */
.gs-pause .gs-pause-card textarea {
  width: calc(100% - 24px);
  margin: 0 12px 14px;
  padding: 4px 5px;
  border: none;
  border-radius: 0;
  background: #fff;
  color: var(--text);
  box-shadow: var(--sunken);
  font: 12px/1.35 var(--ui);
}
.gs-pause .gs-pause-card textarea:focus {
  outline: 1px dotted var(--text);
  outline-offset: -4px;
}
.gs-pause .gs-dialog-row {
  gap: 6px;
  padding: 0 12px;
}
.gs-pause .gs-pause-card .gs-dialog-alt {
  box-shadow: var(--raised);
}

/* ---- endless ------------------------------------------------------------ */
.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.hud-stat small {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #202020;
}

/* The viewport. Rows are absolutely placed and moved by JS every frame:
   never by a CSS transition, which Visual FX off would flatten to nothing.
   endless.js sets its size, bevel included (border-box). */
.runner {
  position: relative;
  overflow: hidden;
  background: #b4b4b4;
  border: 3px solid;
  border-color: var(--shadow) var(--hi) var(--hi) var(--shadow);
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.runner:focus-visible:not(.mouse) {
  outline: 2px dotted var(--navy);
  outline-offset: -2px;
}
/* rows fade in under the top edge */
.runner::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 22px;
  background: linear-gradient(#b4b4b4, transparent);
  z-index: 2;
  pointer-events: none;
}
/* the out-of-bounds strip, one row tall (--oob, set by endless.js), with
   the red line as its top edge. A row is judged once it's all the way in.
   It takes clicks and taps itself, so only the part of a tile above the
   line can be played. See-through, so the tiles still show as they sink. */
.runner::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--oob);
  box-sizing: border-box;
  border-top: 3px solid #ff0000;
  background: rgba(0, 0, 0, 0.65);
  z-index: 2;
}
.erow {
  position: absolute;
  left: 0;
  bottom: var(--oob);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  will-change: transform;
}
/* the row about to be judged */
.erow.near .c:not(.open):not(.flag) {
  background: #e0a8a8;
  animation: warn 0.5s ease-in-out infinite alternate;
}
@keyframes warn {
  to { background: #f07c7c; }
}
.erow.judged {
  opacity: 0.45;
}
/* the row that ended the run, lifted over the strip so the boom shows */
.erow.hot {
  z-index: 3;
}
.c.ok {
  background: #9fd49f;
  box-shadow: inset 1px 1px 0 var(--shadow);
}

