:root {
  /* One classic Minesweeper pixel. Cells are 16u; JS sets --cell to fit the viewport. */
  --cell: 32px;
  --u: calc(var(--cell) / 16);

  --win-face: #c0c0c0;
  --win-light: #ffffff;
  --win-shadow: #808080;

  --page-bg: #0b0c0e;
  --objective: #ffd21a;
  --comms-accent: #9fd8ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page-bg);
  color: #fff;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  gap: 20px;
}

/* Unless there's room beside the game, the comms flyout sits above it, so leave it room. */
@media (max-width: 1080px) {
  .hud-screen .stage { padding-top: max(170px, calc(env(safe-area-inset-top) + 158px)); }
}

/* ---------- Classic window chrome ---------- */

.game {
  background: var(--win-face);
  border: calc(var(--u) * 3) solid;
  border-color: var(--win-light) var(--win-shadow) var(--win-shadow) var(--win-light);
  padding: calc(var(--u) * 6);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--u) * 37);
  padding: 0 calc(var(--u) * 5);
  border: calc(var(--u) * 2) solid;
  border-color: var(--win-shadow) var(--win-light) var(--win-light) var(--win-shadow);
  margin-bottom: calc(var(--u) * 6);
}

.lcd {
  display: flex;
  background: #000;
  border: var(--u) solid;
  border-color: var(--win-shadow) var(--win-light) var(--win-light) var(--win-shadow);
}

.lcd svg {
  display: block;
  width: calc(var(--u) * 13);
  height: calc(var(--u) * 23);
}

.lcd .on { fill: #ff0000; }
.lcd .off { fill: #2a0000; }

.face {
  appearance: none;
  -webkit-appearance: none;
  width: calc(var(--u) * 26);
  height: calc(var(--u) * 26);
  padding: 0;
  margin: 0;
  background: var(--win-face);
  border: calc(var(--u) * 3) solid;
  border-color: var(--win-light) var(--win-shadow) var(--win-shadow) var(--win-light);
  outline: var(--u) solid var(--win-shadow);
  outline-offset: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.face:active {
  border-width: var(--u);
  border-color: var(--win-shadow);
  padding: calc(var(--u) * 2) 0 0 calc(var(--u) * 2);
}

.face svg {
  width: calc(var(--u) * 17);
  height: calc(var(--u) * 17);
  display: block;
}

/* Face states: data-face = smile | o | win; .talking opens the mouth. */
.face .eyes-o,
.face .shades,
.face .mouth-talk,
.face .mouth-o { display: none; }

.face[data-face="o"] .eyes { display: none; }
.face[data-face="o"] .eyes-o { display: inline; }
.face[data-face="o"] .mouth-smile { display: none; }
.face[data-face="o"] .mouth-o { display: inline; }

.face[data-face="win"] .eyes { display: none; }
.face[data-face="win"] .shades { display: inline; }

.face.talking:not([data-face="o"]) .mouth-smile { display: none; }
.face.talking:not([data-face="o"]) .mouth-talk { display: inline; }

/* ---------- Board ---------- */

.board-wrap {
  border: calc(var(--u) * 3) solid;
  border-color: var(--win-shadow) var(--win-light) var(--win-light) var(--win-shadow);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols, 9), var(--cell));
  grid-auto-rows: var(--cell);
  touch-action: none;
  cursor: default;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  background: var(--win-face);
  border: calc(var(--u) * 2) solid;
  border-color: var(--win-light) var(--win-shadow) var(--win-shadow) var(--win-light);
}

.cell svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.cell.open,
.cell.pressed {
  border-width: var(--u) 0 0 var(--u);
  border-color: #7b7b7b;
}

/* In open cells the SVG is drawn in the same 16u frame as closed cells. */
.cell.open svg,
.cell.pressed svg {
  inset: calc(var(--u) * -1) 0 0 calc(var(--u) * -1);
  width: var(--cell);
  height: var(--cell);
}

.cell:not(.open):not(.pressed) svg {
  inset: calc(var(--u) * -2);
  width: var(--cell);
  height: var(--cell);
}

.cell.hit { background: #ff0000; }

/* ---------- Objective marker ---------- */

.objective {
  position: absolute;
  left: calc(var(--c) * var(--cell));
  top: calc(var(--r) * var(--cell));
  width: var(--cell);
  height: var(--cell);
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.objective::before {
  content: "";
  position: absolute;
  inset: 0;
  /* A dark pool under the waypoint so it reads against the light cells. */
  background: radial-gradient(circle closest-side, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.2) 70%, rgba(0, 0, 0, 0));
  box-shadow: inset 0 0 0 calc(var(--u) * 1) rgba(255, 210, 26, 0.95),
              inset 0 0 calc(var(--u) * 5) rgba(255, 190, 0, 0.6);
  animation: objective-cell 1.4s ease-in-out infinite;
}

.objective .wp,
.objective .ring {
  grid-area: 1 / 1;
  width: 44%;
  height: 44%;
  transform: rotate(45deg);
}

.objective .wp {
  background: rgba(255, 210, 26, 0.85);
  border: calc(var(--u) * 1.5) solid var(--objective);
  /* Dark outline and shadow first, then the yellow glow. */
  box-shadow: 0 0 0 calc(var(--u) * 0.75) rgba(0, 0, 0, 0.8),
              0 0 calc(var(--u) * 3) rgba(255, 200, 0, 0.9),
              0 0 calc(var(--u) * 5) calc(var(--u) * 1) rgba(0, 0, 0, 0.45);
  animation: objective-pulse 1.4s ease-in-out infinite;
}

.objective .ring {
  border: calc(var(--u) * 1) solid var(--objective);
  box-shadow: 0 0 0 calc(var(--u) * 0.5) rgba(0, 0, 0, 0.5);
  opacity: 0;
  animation: objective-ring 1.4s ease-out infinite;
}

.objective.in { animation: objective-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.15) both; }
.objective.out { animation: objective-out 0.2s ease-in both; }

@keyframes objective-in {
  from { transform: scale(1.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes objective-out {
  to { transform: scale(0.6); opacity: 0; }
}

@keyframes objective-pulse {
  0%, 100% { transform: rotate(45deg) scale(1); }
  50% { transform: rotate(45deg) scale(1.12); }
}

@keyframes objective-ring {
  0% { transform: rotate(45deg) scale(1); opacity: 0.9; }
  100% { transform: rotate(45deg) scale(2.1); opacity: 0; }
}

@keyframes objective-cell {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ---------- Subtitles ---------- */

.subtitle {
  width: min(560px, 100%);
  font-family: "Oswald", "Arial Narrow", sans-serif;
  min-height: 3.2em;
  text-align: center;
  font-size: clamp(17px, 4.6vw, 22px);
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
  text-shadow:
    -2px -2px 0 #000, 0 -2px 0 #000, 2px -2px 0 #000,
    -2px 0 0 #000, 2px 0 0 #000,
    -2px 2px 0 #000, 0 2px 0 #000, 2px 2px 0 #000,
    0 0 6px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.subtitle.show { opacity: 1; }

/* ---------- NPC comms flyout ---------- */

.comms {
  position: fixed;
  font-family: "Oswald", "Arial Narrow", sans-serif;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: min(300px, calc(100vw - 24px));
  padding: 12px 14px 14px;
  background: linear-gradient(90deg, rgba(10, 16, 22, 0.9), rgba(10, 16, 22, 0.78));
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transform: translateX(calc(100% + 32px));
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.35s ease;
  pointer-events: none;
  z-index: 10;
}

.comms.show {
  transform: translateX(0);
  opacity: 1;
}

.comms-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--comms-accent);
}

.comms-wave {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 8px;
}

/* ---------- Recovery vignette ---------- */

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(160, 0, 0, 0) 45%, rgba(170, 0, 0, 0.55) 75%, rgba(200, 0, 0, 0.9) 100%);
  box-shadow: inset 0 0 12vmin 2vmin rgba(200, 0, 0, 0.85);
}

/* ---------- HUD contained in the game window (default layout) ---------- */

.hud-board .game-frame { position: relative; }

.hud-board .game,
.hud-board .board-wrap {
  position: relative;
  overflow: hidden;
}

.hud-board .vignette {
  position: absolute;
  z-index: 3;
  background: radial-gradient(ellipse at center, rgba(160, 0, 0, 0) 55%, rgba(170, 0, 0, 0.4) 85%, rgba(200, 0, 0, 0.8) 100%);
  box-shadow: inset 0 0 calc(var(--u) * 16) calc(var(--u) * 2) rgba(200, 0, 0, 0.85);
}

.hud-board .subtitle {
  /* Spans the whole game window; the padding keeps the text where it was,
     just above the bottom of the board (frame 3 + padding 6 + board edge 3
     + 6, and 12 + 2 at the sides). */
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 calc(var(--u) * 14) calc(var(--u) * 18);
  width: auto;
  min-height: 0;
  z-index: 6;
  pointer-events: none;
  font-size: calc(var(--u) * 10);
  text-shadow:
    -1.5px -1.5px 0 #000, 0 -1.5px 0 #000, 1.5px -1.5px 0 #000,
    -1.5px 0 0 #000, 1.5px 0 0 #000,
    -1.5px 1.5px 0 #000, 0 1.5px 0 #000, 1.5px 1.5px 0 #000,
    0 0 4px rgba(0, 0, 0, 0.8);
}

/* Dark gradient behind the subtitle: the full width of the game window,
   border included, rising from its bottom edge and fading out above the text. */
.hud-board .subtitle::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: calc(var(--u) * -12);
  z-index: -1;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.55) 45%, rgba(0, 0, 0, 0) 100%);
}

.hud-board .comms {
  position: absolute;
  /* Covers the header's right side (the timer) without reaching the smiley. */
  top: calc(var(--u) * 6);
  right: calc(var(--u) * 6);
  width: calc(var(--u) * 60);
  height: calc(var(--u) * 37);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 calc(var(--u) * 5);
  box-shadow: 0 calc(var(--u) * 2) calc(var(--u) * 8) rgba(0, 0, 0, 0.5);
  transform: translateX(calc(100% + var(--u) * 8));
  z-index: 5;
}

.hud-board .comms.show { transform: translateX(0); }

.hud-board .comms-name { font-size: calc(var(--u) * 5.5); }

.hud-board .comms-wave {
  height: calc(var(--u) * 14);
  margin-top: calc(var(--u) * 3);
}

/* ---------- Ending ---------- */

/* Holds the comms flyout in place over where the game window was, so the
   window can drift away under it. Clips like the window did. */
.comms-dock {
  position: fixed;
  overflow: hidden;
  pointer-events: none;
  z-index: 10;
}

.comms-dock[hidden] { display: none; }

/* Black screen the credits scroll up over. */
.credits {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: #000;
  overflow: hidden;
  opacity: 0;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

.credits[hidden] { display: none; }

.credits-roll {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: 0 16px;
  color: #ece9e2;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-transform: uppercase;
  will-change: transform;
}

.credits-heading {
  margin: 72px 0 22px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: #8f8b84;
}

/* Role on the left of the centre line, names on the right. */
.credits-entry {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 28px;
  margin: 0 auto 14px;
  max-width: 760px;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0.08em;
}

.credits-role {
  text-align: right;
  color: #8f8b84;
}

.credits-names { text-align: left; }

/* The opening credit gets a card of its own. */
.credits-feature {
  display: block;
  margin: 0 auto 160px;
  text-align: center;
}

.credits-feature .credits-role {
  text-align: center;
  font-size: 13px;
  letter-spacing: 0.32em;
  margin-bottom: 10px;
}

.credits-feature .credits-names {
  text-align: center;
  font-size: 30px;
  font-weight: 300;
  letter-spacing: 0.18em;
}

@media (max-width: 520px) {
  .credits-entry {
    column-gap: 16px;
    font-size: 12px;
    letter-spacing: 0.06em;
  }
  .credits-feature .credits-names { font-size: 24px; }
}

/* ---------- Wake-up intro ---------- */

/* Eyelids: black with an elliptical opening, drawn by js/wakeUp.js. */
.eyes {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: #000;
  pointer-events: none;
}

.eyes[hidden] { display: none; }

/* Title over the wake-up. Letters start a little apart and drift further
   (js/title.js moves each one). */
.title {
  position: fixed;
  inset: 0;
  z-index: 36;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}

.title[hidden] { display: none; }

.title-word {
  display: flex;
  font-family: "Archivo Black", "Arial Black", sans-serif;
  font-size: min(8.2vw, 105px);  /* fully spread, at most ~88% of the width */
  line-height: 1;
  color: #ece9e2;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.title-word span {
  display: inline-block;
  margin: 0 0.05em;
  will-change: transform;
}

/* The game can't be touched until the intro hands over control. */
.stage.waking { pointer-events: none; }

/* ---------- Logo sequence ---------- */

.logo-sequence {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #000;
  opacity: 0;
  cursor: default;
}

.logo-sequence[hidden] { display: none; }

/* Logos are flattened to an off-white silhouette, whatever their colors. */
.logo-sequence .logo {
  width: auto;
  height: auto;
  max-width: calc(min(62vw, 440px) * var(--size, 1));
  max-height: calc(min(26vh, 200px) * var(--size, 1));
  filter: brightness(0) invert(1) sepia(0.12);
  opacity: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.logo-sequence .logo.shaded {
  filter: grayscale(1) invert(1) brightness(1.35) contrast(1.2) sepia(0.12);
}

/* ---------- Start screen: Win95 desktop ---------- */

.desktop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: #008080;
  cursor: default;
}

.desktop[hidden] { display: none; }

.shortcut {
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  outline: none;
  cursor: default;
  touch-action: manipulation;
}

/* "A game by Mike Lacher", in the desktop's pixel lettering. */
.desktop-credit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

/* Dimmed to stay subtle; only the name brightens on hover. */
.desktop-credit canvas {
  display: block;
  opacity: 0.7;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.desktop-credit a { cursor: pointer; outline: none; }
.desktop-credit a:hover canvas,
.desktop-credit a:focus-visible canvas { opacity: 1; }

.shortcut canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
