/* Film-accurate matrix glyphs, mapped onto ASCII by the typeface.
   Fetched lazily by game.js via document.fonts.load() when matrix mode
   needs it; canvas fillText alone never triggers @font-face downloads. */
@font-face {
  font-family: 'Matrix Code NFI';
  src: url('fonts/matrix-code-nfi.ttf') format('truetype');
  font-display: swap;
}

:root {
  --teal: #8fd4d1;
  --teal-rgb: 143, 212, 209;
  --teal-dim: #3d7a78;
  --teal-deep: #143230;
  --teal-ink: #b7e4e1;
  --bg: #010605;
  --glow: rgba(var(--teal-rgb), 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #dde2e9;
  color: var(--teal);
  font-family: "Share Tech Mono", ui-monospace, monospace;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  /* No long-press callout / magnifier loupe on iOS. */
  -webkit-touch-callout: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

body.fg-ads-offset #crt,
body.fg-ads-offset .screen {
  top: var(--fg-ad-h, 0px);
}

.crt {
  position: fixed;
  inset: 0;
  /* Light desk surface behind the hardware panels. */
  background:
    radial-gradient(ellipse at 50% 35%, #f2f5f8 0%, #dde2e9 78%);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
}

.scanlines,
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0 2px,
    rgba(0, 0, 0, 0.18) 2px 3px
  );
  /* mix-blend-mode over a 60fps canvas is a compositor tax on phones. */
  opacity: 0.55;
}

.vignette {
  background:
    radial-gradient(ellipse at center, transparent 52%, rgba(0, 0, 0, 0.62) 100%);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.45);
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 8px;
  pointer-events: none;
  text-shadow: 0 0 10px var(--glow);
  letter-spacing: 0.14em;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hud-right { justify-content: flex-end; }

.hud-center {
  font-size: clamp(13px, 2.4vw, 18px);
  letter-spacing: 0.22em;
}

#fileName {
  font-size: clamp(15px, 2.6vw, 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  pointer-events: auto;
  appearance: none;
  border: 1px solid var(--teal-dim);
  background: rgba(0, 20, 18, 0.4);
  color: var(--teal);
  width: 34px;
  height: 34px;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  text-shadow: 0 0 8px var(--glow);
}

.icon-btn:hover,
.icon-btn:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--teal);
  line-height: 1;
}

.logo span {
  font-size: 8px;
  letter-spacing: 0.28em;
  margin-top: 2px;
}

.logo svg { display: block; filter: drop-shadow(0 0 6px var(--glow)); }

.logo-lg { margin: 0 auto 8px; }

.coords {
  /* Retired from the panel design; kept in the DOM as a data readout. */
  display: none;
}

.toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 14;
  min-height: 1.2em;
  text-align: center;
  letter-spacing: 0.16em;
  font-size: clamp(13px, 2.4vw, 18px);
  text-shadow: 0 0 12px var(--glow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.toast.show { opacity: 1; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  /* html/body disable touch gestures for the game; re-enable scroll here */
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 16px;
  background: rgba(16, 22, 30, 0.5);
  pointer-events: none;
}

.screen .panel,
.screen .depot-link {
  pointer-events: auto;
}

/* Touches land on the panel, so it must allow the screen's pan gesture. */
.screen .panel {
  touch-action: pan-y;
}

.screen.hidden { display: none; }

.panel {
  width: min(460px, 100%);
  /* margin auto centers when there's room and allows scrolling when not */
  margin: auto;
  flex-shrink: 0;
  border: 1px solid var(--teal-dim);
  background: rgba(1, 10, 9, 0.92);
  box-shadow: 0 0 28px rgba(var(--teal-rgb), 0.12), inset 0 0 40px rgba(var(--teal-rgb), 0.04);
  padding: 28px 22px 24px;
  text-align: center;
}

.kicker {
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 11px;
  opacity: 0.75;
  margin-bottom: 8px;
}

h1, h2 {
  font-weight: 400;
  letter-spacing: 0.18em;
  text-shadow: 0 0 16px var(--glow);
  margin-bottom: 14px;
}

h1 { font-size: clamp(28px, 7vw, 40px); }
h2 { font-size: clamp(22px, 5vw, 30px); }

.blurb, .howto-list, .howto-hint, .best-line {
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: 0.04em;
  color: var(--teal-ink);
  text-align: left;
}

.blurb { margin-bottom: 18px; }

.best-line {
  text-align: center;
  margin-top: 14px;
  opacity: 0.7;
  font-size: 12px;
  letter-spacing: 0.12em;
}

.howto-list {
  padding-left: 1.15em;
  margin-bottom: 14px;
}

.howto-list li { margin-bottom: 10px; }

.howto-list strong { color: var(--teal); }

.howto-hint {
  text-align: center;
  opacity: 0.75;
  margin-bottom: 18px;
}

.diff-row {
  display: flex;
  gap: 8px;
  margin: 2px 0 8px;
}

.diff-btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--teal-dim);
  background: transparent;
  color: var(--teal);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.18em;
  padding: 9px 4px;
  cursor: pointer;
  opacity: 0.65;
}

.diff-btn:hover,
.diff-btn:focus-visible {
  border-color: var(--teal);
  opacity: 0.9;
  outline: none;
}

.diff-btn.sel {
  border-color: var(--teal);
  background: rgba(var(--teal-rgb), 0.14);
  opacity: 1;
  text-shadow: 0 0 8px var(--glow);
}

.hue-row { flex-wrap: wrap; }

.hue-row .hue-btn {
  flex: 1 1 28%;
  min-width: 86px;
}

.hue-btn::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--hue, var(--teal));
  box-shadow: 0 0 6px var(--hue, var(--teal));
  margin-right: 7px;
  vertical-align: middle;
}

.diff-note {
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  color: var(--teal-ink);
  opacity: 0.7;
  margin-bottom: 10px;
  text-align: center;
}

.term-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  appearance: none;
  border: 1px solid var(--teal);
  background: rgba(var(--teal-rgb), 0.1);
  color: var(--teal);
  font: inherit;
  letter-spacing: 0.22em;
  padding: 12px 14px;
  cursor: pointer;
  text-shadow: 0 0 8px var(--glow);
}

.term-btn:hover,
.term-btn:focus-visible {
  background: rgba(var(--teal-rgb), 0.2);
  outline: none;
}

.term-btn-ghost {
  border-color: var(--teal-dim);
  background: transparent;
}

.depot-link {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 14px;
  color: var(--teal);
  text-decoration: none;
  letter-spacing: 0.16em;
  font-size: 13px;
  z-index: 31;
  text-shadow: 0 0 8px var(--glow);
}

.depot-link:hover { color: #fff; }

@media (max-width: 520px) {
  .hud { letter-spacing: 0.08em; }
  .hud-center { letter-spacing: 0.1em; }
  .logo span { display: none; }
}

/* Short viewports (phone landscape): compact menu so it fits on screen. */
@media (max-height: 500px) {
  .screen { padding: 10px 12px; }
  .panel {
    width: min(540px, 100%);
    padding: 12px 16px 12px;
  }
  .logo-lg svg { width: 36px; height: 36px; }
  .logo-lg { margin-bottom: 4px; }
  .kicker { margin-bottom: 3px; }
  h1 { font-size: 22px; margin-bottom: 6px; }
  h2 { font-size: 18px; margin-bottom: 6px; }
  .blurb { font-size: 12px; line-height: 1.4; margin-bottom: 8px; }
  .diff-note { display: none; }
  .diff-row { margin: 2px 0 4px; }
  .diff-btn { padding: 6px 4px; font-size: 11px; }
  .term-btn { padding: 8px 12px; margin-top: 6px; }
  .howto-list li { margin-bottom: 5px; }
  .howto-list, .howto-hint { font-size: 12px; }
  .best-line { margin-top: 8px; }
}

.persona-debug {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(4, 10, 14, 0.88);
  border: 1px solid rgba(var(--teal-rgb), 0.4);
  color: var(--teal);
  font: 11px/1 "Share Tech Mono", monospace;
  letter-spacing: 0.08em;
  pointer-events: auto;
}
.persona-debug.hidden { display: none; }
.persona-debug-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.persona-debug input[type="range"] { flex: 1; min-width: 80px; }
.persona-debug-check { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.persona-debug-solve {
  background: #12302e;
  color: inherit;
  border: 1px solid currentColor;
  border-radius: 4px;
  font: inherit;
  letter-spacing: 0.08em;
  padding: 2px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.persona-debug-solve:active { background: #1d4a47; }
