:root {
  --table-edge: #123b4b;
  --table-light: #1c5363;
  --surface: #18364c;
  --line: #638eab;
}
/* The board takes the room the screen has. Small boards keep comfortable tiles; large boards are
   held to the height left under the header, so the whole field stays in view on a desktop. */
.table {
  --cols: 9;
  --rows: 9;
  --table-width: min(calc(var(--cols) * 3.4rem + 1.5rem), calc((100dvh - 11.5rem) * var(--cols) / var(--rows) + 1.5rem));
}
.table[data-mode="easy"] { --table-width: 31.5rem; }
.table[data-mode="medium"] { --table-width: 36rem; }
.table[data-mode="hard"] { --table-width: 40rem; }
main:has(.table:is([data-mode="expert"], [data-mode="vast"], [data-mode="colossal"])) { padding-top: .75rem; }
#board {
  display: grid;
  gap: 2px;
  padding: clamp(.25rem, 1vw, .65rem);
  background: #0b2334;
  overflow-x: auto;
}
.survey-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; min-width: calc(var(--cols) * 1.25rem); }
.survey-row > div { container-type: inline-size; }
.table:is([data-mode="vast"], [data-mode="colossal"]) :is(#board, .survey-row) { gap: 1px; }
.tile {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border: 1px solid rgb(152 201 223 / .13);
  border-radius: .2rem;
  background: #142e42;
  font-size: clamp(.6rem, 62cqi, 1.1rem);
  font-weight: 800;
  line-height: 1;
}
.tile:is([data-tile="covered"], [data-tile="flag"]) {
  border-color: #5983a0;
  background: linear-gradient(140deg, #32566f, #27485f);
  box-shadow: inset 0 1px rgb(222 245 255 / .12);
}
.tile:is([data-tile="flag"], [data-tile="wrong-flag"]) { color: var(--accent); }
.tile[data-tile="mine"] { color: #ffd7e4; background: #462e4d; }
.tile[data-tile="hit"] { color: #fff; background: #a53451; }
.tile[data-tile="1"] { color: #9cd5ff; }
.tile[data-tile="2"] { color: #8df0bd; }
.tile[data-tile="3"] { color: #ffbda7; }
.tile[data-tile="4"] { color: #d5c0ff; }
.tile[data-tile="5"] { color: #ff9aba; }
.tile[data-tile="6"] { color: #83e9ec; }
.tile[data-tile="7"] { color: #f2f5ff; }
.tile[data-tile="8"] { color: #f7da95; }
.tile:not([aria-disabled="true"]):is([data-tile="covered"], [data-tile="flag"], [data-chord="true"]):hover { filter: brightness(1.24); }
.tile[aria-disabled="true"], .tile[data-tile="0"] { cursor: default; }
.tile:focus-visible { outline-offset: -2px; }
#flag-mode[aria-pressed="true"] { color: #1b233b; background: var(--accent); border-color: var(--accent); }
.marking .tile:is([data-tile="covered"], [data-tile="flag"]):hover { border-color: var(--accent); }

/* End of a survey. --d is each tile's distance from the board's middle (won) or from the triggered
   mine (lost); --reveal is when the result card appears; --chain is how long the mines take to go
   off. Every animation ends on the tile's resting style, so a finished board loaded later looks the
   same, just without the motion. */
.board-frame { position: relative; }
#burst { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
#doom {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  background: radial-gradient(ellipse at 50% 45%, transparent 30%, rgb(60 0 12 / .55) 75%, rgb(18 0 4 / .85));
  transition: opacity 1.6s ease;
}
#doom.shown { opacity: 1; }

.ending {
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  z-index: 15;
  display: grid;
  justify-items: center;
  gap: .45rem;
  width: min(calc(100% - 1.5rem), 25rem);
  padding: clamp(1rem, 4vw, 1.6rem) clamp(1rem, 4vw, 1.75rem);
  border-radius: .9rem;
  text-align: center;
}
.ending h2 { font-size: clamp(1.5rem, 6vw, 2.2rem); line-height: 1.05; }
.ending p:not(.ending-badge) { color: var(--muted); font-size: .95rem; font-weight: 600; }
.ending-badge { font-size: clamp(2.2rem, 9vw, 3.2rem); line-height: 1; }
.ending-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem; margin-top: .55rem; }
#again { color: #1b233b; background: var(--accent); border-color: var(--accent); }

/* Won: a gold wave rolls out from the middle, every mine is shown found, the card pops in. */
.table[data-status="won"] .board {
  border-color: rgb(243 197 101 / .7);
  box-shadow: 0 0 0 2px rgb(243 197 101 / .25), 0 0 48px rgb(243 197 101 / .32), 0 16px 46px rgb(3 7 23 / .36);
}
.table[data-status="won"] .tile[data-tile="flag"] {
  color: #b9ffd9;
  border-color: #4fbf8b;
  background: linear-gradient(140deg, #2b7a5c, #1e5a45);
  text-shadow: 0 0 10px rgb(141 240 189 / .8);
}
.table[data-status="won"] .ending {
  border: 2px solid var(--accent);
  background: radial-gradient(ellipse at 50% 0, rgb(243 197 101 / .28), transparent 70%), rgb(16 26 56 / .94);
  box-shadow: 0 0 0 6px rgb(243 197 101 / .14), 0 0 60px rgb(243 197 101 / .45), 0 20px 50px rgb(0 0 0 / .5);
}
.table[data-status="won"] .ending h2 { color: var(--accent); text-shadow: 0 0 22px rgb(243 197 101 / .6); }
.table[data-status="won"] .ending-badge { color: var(--accent); text-shadow: 0 0 24px rgb(243 197 101 / .9); }
.table[data-fresh="won"] .tile { animation: cleared 650ms ease calc(var(--d, 0) * 55ms) both; }
.table[data-fresh="won"] .ending { animation: pop-in 520ms cubic-bezier(.2, 1.6, .45, 1) var(--reveal) both; }
.table[data-fresh="won"] .ending-badge { animation: spin-in 900ms ease-out calc(var(--reveal) + 120ms) both; }
@keyframes cleared {
  45% { background: #f3c565; color: #1b233b; border-color: #fff3c9; transform: scale(1.12); box-shadow: 0 0 14px rgb(243 197 101 / .9); }
}
@keyframes pop-in { from { opacity: 0; transform: scale(.4); } }
@keyframes spin-in { from { transform: rotate(-200deg) scale(.2); opacity: 0; } }

/* Lost: the board jolts, the mines go off one after another from the one that was triggered, the
   field goes dark and scorched, and a red card rises out of the smoke. */
.table[data-status="lost"] .board {
  border-color: #7a1730;
  box-shadow: 0 0 0 2px rgb(165 52 81 / .45), 0 0 70px rgb(180 20 45 / .5), 0 16px 46px rgb(0 0 0 / .6);
}
.table[data-status="lost"] .tile:not([data-tile="mine"], [data-tile="hit"], [data-tile="wrong-flag"]) {
  filter: grayscale(.75) brightness(.48) sepia(.35);
}
.table[data-fresh="lost"] .tile { transition: filter 1.4s ease calc(var(--chain, 0ms) + 200ms); }
.table[data-status="lost"] .tile[data-tile="mine"] {
  color: #ffcf8a;
  border-color: #8a2a2a;
  background: radial-gradient(circle, #6e1a1f, #2a0c11 80%);
  text-shadow: 0 0 8px #ff6a3d;
}
.table[data-status="lost"] .tile[data-tile="hit"] {
  position: relative;
  z-index: 1;
  color: #fff7e0;
  border-color: #ffb35c;
  background: radial-gradient(circle, #ffef9a, #ff5a3c 35%, #a5142d 75%);
  box-shadow: 0 0 22px 6px rgb(255 90 60 / .7);
  text-shadow: 0 0 6px #fff;
}
.table[data-status="lost"] .tile[data-tile="wrong-flag"] { color: #ff6b6b; background: #2a1418; text-decoration: line-through; }
.table[data-status="lost"] .ending {
  border: 2px solid #a5142d;
  background: radial-gradient(ellipse at 50% 120%, rgb(165 20 45 / .45), transparent 70%), rgb(14 6 10 / .95);
  box-shadow: 0 0 0 6px rgb(120 10 30 / .25), 0 0 80px rgb(165 20 45 / .55), 0 20px 50px rgb(0 0 0 / .7);
}
.table[data-status="lost"] .ending h2 { color: #ff6b6b; letter-spacing: .02em; text-shadow: 0 0 18px rgb(255 40 60 / .7), 0 2px 0 #3b0710; }
.table[data-status="lost"] .ending-badge { color: #ff8a3d; text-shadow: 0 0 26px #ff3b2f; }
.table[data-fresh="lost"] .board { animation: jolt 620ms cubic-bezier(.36, .07, .19, .97) both; }
.table[data-fresh="lost"] .tile[data-tile="hit"] { animation: blast 900ms ease-out both; }
.table[data-fresh="lost"] .tile[data-tile="mine"] { animation: detonate 520ms ease-out calc(var(--d, 0) * 75ms) both; }
.table[data-fresh="lost"] .ending { animation: rise 1100ms ease-out var(--reveal) both; }
.table[data-fresh="lost"] .ending-badge { animation: smoulder 2.4s ease-in-out calc(var(--reveal) + 400ms) 3; }
@keyframes jolt {
  10%, 90% { transform: translate(-2px, 1px); }
  20%, 80% { transform: translate(4px, -3px) rotate(.4deg); }
  30%, 50%, 70% { transform: translate(-7px, 4px) rotate(-.6deg); }
  40%, 60% { transform: translate(7px, -2px) rotate(.5deg); }
}
@keyframes blast {
  0% { transform: scale(1); background: #fff; box-shadow: 0 0 0 0 #fff; }
  20% { transform: scale(1.9); background: #fff3c0; box-shadow: 0 0 60px 30px rgb(255 120 60 / .9); }
}
@keyframes detonate {
  0% { color: transparent; background: linear-gradient(140deg, #32566f, #27485f); border-color: #5983a0; text-shadow: none; }
  35% { transform: scale(1.45); color: #fff; background: #ffb35c; box-shadow: 0 0 26px 8px rgb(255 90 60 / .85); }
}
@keyframes rise { from { opacity: 0; transform: translateY(1.5rem) scale(.96); filter: blur(8px); } }
@keyframes smoulder { 50% { text-shadow: 0 0 40px #ff3b2f, 0 0 12px #ffbd59; } }

@media (prefers-reduced-motion: reduce) {
  .table[data-fresh] .board, .table[data-fresh] .tile, .table[data-fresh] .ending, .table[data-fresh] .ending-badge { animation: none; }
  .table[data-fresh="lost"] .tile { transition: none; }
  #doom { transition: none; }
}

#ending-extra:empty { display: none; }
#ending-extra { color: var(--ink); font-weight: 700; }
#ending-extra[data-best="true"] { color: #8df0bd; text-shadow: 0 0 14px rgb(141 240 189 / .55); }
#clock { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
#clock:empty { display: none; }

/* Records */
#records { width: min(40rem, calc(100% - 1rem)); max-height: calc(100dvh - 2rem); overflow-y: auto; }
#records h3 { margin: 1.1rem 0 .45rem; font: 700 1rem/1.2 var(--heading); }
#records section { margin-top: .25rem; }
.tabs { display: flex; gap: .35rem; margin-top: 1rem; border-bottom: 1px solid rgb(211 219 255 / .2); }
.tabs [role="tab"] { border-width: 0 0 3px; border-radius: .4rem .4rem 0 0; border-color: transparent; background: transparent; }
.tabs [role="tab"][aria-selected="true"] { border-color: var(--accent); color: var(--accent); background: rgb(243 197 101 / .08); }
.records-empty { color: var(--muted); }
.records-scroll { overflow-x: auto; }
#records table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
#records :is(th, td) { padding: .35rem .5rem; text-align: right; border-bottom: 1px solid rgb(211 219 255 / .12); }
#records :is(thead th, tbody th) { text-align: left; }
#records thead th { color: var(--muted); font-weight: 600; }
#records thead th:not(:first-child) { text-align: right; }
.recent, .ranking { margin: 0; padding: 0; list-style: none; display: grid; gap: .3rem; font-size: .9rem; }
.recent li {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr) auto;
  gap: .1rem .6rem;
  align-items: baseline;
  padding: .4rem .6rem;
  border-radius: .4rem;
  background: rgb(255 255 255 / .04);
  border-left: 3px solid #a53451;
}
.recent li[data-won="true"] { border-left-color: #4fbf8b; }
.recent .outcome { font-weight: 800; color: #ff8a9b; }
.recent li[data-won="true"] .outcome { color: #8df0bd; }
.recent .detail { grid-column: 2; color: var(--muted); font-variant-numeric: tabular-nums; }
.recent time { grid-row: 1 / span 2; grid-column: 3; color: var(--muted); font-size: .82rem; align-self: center; }
.board-pick { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin-top: 1rem; }
.board-pick h3 { margin: 0 !important; }
.ranking li {
  display: grid;
  grid-template-columns: 1.8rem minmax(0, 1fr) auto;
  gap: .6rem;
  align-items: center;
  padding: .4rem .6rem;
  border-radius: .4rem;
  background: rgb(255 255 255 / .04);
}
.ranking li:first-child .rank { color: var(--accent); }
.ranking li[data-you="true"] { outline: 1px solid var(--accent); background: rgb(243 197 101 / .1); }
.ranking .rank { font-weight: 800; text-align: center; color: var(--muted); }
.ranking .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ranking .score { font-variant-numeric: tabular-nums; color: var(--muted); }
#name-note { font-size: .85rem; }
