/* Drift Recall: game window, board and tiles. Colours come from /assets/site.css. */

.desk {
  box-sizing: border-box;
  flex: none;
  min-height: calc(100vh - var(--hdr));
  padding-inline: 16px;
  padding-block: 16px;
  display: grid;
  place-items: center;
  background-image: radial-gradient(circle, var(--desk-dot) 1px, transparent 1.5px);
  background-size: 20px 20px;
}

@supports (height: 100dvh) {
  .desk { min-height: calc(100dvh - var(--hdr)); }
}

/* The game window */
.window {
  box-sizing: border-box;
  width: min(100%, 1100px, max(260px, calc((100vh - 214px - var(--hdr)) * 16 / 9)));
  display: flex;
  flex-direction: column;
  background: var(--win);
  border: 1.5px solid var(--win-line);
  border-radius: 14px;
  box-shadow: var(--win-shadow);
  overflow: hidden;
}
@supports (height: 100dvh) {
  .window { width: min(100%, 1100px, max(260px, calc((100dvh - 214px - var(--hdr)) * 16 / 9))); }
}
.window.is-opening { animation: win-in 0.22s ease-out; }
.window.is-closing { animation: win-out 0.16s ease-in forwards; pointer-events: none; }

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 7px 7px 14px;
  background: var(--bar);
  color: var(--bar-ink);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 7px); gap: 2px; }
.brand-mark i { width: 7px; height: 7px; border-radius: 2px; background: var(--tile); }
.brand-mark i:nth-child(2) { background: var(--ok); }
.brand h1 {
  margin: 0;
  font: 400 13px/1 "Bungee", "Arial Black", Impact, sans-serif;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bar-muted);
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bad); color: var(--on-state); }

/* Status strip: phase, timer, 1-8 progress */
.status {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
/* Wide enough for "MEMORIZE 3.0 s", so the strip wraps the same way in every phase */
.phase { display: flex; align-items: baseline; gap: 10px; min-width: 8.8em; }
.phase-label {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.phase-detail {
  font: 400 12px/1 "Martian Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pips { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.pip {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  font: 600 10px/1 "Martian Mono", ui-monospace, Menlo, monospace;
  color: var(--muted);
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.pip.is-next { border-color: var(--accent); color: var(--ink); }
.pip.is-found { border-color: var(--ok); background: var(--ok); color: var(--on-state); }
.pip.is-miss { border-color: var(--bad); background: var(--bad); color: var(--on-state); }
.timer { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; overflow: hidden; }
.timer-fill {
  height: 100%;
  background: var(--accent);
  transition: background-color 0.2s;
  transform: scaleX(0);
  transform-origin: left center;
}

.timer-fill.is-urgent { background: var(--bad); }
.phase-detail.is-urgent { color: var(--bad); font-weight: 600; }

/* The square field */
.board {
  position: relative;
  flex: none;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background-color: var(--field);
  background-image:
    linear-gradient(var(--field-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--field-line) 1px, transparent 1px);
  background-size: calc(var(--unit, 400px) / 8) calc(var(--unit, 400px) / 8);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: var(--tpx, 80px);
  aspect-ratio: 1 / 1;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: default;
  outline: none;
  will-change: transform;
}
.board.is-recall .tile:focus-visible .face { outline: 3px solid var(--focus-field); outline-offset: 3px; }
.face {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding-bottom: calc(var(--tpx, 80px) * 0.07);
  border-radius: 17%;
  background: var(--tile);
  color: var(--tile-ink);
  box-shadow:
    inset 0 calc(var(--tpx, 80px) * -0.07) 0 var(--tile-rim),
    0 calc(var(--tpx, 80px) * 0.09) calc(var(--tpx, 80px) * 0.2) var(--tile-shadow);
  font: 400 calc(var(--tpx, 80px) * 0.46)/1 "Bungee", "Arial Black", Impact, sans-serif;
  transition: background-color 0.16s ease, box-shadow 0.16s ease, transform 0.12s ease;
}
.num { display: block; }
.board.is-recall .tile { cursor: pointer; }
@media (hover: hover) {
  .board.is-recall .tile:not(.is-found):hover .face { transform: translateY(-2px); }
}
.board.is-recall .tile:not(.is-found):active .face { transform: translateY(1px) scale(0.97); }
.board.is-memorize .num { animation: num-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.face.pulse { animation: hide-pulse 0.3s ease; }

.tile.is-found .face {
  background: var(--ok);
  color: var(--on-state);
  box-shadow:
    inset 0 calc(var(--tpx, 80px) * -0.07) 0 var(--ok-rim),
    0 calc(var(--tpx, 80px) * 0.09) calc(var(--tpx, 80px) * 0.2) var(--tile-shadow);
}
.tile.is-wrong .face {
  background: var(--bad);
  color: var(--on-state);
  box-shadow:
    inset 0 calc(var(--tpx, 80px) * -0.07) 0 var(--bad-rim),
    0 calc(var(--tpx, 80px) * 0.09) calc(var(--tpx, 80px) * 0.2) var(--tile-shadow);
  animation: shake 0.38s ease;
}
/* Squares overlap now: keep unfound ones clickable above found ones,
   and the miss and the answer on top once the round ends */
.tile.is-found { z-index: 0; }
.tile.is-wrong { z-index: 2; }
.tile.is-target { z-index: 3; }
.tile.is-revealed .num { opacity: 0.72; }
.tile.is-target .face { outline: 3px solid var(--accent); outline-offset: 3px; }
.tile.is-target .num { opacity: 1; }

/* Start card */
.intro {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
}
.card {
  box-sizing: border-box;
  width: min(100%, 330px);
  max-height: 100%;
  overflow: auto;
  padding: 20px 22px 22px;
  border-radius: 12px;
  background: var(--win);
  color: var(--ink);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
}
.card h2 {
  margin: 0 0 12px;
  font: 400 19px/1.15 "Bungee", "Arial Black", Impact, sans-serif;
  text-wrap: balance;
}
.card ol {
  display: grid;
  gap: 6px;
  margin: 0 0 18px;
  padding-left: 1.25em;
  color: var(--muted);
}
.card li::marker { color: var(--ink); font-weight: 700; }

/* Footer: message, best score, end-of-round actions */
.footer {
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  min-height: 66px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.readout { display: grid; gap: 3px; flex: 1 1 220px; min-width: 0; }
.message { margin: 0; font-weight: 500; }
.best {
  font: 400 11px/1.3 "Martian Mono", ui-monospace, Menlo, monospace;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.actions { display: flex; gap: 8px; }
.btn {
  font: 600 14px/1 "Figtree", system-ui, sans-serif;
  padding: 11px 18px;
  border: 1.5px solid var(--btn);
  border-radius: 9px;
  background: var(--btn);
  color: var(--btn-ink);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--ink); }
.btn:focus-visible,
.icon-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

@keyframes num-in { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes hide-pulse { 0% { transform: scale(1); } 45% { transform: scale(0.9); } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6%); }
  40% { transform: translateX(5%); }
  60% { transform: translateX(-4%); }
  80% { transform: translateX(2%); }
}
@keyframes win-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes win-out { to { opacity: 0; transform: translateY(6px) scale(0.97); } }

@media (max-width: 420px) {
  .titlebar h1 { font-size: 12px; }
  .status, .footer { padding-inline: 12px; }
  .pip { width: 20px; height: 20px; }
  .card { padding: 16px; }
  .card h2 { font-size: 16px; }
  .card ol { gap: 4px; margin-bottom: 14px; font-size: 14px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
}

/* Short screens: the status strip wraps to two rows, so budget for it */
@media (max-height: 612px) {
  .window { width: min(100%, 1100px, max(260px, calc((100vh - 241px - var(--hdr)) * 16 / 9))); }
}
@supports (height: 100dvh) {
  @media (max-height: 612px) {
    .window { width: min(100%, 1100px, max(260px, calc((100dvh - 241px - var(--hdr)) * 16 / 9))); }
  }
}

/* Landscape phones: status and footer move beside the board */
@media (orientation: landscape) and (max-height: 540px) and (min-aspect-ratio: 8 / 5) {
  .desk { padding-block: 8px; }
  .window {
    width: min(100%, 1100px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 260px);
    grid-template-rows: auto auto 1fr;
  }
  .titlebar { grid-column: 1 / -1; }
  .board { grid-column: 1; grid-row: 2 / span 2; width: auto; height: calc(100vh - 65px - var(--hdr)); aspect-ratio: auto; }
  .status { grid-column: 2; grid-row: 2; border-left: 1px solid var(--line); }
  .footer { grid-column: 2; grid-row: 3; border-top: 0; border-left: 1px solid var(--line); align-content: end; }
  .card { padding: 14px; }
  .card h2 { font-size: 16px; }
  .card ol { gap: 4px; margin-bottom: 12px; font-size: 14px; }
}
@supports (height: 100dvh) {
  @media (orientation: landscape) and (max-height: 540px) and (min-aspect-ratio: 8 / 5) {
    .board { height: calc(100dvh - 65px - var(--hdr)); }
  }
}

/* Wide portrait screens: 4:3 keeps the arena landscape and still bigger than a square would be */
@media (min-width: 870px) and (orientation: portrait) {
  .board { aspect-ratio: 4 / 3; }
  .window { width: min(100%, 1100px, max(260px, calc((100vh - 214px - var(--hdr)) * 4 / 3))); }
}
@supports (height: 100dvh) {
  @media (min-width: 870px) and (orientation: portrait) {
    .window { width: min(100%, 1100px, max(260px, calc((100dvh - 214px - var(--hdr)) * 4 / 3))); }
  }
}

/* Portrait phones and tablets: any landscape shape would shrink the arena, so it stays square */
@media (max-width: 869px) and (orientation: portrait) {
  .board { aspect-ratio: 1 / 1; }
  .window { width: min(100%, max(260px, calc(100vh - 214px - var(--hdr)))); }
}
@media (max-width: 869px) and (orientation: portrait) and (max-height: 612px) {
  .window { width: min(100%, max(260px, calc(100vh - 241px - var(--hdr)))); }
}
@supports (height: 100dvh) {
  @media (max-width: 869px) and (orientation: portrait) {
    .window { width: min(100%, max(260px, calc(100dvh - 214px - var(--hdr)))); }
  }
  @media (max-width: 869px) and (orientation: portrait) and (max-height: 612px) {
    .window { width: min(100%, max(260px, calc(100dvh - 241px - var(--hdr)))); }
  }
}

/* Windows High Contrast: colors get replaced, so draw edges and states explicitly */
@media (forced-colors: active) {
  .face { border: 2px solid ButtonText; }
  .tile.is-found .face,
  .pip.is-found { background: Highlight; color: HighlightText; border-color: Highlight; }
  .tile.is-wrong .face { border: 4px dashed ButtonText; }
  .pip.is-miss { border-style: dashed; border-width: 3px; }
  .pip.is-next { border-width: 3px; }
}

/* Very small boards: keep the whole start card, Start included, inside the board */
@media (max-width: 720px), (max-height: 612px) {
  .intro { padding: 10px; }
  .card { padding: 14px 14px 16px; }
  .card h2 { margin-bottom: 8px; font-size: 15px; }
  .card ol { gap: 2px; margin-bottom: 12px; font-size: 13px; line-height: 1.35; }
  .card .btn { padding: 9px 16px; }
}

/* Very short boards (small phones held sideways): just the title and Start.
   The full rules are in "How to play" below the game. */
@media (max-height: 380px), (orientation: landscape) and (max-height: 480px) and (max-aspect-ratio: 8 / 5) {
  .card ol { display: none; }
  .card h2 { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .window.is-opening,
  .window.is-closing,
  .board.is-memorize .num,
  .face.pulse,
  .tile.is-wrong .face { animation: none; }
  .face, .pip, .btn { transition: none; }
}
