:root {
  color-scheme: light;
  --page: #008080;
  --shell: #c0c0c0;
  --panel: #c0c0c0;
  --panel-raised: #d4d0c8;
  --panel-soft: #e8e8e8;
  --line: #808080;
  --line-soft: #a0a0a0;
  --text: #000000;
  --muted: #3e3e3e;
  --quiet: #606060;
  --safe: #008000;
  --safe-deep: #006000;
  --signal: #000080;
  --signal-deep: #000050;
  --danger: #c00000;
  --focus: #000000;
  --cell-size: 44px;
  --cell-gap: 0px;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: #008080;
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  transform: translateY(-160%);
  border: 2px solid var(--focus);
  background: var(--page);
  color: var(--text);
  font-weight: 750;
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 2px dotted #000000;
  outline-offset: 3px;
}

.site-header {
  width: min(1320px, calc(100% - 24px));
  min-height: 38px;
  margin: 14px auto 0;
  padding: 4px 5px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 6px;
  border: 2px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  border-bottom: 0;
  background: #000080;
  color: #ffffff;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, .35);
}

.brand-home,
.icon-button {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  color: #000000;
  text-decoration: none;
  cursor: pointer;
}

.brand-home:hover,
.icon-button:hover {
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #d4d0c8;
}

.brand-home:active,
.icon-button:active {
  padding: 2px 0 0 2px;
  border-color: #404040 #ffffff #ffffff #404040;
}

.brand-mark {
  width: 18px;
  height: 18px;
  position: relative;
  border: 2px solid #000080;
  border-radius: 50%;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: #000080;
}

.brand-mark::before {
  width: 2px;
  height: 22px;
  top: -4px;
  left: 6px;
}

.brand-mark::after {
  width: 22px;
  height: 2px;
  top: 6px;
  left: -4px;
}

.title-lockup {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.eyebrow,
.section-kicker,
.readout-label,
.phase-label,
.version-stamp,
.field-legend {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.eyebrow {
  display: none;
}

h1 {
  margin: 0;
  flex: 0 0 auto;
  color: #ffffff;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
}

.game-deck {
  margin: 0;
  overflow: hidden;
  color: #e6e6e6;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-shell {
  width: min(1320px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 310px);
  align-items: start;
  gap: 10px;
  border: 2px solid;
  border-top: 0;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, .35);
}

.play-station {
  min-width: 0;
  border: 3px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  box-shadow: none;
}

.instrument-bar {
  min-height: 88px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  border-bottom: 2px solid #808080;
  background: #c0c0c0;
}

.readout {
  min-width: 0;
  margin: 8px;
  padding: 5px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 3px solid;
  border-color: #404040 #ffffff #ffffff #404040;
  background: #101010;
  text-align: center;
}

.readout-label {
  color: #c0c0c0;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", sans-serif;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: none;
}

.readout-value {
  margin-top: 0;
  color: #ff2a22;
  font-family: "Cascadia Mono", "Courier New", monospace;
  font-size: clamp(34px, 5vw, 46px);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: .08em;
  line-height: .98;
  text-shadow: 2px 0 #660000;
}

.face-btn {
  width: 76px;
  min-height: 68px;
  position: relative;
  display: grid;
  place-items: center;
  align-self: center;
  border: 3px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  cursor: pointer;
}

.face-btn:hover {
  background: #d4d0c8;
}

.face-btn:active {
  border-color: #404040 #ffffff #ffffff #404040;
}

.face-glyph {
  font-size: 34px;
  line-height: 1;
  filter: grayscale(.1);
}

.restart-caption {
  position: absolute;
  bottom: 4px;
  color: #202020;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", sans-serif;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mission-line {
  min-height: 58px;
  margin: 8px 8px 0;
  padding: 10px clamp(12px, 2vw, 22px);
  display: grid;
  grid-template-columns: minmax(135px, auto) 1fr auto;
  align-items: center;
  gap: 14px;
  border: 2px solid;
  border-color: #808080 #ffffff #ffffff #808080;
  background: #d4d0c8;
}

.phase {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.phase-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 0;
  background: #808080;
  box-shadow: inset 1px 1px #404040, inset -1px -1px #ffffff;
}

.phase-dot.is-active {
  background: #0000aa;
  box-shadow: inset 1px 1px #000050, inset -1px -1px #7070ff;
}

.phase-dot.is-won {
  background: #008000;
  box-shadow: inset 1px 1px #004000, inset -1px -1px #70c070;
}

.phase-dot.is-lost {
  background: #d00000;
  box-shadow: inset 1px 1px #600000, inset -1px -1px #ff7070;
}

.phase-copy {
  min-width: 0;
}

.phase-label {
  display: block;
  color: #404040;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", sans-serif;
  font-size: 9px;
  letter-spacing: 0;
  text-transform: none;
}

.phase-value {
  display: block;
  overflow: hidden;
  color: #000000;
  font-size: 13px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clearance-track {
  height: 12px;
  overflow: hidden;
  border: 2px solid;
  border-color: #808080 #ffffff #ffffff #808080;
  background: #ffffff;
}

.clearance-bar {
  width: 0;
  height: 100%;
  background: #000080;
  transition: width 180ms ease-out;
}

.clearance-value {
  min-width: 42px;
  color: #000080;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.board-frame {
  position: relative;
  overflow: hidden;
  background: #c0c0c0;
}

.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.board-frame::before {
  inset: 0;
  border: 10px solid #c0c0c0;
}

.board-frame::after {
  inset: 10px;
  border: 3px solid;
  border-color: #404040 #ffffff #ffffff #404040;
}

.board-scroller {
  width: 100%;
  min-height: 410px;
  max-height: min(68vh, 720px);
  padding: clamp(24px, 4vw, 48px);
  overflow: auto;
  overscroll-behavior: contain;
  background: #c0c0c0;
  scrollbar-color: #808080 #c0c0c0;
  scrollbar-width: thin;
  touch-action: pan-x pan-y;
}

.board-scroller::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.board-scroller::-webkit-scrollbar-track {
  background: #c0c0c0;
}

.board-scroller::-webkit-scrollbar-thumb {
  border: 2px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
}

.board {
  width: max-content;
  margin: auto;
  display: grid;
  gap: var(--cell-gap);
  padding: 3px;
  border: 4px solid;
  border-color: #404040 #ffffff #ffffff #404040;
  background: #808080;
  box-shadow: none;
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  color: #000000;
  font-family: "Cascadia Mono", "Courier New", monospace;
  font-size: calc(var(--cell-size) * .48);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: none;
}

.cell:hover {
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #d4d0c8;
}

.cell:active {
  border-color: #404040 #ffffff #ffffff #404040;
  transform: none;
}

.cell.revealed {
  border: 1px solid #808080;
  background: #c0c0c0;
  cursor: default;
  transform: none;
}

.cell.revealed.just-revealed {
  animation: safe-open 180ms ease-out both;
  animation-delay: var(--reveal-delay, 0ms);
}

.cell.revealed.is-empty::after {
  content: "";
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: transparent;
}

.cell.flagged {
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  color: #d00000;
}

.cell.flagged::before {
  content: "";
  width: 35%;
  height: 48%;
  position: absolute;
  top: 20%;
  left: 30%;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.cell.flagged::after {
  content: "";
  width: 42%;
  height: 28%;
  position: absolute;
  top: 18%;
  left: 34%;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.cell.mine {
  border-color: #800000;
  background: #ff3b30;
  color: #000000;
  animation: mine-hit 220ms ease-out;
}

.cell.wrong-flag {
  border-color: var(--danger);
  background: #ffb0b0;
}

.cell[data-num="1"] { color: #0000ff; }
.cell[data-num="2"] { color: #008000; }
.cell[data-num="3"] { color: #ff0000; }
.cell[data-num="4"] { color: #000080; }
.cell[data-num="5"] { color: #800000; }
.cell[data-num="6"] { color: #008080; }
.cell[data-num="7"] { color: #000000; }
.cell[data-num="8"] { color: #606060; }

.mine-face {
  width: 82%;
  height: 82%;
  object-fit: cover;
  border: 2px solid var(--danger);
  border-radius: 50%;
}

.sweep-line {
  z-index: 3;
  width: 2px;
  height: calc(100% - 28px);
  position: absolute;
  top: 14px;
  left: 14px;
  opacity: 0;
  pointer-events: none;
  background: var(--safe);
  box-shadow: 0 0 18px rgba(167, 216, 138, .56);
  display: none;
}

.board-frame.is-running .sweep-line {
  opacity: .28;
  animation: field-sweep 4.8s linear infinite;
}

.board-hint {
  margin: 0 8px 8px;
  padding: 9px 14px;
  border: 2px solid;
  border-color: #808080 #ffffff #ffffff #808080;
  background: #d4d0c8;
  color: #202020;
  font-size: 11px;
  text-align: center;
}

.control-panel {
  min-width: 0;
  border: 3px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
}

.control-section {
  margin: 8px;
  padding: 16px 12px 12px;
  border: 2px groove #ffffff;
  background: #c0c0c0;
}

.section-kicker {
  width: max-content;
  margin: -25px 0 6px;
  padding: 0 5px;
  background: #c0c0c0;
  color: #000080;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", sans-serif;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.control-section h2 {
  margin: 0 0 15px;
  color: #000000;
  font-size: 15px;
  letter-spacing: -.02em;
}

.difficulty {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.diff-btn,
.mode-btn,
.camera-btn {
  width: 100%;
  min-height: 48px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 2px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  color: #000000;
  text-align: left;
  cursor: pointer;
}

.diff-btn:hover,
.mode-btn:hover,
.camera-btn:hover {
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #d4d0c8;
}

.diff-btn:active,
.mode-btn:active,
.camera-btn:active,
.diff-btn[aria-pressed="true"],
.mode-btn[aria-pressed="true"] {
  border-color: #404040 #ffffff #ffffff #404040;
  background: #d4d0c8;
}

.diff-btn[aria-pressed="true"] .diff-name,
.mode-btn[aria-pressed="true"] .mode-name {
  outline: 1px dotted #000000;
  outline-offset: 2px;
}

.diff-index,
.mode-icon,
.camera-icon {
  width: 27px;
  color: #000080;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
}

.diff-name,
.mode-name,
.camera-name {
  min-width: 0;
  font-size: 13px;
  font-weight: 720;
}

.diff-meta,
.mode-state {
  color: #202020;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.mode-btn {
  margin-top: 8px;
}

.camera-btn {
  margin-top: 8px;
  grid-template-columns: auto 1fr;
}

.face-preview {
  width: 27px;
  height: 27px;
  object-fit: cover;
  border: 1px solid var(--signal);
  border-radius: 50%;
}

.field-notes {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  list-style: none;
}

.field-notes li {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 9px;
  color: #202020;
  font-size: 12px;
  line-height: 1.5;
}

.field-notes kbd {
  min-width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border: 1px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  border-bottom-width: 2px;
  background: #c0c0c0;
  color: #000000;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.system-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #202020;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.system-ok {
  color: #008000;
  font-weight: 800;
}

.version-stamp {
  width: min(1320px, calc(100% - 24px));
  margin: 0 auto 14px;
  padding: 6px 10px;
  border: 2px solid;
  border-color: #808080 #ffffff #ffffff #808080;
  background: #c0c0c0;
  color: #303030;
  font-size: 9px;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, .35);
}

.dialog {
  width: min(92vw, 520px);
  max-height: min(86vh, 720px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 3px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  color: #000000;
  box-shadow: 7px 7px 0 rgba(0, 0, 0, .45);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, .55);
}

.dialog-header {
  min-height: 38px;
  padding: 4px 5px 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 0;
  background: #000080;
  color: #ffffff;
}

.dialog-header h2 {
  margin: 0;
  color: #ffffff;
  font-size: 15px;
}

.dialog-body {
  padding: 20px;
  background: #c0c0c0;
}

.dialog-field {
  display: grid;
  gap: 8px;
}

.dialog-field + .dialog-field {
  margin-top: 18px;
}

.field-legend {
  color: #202020;
  font-size: 10px;
  font-weight: 800;
}

select {
  min-height: 48px;
  padding: 10px 40px 10px 12px;
  border: 2px solid;
  border-color: #404040 #ffffff #ffffff #404040;
  border-radius: 0;
  background: #ffffff;
  color: #000000;
}

.camera-stage {
  min-height: 260px;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 3px solid;
  border-color: #404040 #ffffff #ffffff #404040;
  background: #000000;
}

.camera-video {
  width: 100%;
  max-height: 390px;
  display: none;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-canvas {
  display: none;
}

.camera-placeholder {
  max-width: 300px;
  padding: 28px;
  color: #202020;
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.camera-status {
  min-height: 20px;
  margin: 12px 0 0;
  color: #202020;
  font-size: 12px;
}

.camera-actions {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.camera-action-btn {
  min-height: 48px;
  padding: 10px 12px;
  border: 2px solid;
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #c0c0c0;
  color: #000000;
  cursor: pointer;
}

.camera-action-btn.capture {
  border-color: var(--safe-deep);
}

.camera-action-btn.danger {
  border-color: #714036;
  color: #ffb6aa;
}

.camera-action-btn:hover {
  border-color: #ffffff #404040 #404040 #ffffff;
  background: #d4d0c8;
}

.camera-action-btn:active {
  border-color: #404040 #ffffff #ffffff #404040;
  background: #d4d0c8;
}

.site-header :focus-visible,
.dialog-header :focus-visible {
  outline-color: #ffffff;
}

.visually-hidden {
  width: 1px !important;
  height: 1px !important;
  position: absolute !important;
  overflow: hidden !important;
  clip: rect(1px, 1px, 1px, 1px) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

@keyframes field-sweep {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw - 64px)); }
}

@keyframes mine-hit {
  0% { transform: scale(.78); }
  58% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes safe-open {
  from {
    opacity: .45;
    transform: scale(.86);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 900px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .control-section:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  :root {
    --cell-size: 40px;
  }

  .site-header {
    width: calc(100% - 12px);
    margin-top: 6px;
    padding: 4px 5px;
    gap: 6px;
  }

  .brand-home,
  .icon-button {
    width: 28px;
    height: 28px;
  }

  .game-deck {
    display: none;
  }

  .game-shell {
    width: calc(100% - 12px);
    padding: 6px;
  }

  .play-station {
    box-shadow: none;
  }

  .instrument-bar {
    min-height: 70px;
  }

  .readout {
    margin: 6px;
    padding: 5px;
  }

  .readout-value {
    font-size: 29px;
  }

  .face-btn {
    width: 68px;
    min-height: 68px;
  }

  .mission-line {
    grid-template-columns: minmax(110px, 1fr) 1fr auto;
    gap: 8px;
    padding: 9px 10px;
  }

  .phase-label,
  .restart-caption {
    display: none;
  }

  .board-scroller {
    min-height: 340px;
    max-height: 58vh;
    padding: 16px 4px;
  }

  .board-hint {
    font-size: 10px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .control-section:last-child {
    grid-column: auto;
  }

  .camera-actions {
    grid-template-columns: 1fr;
  }

  .version-stamp {
    width: calc(100% - 12px);
    margin-bottom: 6px;
  }
}

@media (orientation: landscape) and (max-height: 480px) {
  .site-header {
    margin-top: 4px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .site-header .brand-home,
  .site-header .icon-button {
    width: 28px;
    height: 28px;
  }

  .eyebrow,
  .game-deck {
    display: none;
  }

  h1 {
    font-size: 15px;
  }

  .game-shell {
    grid-template-columns: minmax(0, 1fr) 250px;
    padding: 6px;
    gap: 6px;
  }

  .instrument-bar {
    min-height: 58px;
  }

  .face-btn {
    width: 58px;
    min-height: 58px;
  }

  .face-glyph {
    font-size: 24px;
  }

  .readout {
    margin: 4px;
    padding: 4px 8px;
  }

  .readout-value {
    font-size: 27px;
  }

  .mission-line {
    min-height: 44px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .board-scroller {
    min-height: 220px;
    max-height: calc(100vh - 160px);
    padding: 12px;
  }

  .board-hint,
  .control-section:nth-child(3),
  .control-section:nth-child(4),
  .version-stamp {
    display: none;
  }

  .control-panel {
    display: block;
  }

  .control-section {
    margin: 5px;
    padding: 8px;
  }

  .control-section .section-kicker {
    display: none;
  }

  .control-section h2 {
    margin-bottom: 5px;
    font-size: 13px;
  }

  .diff-btn,
  .mode-btn,
  .camera-btn {
    min-height: 44px;
    padding: 6px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }

  .sweep-line {
    display: none;
  }
}
