/* FINANCE SIMULATOR '95 — core visual language (v0.1)
   Palette from the title mockup: office-night navy, CRT beige, SNES gold,
   Win3.1 gray chrome, dot-matrix paper. Monospace everywhere, chunky borders,
   no rounded corners except CRT glass. */

:root {
  /* the game is natively dark — declaring it opts out of Android browser
     "auto dark" / force-dark filters, which halo dark-on-light text */
  color-scheme: dark;
  /* safe-area insets (0 on desktop; live on notched phones via viewport-fit=cover) */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --hud-h: calc(44px + var(--sat));
  --navy-deep: #101026;
  --navy: #1c2a4a;
  --navy-soft: #2a3d66;
  --gold: #e8b83a;
  --gold-hot: #ffd76a;
  --red: #b8322e;
  --red-hot: #e04440;
  --beige: #d8cfc0;
  --bezel: #a89f8e;
  --bezel-dark: #6f6857;
  --paper: #f2ead6;
  --paper-shadow: #d8cdb0;
  --ink: #221a0e;
  --pink: #f2b8c6;
  --pink-ink: #8e2c48;
  --phosphor: #39ff6e;
  --phosphor-dim: #1d8f42;
  --amber: #ffb000;
  --win-gray: #c0c0c0;
  --win-gray-dark: #808080;
  --win-navy: #000080;
  --white: #f8f6ef;
}

/* Courier New doesn't exist on Android; the generic monospace substitute has
   no real bold, and synthetic bold double-strikes into a smeared "drop shadow"
   on small panels (seen on the Z Fold cover screen). Cousine is metric-
   compatible with Courier New and ships a true bold — macOS/iOS still resolve
   Courier New first, so nothing changes there. */
@font-face {
  font-family: 'Cousine';
  src: url('../assets/fonts/cousine-regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Cousine';
  src: url('../assets/fonts/cousine-bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

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

/* Android rasterizes our chunky offset text-shadows far heavier than desktop,
   so text reads muddy-dark. Blanket-disable every text-shadow there for now
   (body.android is set by updateLayout in core.js). */
body.android, body.android * { text-shadow: none !important; }

html, body {
  height: 100%;
  background: #05050c;
  overflow: hidden;
  font-family: "Courier New", Cousine, Courier, monospace;
  color: var(--white);
  -webkit-font-smoothing: none;
  /* touch hardening: the core loop is rapid tapping — no zoom, no selection
     loupes, no callouts, no gray tap flashes, no rubber-banding */
  position: fixed; inset: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}

img { image-rendering: pixelated; -webkit-user-drag: none; }

/* ---- stage: the full viewport ---- */
#stagewrap { position: fixed; inset: 0; }
#stage {
  position: absolute; inset: 0;
  background: var(--navy-deep);
  overflow: hidden;
}
#stage .screen { position: absolute; inset: 0; overflow: hidden; }

/* global scanlines */
#scanlines {
  position: absolute; inset: 0; pointer-events: none; z-index: 900;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.07) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
  display: none; /* disabled for now — delete this line to bring them back */
}

/* ---- HUD (the only three gauges) ---- */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 800;
  height: var(--hud-h);
  display: flex; align-items: center; gap: 14px;
  padding: var(--sat) max(12px, var(--sar)) 0 max(12px, var(--sal));
  background: linear-gradient(#20204a, #16163a);
  border-bottom: 3px solid #000;
  font-size: 14px; font-weight: bold; letter-spacing: 1px;
}
body.compact #hud { gap: 8px; font-size: 12px; letter-spacing: 0; }
body.compact #hud .hud-label { display: none; }
#hud[hidden] { display: none; }
#hud .hud-item { display: flex; align-items: center; gap: 7px; }
#hud .hud-right { margin-left: auto; display: flex; gap: 14px; }
#hud .hud-date { color: var(--gold); }
#hud .hud-cash { color: var(--phosphor); }
#hud .hud-cash.neg { color: var(--red-hot); }
#hud .hud-board { color: var(--white); opacity: .85; }
.smiley { /* canvas element drawn by ui.smiley() */
  display: inline-block; flex: none;
  image-rendering: pixelated;
}

/* ---- Win 3.1 window chrome ---- */
.win {
  background: var(--win-gray);
  border-top: 3px solid #fff;
  border-left: 3px solid #fff;
  border-right: 3px solid #4d4d4d;
  border-bottom: 3px solid #4d4d4d;
  box-shadow: 4px 4px 0 rgba(0,0,0,.45);
  color: #000;
}
.win { max-width: calc(100vw - 16px); }
.win-title {
  background: var(--win-navy);
  color: #fff;
  padding: 4px 8px;
  font-weight: bold; font-size: 14px; letter-spacing: 1px;
  display: flex; justify-content: space-between; align-items: center;
  user-select: none;
  min-width: 0;
}
.win-title > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.win-title .win-dot { width:14px; height:14px; background: var(--win-gray);
  border:1px solid #000; flex:none; }
.win-body { padding: 12px; font-size: 15px; font-weight: bold; }

/* ---- buttons ---- */
.btn {
  font-family: inherit;
  font-size: 15px; font-weight: bold; letter-spacing: 1px;
  padding: 8px 18px;
  background: var(--win-gray);
  color: #000;
  border-top: 3px solid #fff;
  border-left: 3px solid #fff;
  border-right: 3px solid #4d4d4d;
  border-bottom: 3px solid #4d4d4d;
  cursor: pointer;
  text-transform: uppercase;
}
.btn:active { border-top:3px solid #4d4d4d; border-left:3px solid #4d4d4d;
  border-right:3px solid #fff; border-bottom:3px solid #fff; }
.btn:disabled { color:#7a7a7a; cursor:default; }
.btn.btn-gold { background: var(--gold); }
.btn.btn-red { background: var(--red-hot); color:#fff; }
.btn.btn-big { font-size: 20px; padding: 14px 30px; }
.btn:focus-visible { outline: 3px dashed var(--gold-hot); outline-offset: 2px; }
body.touch .btn { min-height: 44px; }
body.touch .btn.btn-big { min-height: 52px; }

/* ---- paper / dot-matrix ---- */
.paper {
  background:
    repeating-linear-gradient(0deg, transparent 0 26px, rgba(60,40,10,.03) 26px 27px),
    var(--paper);
  color: var(--ink);
  border: 2px solid var(--paper-shadow);
  box-shadow: 5px 5px 0 rgba(0,0,0,.4);
  padding: 16px;
  font-size: 16px;
  max-width: calc(100vw - 16px);
}
.paper.pink { background: var(--pink); color: var(--pink-ink);
  border-color: #d391a4; }
.dotmatrix {
  font-family: "Courier New", Cousine, monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  line-height: 1.7;
  font-weight: bold;
}
.dotmatrix .dm-head {
  border-bottom: 2px dashed var(--ink); padding-bottom: 6px; margin-bottom: 10px;
  font-weight: bold;
}
.tearoff { position: relative; }
.tearoff::before, .tearoff::after {
  content: ''; position: absolute; left: 0; right: 0; height: 8px;
  background-image: radial-gradient(circle at 6px 4px, transparent 4px, var(--paper) 4px);
  background-size: 14px 8px;
}
.tearoff::before { top: -8px; }
.tearoff::after { bottom: -8px; transform: scaleY(-1); }

/* ---- stamps ---- */
.stampmark {
  display: inline-block;
  padding: 4px 14px;
  font-weight: bold; font-size: 22px; letter-spacing: 3px;
  border: 4px double currentColor;
  transform: rotate(-8deg);
  opacity: .92;
  pointer-events: none;
}
.stamp-approve { color: #1b6e34; }
.stamp-void { color: var(--red); }
@keyframes stampIn {
  0% { transform: rotate(-8deg) scale(2.4); opacity: 0; }
  60% { transform: rotate(-8deg) scale(.94); opacity: 1; }
  100% { transform: rotate(-8deg) scale(1); opacity: .92; }
}
.stampmark.fresh { animation: stampIn .18s steps(3) both; }

/* ---- date cards ---- */
.datecard {
  position: absolute; inset: 0; z-index: 850;
  background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center;
  cursor: pointer;
}
.datecard { padding: 0 max(16px, var(--sar)) 0 max(16px, var(--sal)); }
.datecard .dc-main {
  font-size: clamp(20px, 6.5vw, 34px); font-weight: bold;
  letter-spacing: clamp(2px, 1vw, 4px);
  color: var(--gold);
  text-shadow: 3px 3px 0 #5a3a00, 6px 6px 0 #000;
  text-transform: uppercase;
}
.datecard .dc-sub {
  font-size: clamp(14px, 4vw, 17px); color: var(--white); opacity: .92;
  letter-spacing: 2px;
  max-width: min(660px, 92vw); line-height: 1.8; font-weight: bold;
}
.datecard .dc-hint { position:absolute; bottom:calc(26px + var(--sab));
  font-size:12px; opacity:.45; letter-spacing:2px; }

/* ---- first-time orientation tours (ui.orient) ----
   A spotlight cutout over the live element (the scrim is the hole's giant
   box-shadow), a bobbing gold arrow, and a terse paper chip. The tour root
   eats every click (advance); hole/tip/hint are pointer-transparent.
   z 820: over the HUD (800) so even it dims — only the spotlit element
   stays lit — but under datecards (850). */
.tour { position: absolute; inset: 0; z-index: 820; cursor: pointer; }
/* while a tour is up, the global CRT overlay (z 900, above the tour)
   would texture the chips — clarity wins */
body.touring #scanlines { display: none; }
.tour-hole {
  position: absolute; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(5, 5, 15, .78);
  outline: 3px dashed var(--gold); outline-offset: 2px;
  animation: tourPulse 1s steps(2) infinite;
}
@keyframes tourPulse { 50% { outline-color: var(--gold-hot); } }
.tour-tip {
  position: absolute; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  max-width: min(400px, calc(100vw - 16px));
}
.tour-tip .tt-arrow {
  font-size: 30px; line-height: 1; color: var(--gold-hot);
  text-shadow: 2px 2px 0 #000;
}
.tour-tip.tt-below .tt-arrow { animation: tourBobUp .5s steps(2) infinite; }
.tour-tip.tt-above .tt-arrow { animation: tourBobDn .5s steps(2) infinite; }
@keyframes tourBobUp { 50% { transform: translateY(-5px); } }
@keyframes tourBobDn { 50% { transform: translateY(5px); } }
.tour-tip .tt-card {
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .5);
  padding: 6px 12px; text-align: center;
}
.tour-tip .tt-label {
  font-weight: bold; font-size: 15px; letter-spacing: 1px;
  text-transform: uppercase; white-space: nowrap;
}
.tour-tip .tt-sub {
  /* tutorial voice: plain sentence-case English, not game caps */
  font-size: 12px; font-weight: bold; letter-spacing: .3px;
  line-height: 1.45; opacity: .85; margin-top: 3px;
}
.tour-hint {
  position: absolute; left: 0; right: 0;
  bottom: calc(12px + var(--sab));
  text-align: center; pointer-events: none;
  font-size: 11px; font-weight: bold; letter-spacing: 2px;
  color: var(--white); opacity: .5;
}

/* ---- dialogue box ---- */
.dialog {
  position: absolute; z-index: 700;
  left: max(24px, var(--sal)); right: max(24px, var(--sar));
  bottom: calc(20px + var(--sab));
  background: var(--navy);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 3px #000, 6px 6px 0 rgba(0,0,0,.5);
  min-height: 150px;
  display: flex; gap: 14px; padding: 14px;
}
.dialog .dlg-portrait { flex: none; width: 110px; }
.dialog .dlg-portrait .portrait { width: 110px; height: 130px; }
.dialog .dlg-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
body.compact .dialog {
  left: max(10px, var(--sal)); right: max(10px, var(--sar));
  bottom: calc(10px + var(--sab));
  gap: 10px; padding: 12px; min-height: 120px;
}
body.compact .dialog .dlg-portrait { width: 64px; }
body.compact .dialog .dlg-portrait .portrait { width: 64px; height: 76px; font-size: 26px; }
body.compact .dialog .dlg-choices { flex-direction: column; }
body.compact .dialog .dlg-choices .btn { width: 100%; }
@media (max-width: 399px) {
  .dialog .dlg-portrait { display: none; }
}
body.short .dialog { min-height: 100px; }
body.short .dialog .dlg-text { max-height: 34dvh; overflow-y: auto; overscroll-behavior: contain; }
.dialog .dlg-name {
  color: var(--gold-hot); font-weight: bold; letter-spacing: 2px;
  font-size: 14px; margin-bottom: 6px; text-transform: uppercase;
}
.dialog .dlg-text { font-size: 16px; line-height: 1.65; min-height: 56px;
  white-space: pre-wrap; }
.dialog .dlg-choices { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.dialog .dlg-next { align-self: flex-end; margin-top: 8px; font-size: 12px;
  color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- portraits ---- */
.portrait {
  width: 96px; height: 112px;
  border: 3px solid #000;
  box-shadow: 0 0 0 2px var(--gold);
  background: var(--navy-soft);
  object-fit: cover; object-position: top center;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: bold; color: rgba(255,255,255,.85);
  text-shadow: 2px 2px 0 #000;
  flex: none;
}

/* ---- CRT phosphor panel ---- */
.crt {
  background: #061206;
  color: var(--phosphor);
  border: 14px solid var(--beige);
  border-radius: 10px;
  box-shadow: inset 0 0 22px rgba(57,255,110,.28), 0 0 0 3px var(--bezel-dark),
    6px 8px 0 rgba(0,0,0,.5);
  font-size: 15px;
  text-shadow: 0 0 4px rgba(57,255,110,.55);
}

/* ---- toast ---- */
#toasts { position: absolute; top: calc(var(--hud-h) + 10px);
  right: max(12px, var(--sar)); z-index: 950;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0,0,0,.5);
  padding: 7px 12px; font-size: 13px; font-weight: bold;
  letter-spacing: 1px; text-transform: uppercase;
  animation: toastIn .15s steps(3) both;
  max-width: min(440px, calc(100vw - 24px));
}
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }

/* ---- generic helpers ---- */
.center { display:flex; align-items:center; justify-content:center; }
.col { display:flex; flex-direction:column; }
.row { display:flex; flex-direction:row; }
.gap { gap: 12px; }
.grow { flex: 1; }
.gold { color: var(--gold-hot); }
.phos { color: var(--phosphor); }
.dim { opacity: .8; }
.small { font-size: 13px; }
.big { font-size: 22px; font-weight: bold; }
.uppercase { text-transform: uppercase; letter-spacing: 2px; }

/* Some OLED cover panels (Z Fold closed) fringe subpixel-antialiased
   dark-on-light text into a heavy double-strike "shadow"; light-on-dark text
   (grayscale AA) is unaffected, and rotating the panel sidesteps it — which
   is exactly the reported symptom. opacity:.999 pushes these surfaces onto a
   compositor path that rasterizes text with grayscale AA. Visually identical
   otherwise; touch-only so desktop keeps native rendering. */
body.touch .paper, body.touch .win, body.touch .toast,
body.touch .wsj-paper, body.touch .ev-chkstrip, body.touch .eg-cert,
body.touch .eg-wsj, body.touch .eg-clip, body.touch .t-plate,
body.touch .tt-card {
  opacity: .999;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01s !important; transition-duration: .01s !important; }
  /* infinite loops (marquees, blinks) freeze instead of strobing */
  .rm-pause { animation-play-state: paused !important; }
}

/* ---- scrollable panel convention (sheets, ledgers, broadsheets) ---- */
.scrollpanel {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* ---- tip jar: real-world support link (title / PRESS START screen).
   A dark inset chip reads like a little LED ticker on the grey windows;
   a gold "$" coin keeps it on-theme (and out of fiction — a modern ask). */
.tip-jar {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  max-width: 100%; box-sizing: border-box;
  text-decoration: none; text-transform: uppercase; white-space: nowrap;
  font-weight: bold; font-size: clamp(11px, 3vw, 12px); letter-spacing: 1.5px;
  color: var(--gold-hot); background: #2a1c10;
  border-top: 2px solid #6a4a28; border-left: 2px solid #6a4a28;
  border-right: 2px solid #120a04; border-bottom: 2px solid #120a04;
  padding: 8px 14px; cursor: pointer;
}
.tip-jar:hover { background: #3a2716; }
.tip-jar:active {
  border-top-color: #120a04; border-left-color: #120a04;
  border-right-color: #6a4a28; border-bottom-color: #6a4a28;
}
.tip-jar:focus-visible { outline: 3px dashed var(--gold-hot); outline-offset: 2px; }
body.touch .tip-jar { min-height: 44px; }
.tip-jar .tj-coin {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--gold-hot); color: #5a3a00; border: 2px solid #5a3a00;
  font-size: 12px; line-height: 1; letter-spacing: 0;
}

/* ---- tip panel: the embedded Ko-fi widget in a game window. Sits above the
   game UI but under the CRT overlays (900+), like every other panel. ---- */
.tip-overlay {
  position: absolute; inset: 0; z-index: 880;
  background: rgba(5, 5, 15, .82);
  display: flex; align-items: center; justify-content: center;
  padding: calc(12px + var(--sat)) 12px calc(12px + var(--sab));
  box-sizing: border-box;
}
.tip-win {
  width: min(400px, calc(100vw - 24px)); max-height: 100%;
  display: flex; flex-direction: column;
}
.tip-win .win-title { padding-right: 4px; }
.tip-win .win-body {
  padding: 4px; background: #f9f9f9;
  display: flex; flex-direction: column; gap: 3px; min-height: 0;
}
.tip-frame {
  display: block; border: none; width: 100%; background: #f9f9f9;
  height: min(712px, calc(100dvh - 140px));
}
.tip-fallback {
  text-align: center; font-size: 11px; letter-spacing: .5px;
  color: #6a6a6a; text-decoration: none; padding: 4px 2px;
}
.tip-fallback:hover { color: #000; text-decoration: underline; }
/* generic Win 3.1 close box — swapped in for ui.win()'s decorative .win-dot
   wherever a window actually needs to close (tip panel, title menu) */
.win-close {
  font-family: inherit; font-weight: bold; font-size: 15px; line-height: 1;
  width: 22px; height: 22px; padding: 0; cursor: pointer;
  background: var(--win-gray); color: #000;
  border-top: 2px solid #fff; border-left: 2px solid #fff;
  border-right: 2px solid #4d4d4d; border-bottom: 2px solid #4d4d4d;
}
.win-close:active {
  border-top-color: #4d4d4d; border-left-color: #4d4d4d;
  border-right-color: #fff; border-bottom-color: #fff;
}
body.touch .win-close { width: 30px; height: 30px; font-size: 18px; }
