:root {
  --bg: #0f1b3d;
  --panel: #18284f;
  --cell: #f4f6ff;
  --ink: #0f1b3d;
  --head: #ffc83d;
  --mark: #e5384f;
  --bar: 52px;
  --gap: 10px;
  --n: 3;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: #fff; font-family: -apple-system, "SF Pro Rounded", system-ui, Arial, sans-serif; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); }

.bar { height: var(--bar); display: flex; align-items: center; gap: 12px; }
.bar h1 { margin: 0; font-size: 20px; letter-spacing: .04em; flex: 1; }
.bar button { font: inherit; font-size: 13px; color: #fff; background: var(--panel); border: 1px solid #ffffff33; border-radius: 8px; padding: 6px 10px; }

main { display: flex; flex-direction: column; gap: var(--gap); align-items: center; padding-bottom: 8px; }
/* cell side: fits all grids in the viewport height (6 rows each incl. header), capped by width */
.field {
  --cell-size: clamp(28px,
    min(calc((100dvh - var(--bar) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 14px - (var(--n) - 1) * var(--gap) - var(--n) * 40px) / (var(--n) * 6.2)),
        calc((100vw - 24px) / 5.4)),
    128px);
  display: flex; flex-direction: column; align-items: center; }
.field h2 { margin: 0 0 4px; font-size: calc(var(--cell-size) * .36); line-height: calc(var(--cell-size) * .5); letter-spacing: .08em; text-transform: uppercase; color: var(--head); }
.grid {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border-radius: 14px;
}
.h, .c { height: var(--cell-size); display: grid; place-items: center; border-radius: 10px; font-weight: 800; }
.h { height: calc(var(--cell-size) * .7); background: var(--head); color: var(--ink); font-size: calc(var(--cell-size) * .42); }
.c { background: var(--cell); color: var(--ink); font-size: calc(var(--cell-size) * .5); font-variant-numeric: tabular-nums; position: relative; cursor: pointer; border: 0; padding: 0; font-family: inherit; }
.c.free { background: #cfd6f2; font-size: calc(var(--cell-size) * .24); cursor: default; }
.c.marked::after {
  content: ""; position: absolute; inset: 9%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7a8c, var(--mark) 60%, #b01e33);
  opacity: .88; box-shadow: 0 2px 6px #0006;
}
.c.marked { color: #fff; }
.c.marked > span { position: relative; z-index: 1; text-shadow: 0 1px 2px #0008; }
.c:active:not(.free) { transform: scale(.94); }
.msg { text-align: center; opacity: .8; padding: 24px; }
#keepawake { position: fixed; width: 1px; height: 1px; opacity: .01; pointer-events: none; left: 0; bottom: 0; }
@media (min-height: 1100px) { :root { --gap: 16px; } }

.overlay { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 10; }
.overlay[hidden] { display: none; }
.dialog { background: var(--panel); border: 1px solid #ffffff33; border-radius: 16px; padding: 24px; width: min(420px, 88vw); text-align: center; box-shadow: 0 12px 40px #000a; }
.dialog p { margin: 0 0 20px; font-size: 20px; line-height: 1.4; }
.actions { display: flex; gap: 12px; }
.actions button { flex: 1; font: inherit; font-size: 18px; padding: 14px 10px; border-radius: 12px; border: 1px solid #ffffff33; background: var(--bg); color: #fff; }
.actions .primary { background: var(--mark); border-color: var(--mark); font-weight: 700; }
