/* Cheat Day – the play area is a full-screen neon canvas; everything on top of it (HUD chips, buttons, menus)
   is the studio frame: square corners, 3px black outlines, hard offset shadows, flat colour, Rubik.
   Short screens (max-height: 430px, phones sideways) put menu buttons in a column on the right. */
:root {
  --paper: #FAF7F0; --beige: #EFE7D3; --slate: #4C5966; --ink: #1E2328; --k: #000;
  --coral: #FF6B57; --sunny: #FFC845; --sky: #3DA5F4; --glow: #80FF84; --grape: #7A5CFF; --slime: #22AA3A;
  --void: #05060A;
  --gut: max(10px, env(safe-area-inset-left));
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--void); color: var(--ink);
  font: 400 16px/1.35 Rubik, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  touch-action: none; overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
/* CRT scanlines over the play area only (game art, not UI). */
.scanlines {
  position: fixed; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 2px, rgba(0, 0, 0, 0.22) 3px);
}

/* The flat look (default; ?neon turns it off) has no CRT scanlines. */
body.flat .scanlines { display: none; }

/* ---- Frame: HUD ---- */
.hud {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: var(--gut);
  display: flex; gap: 6px; pointer-events: none;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px;
  background: var(--beige); border: 3px solid var(--k); box-shadow: 3px 3px 0 var(--k);
  font: 700 14px/1 Rubik, sans-serif; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chip.score { min-width: 7.5em; justify-content: flex-end; background: var(--paper); }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.bars i { display: block; width: 4px; background: #B9B09A; }
.bars i.on { background: var(--slime); }
.bars i:nth-child(1) { height: 25%; } .bars i:nth-child(2) { height: 50%; }
.bars i:nth-child(3) { height: 75%; } .bars i:nth-child(4) { height: 100%; }

.cheats-btn {
  position: fixed; top: max(6px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  min-width: 128px; height: 42px; padding: 0 18px; cursor: pointer; z-index: 15;
  background: var(--sunny); border: 3px solid var(--k); box-shadow: 5px 5px 0 var(--k);
  font: 800 20px/1 Rubik, sans-serif; letter-spacing: 0.02em;
  animation: cheat-pulse 1.1s steps(2, end) infinite;
}
.cheats-btn:active { transform: translate(calc(-50% + 3px), 3px); box-shadow: 2px 2px 0 var(--k); }
@keyframes cheat-pulse { 50% { background: #FFE08A; } }
body.st-cheats .cheats-btn, body.st-results .cheats-btn, body.st-trophies .cheats-btn, body.st-field .cheats-btn { display: none; }

.corner-btns { position: fixed; top: max(8px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 8px; z-index: 15; }
.sq-btn {
  width: 38px; height: 36px; padding: 0; cursor: pointer; font-weight: 800;
  background: var(--beige); border: 3px solid var(--k); box-shadow: 3px 3px 0 var(--k);
}
.sq-btn[aria-pressed="true"] { text-decoration: line-through; background: #CFC6B0; }
.bomb-btn {
  position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  width: 92px; height: 92px; border-radius: 0; cursor: pointer;
  background: var(--coral); border: 3px solid var(--k); box-shadow: 5px 5px 0 var(--k);
  font: 800 14px/1.1 Rubik, sans-serif;
}
.bomb-btn:disabled { opacity: 0.4; }
.bomb-btn:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--k); }

/* The announcer: big deadpan words over the play area. */
.announce {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); width: min(90vw, 760px);
  text-align: center; pointer-events: none; z-index: 3;
  color: var(--paper); font: 800 clamp(26px, 6vw, 58px)/1.05 Rubik, sans-serif;
  text-shadow: 3px 3px 0 var(--k), -1px -1px 0 var(--k), 1px -1px 0 var(--k), -1px 1px 0 var(--k);
  opacity: 0; transition: opacity 0.2s;
}
.announce.show { opacity: 1; }
.announce small { display: block; margin-top: 8px; font-size: 0.45em; font-weight: 700; color: var(--sunny); }

.toasts {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 20;
}
.toast {
  padding: 7px 12px; background: var(--paper); border: 3px solid var(--k); box-shadow: 3px 3px 0 var(--k);
  font: 700 15px/1.2 Rubik, sans-serif; white-space: nowrap;
}
.toast.cheat { background: var(--sunny); }
.toast.trophy { background: var(--glow); }

/* A new alien's intro card: frame-styled, on the left while the alien zooms up on the right. */
.intro-card {
  position: fixed; left: max(14px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); z-index: 4;
  width: min(50vw, 420px); padding: 16px 18px; cursor: pointer;
  background: var(--paper); border: 3px solid var(--k); box-shadow: 5px 5px 0 var(--k);
  animation: intro-in 0.18s steps(3, end);
}
@keyframes intro-in { from { transform: translate(-30px, -50%); opacity: 0; } }
.intro-card h3 { margin: 0; font: 800 36px/1.05 Rubik, sans-serif; }
.intro-card .kicker { color: var(--coral); font-weight: 800; }
.i-line { margin-top: 8px; font-size: 18px; font-weight: 500; }
.i-more { margin-top: 6px; color: var(--slate); }
.i-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.i-stat { display: inline-block; padding: 3px 8px; background: var(--sunny); border: 3px solid var(--k); font: 700 13px/1.2 Rubik, sans-serif; }
body:not(.st-play) .intro-card { display: none; }

/* Field guide */
.field-list { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 2px 6px 6px 2px; margin: 0; list-style: none; }
.field-list li { display: grid; grid-template-columns: 64px 1fr; gap: 2px 10px; align-items: center; padding: 8px 10px; border: 3px solid var(--k); background: #E4DDCC; color: var(--slate); }
.field-list li.got { background: var(--paper); color: var(--ink); box-shadow: 3px 3px 0 var(--k); }
.field-list canvas { grid-row: span 3; width: 64px; height: 64px; background: var(--void); border: 3px solid var(--k); }
.field-list b { font-size: 16px; }
.field-list small { font-size: 13px; }
.field-list .st { display: inline-block; justify-self: start; padding: 1px 6px; background: var(--sunny); border: 2px solid var(--k); font: 700 12px/1.3 Rubik, sans-serif; color: var(--ink); }

/* ---- Frame: menus ---- */
.screen {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: max(58px, calc(env(safe-area-inset-top) + 54px)) var(--gut) max(14px, env(safe-area-inset-bottom));
}
#s-pause, #s-continue, #s-cheats, #s-trophies, #s-results, #s-field, #s-clear { background: rgba(5, 6, 10, 0.55); }
.card {
  width: min(100%, 640px); max-height: 100%; overflow: auto;
  display: flex; flex-direction: column; gap: 14px; padding: 18px 20px;
  background: var(--paper); border: 3px solid var(--k); box-shadow: 5px 5px 0 var(--k);
}
.small-card { width: min(100%, 460px); }
h1, h2 { margin: 0; font-weight: 800; line-height: 1.05; }
h1 { font-size: clamp(40px, 8vw, 64px); }
h2 { font-size: 30px; }
p { margin: 0; }
.kicker { font: 700 13px/1.2 Rubik, sans-serif; color: var(--slate); text-transform: none; margin-bottom: 4px; }
.dek { font-size: 18px; font-weight: 500; margin-top: 6px; }
.how { margin-top: 8px; }
.keys { margin-top: 8px; font-size: 13px; color: var(--slate); }
body.touch .keys { display: none; }
.fine { font-size: 13px; color: var(--slate); }
.tc-btns { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn {
  min-height: 44px; padding: 8px 16px; cursor: pointer;
  background: var(--paper); border: 3px solid var(--k); box-shadow: 4px 4px 0 var(--k);
  font: 700 17px/1.1 Rubik, sans-serif;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--k); }
.btn.primary { background: var(--slime); }
.btn.sunny { background: var(--sunny); }
.btn.small { min-height: 36px; font-size: 14px; padding: 6px 12px; }
.btn:focus-visible, .sq-btn:focus-visible, .cheats-btn:focus-visible, .sw:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
.count { display: inline-block; min-width: 1.4em; padding: 0 6px; background: var(--sunny); border: 3px solid var(--k); font-size: 0.8em; text-align: center; }

/* Cheats menu: a games-magazine cheats page. */
.cheats-card { width: min(100%, 760px); overflow: hidden; }
.cheat-grid, .trophy-list { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 2px 6px 6px 2px; margin: 0; list-style: none; }
.sw {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name tog" "code tog" "desc desc";
  gap: 2px 10px; padding: 9px 10px; text-align: left; cursor: pointer;
  background: var(--paper); border: 3px solid var(--k); box-shadow: 3px 3px 0 var(--k);
}
.sw .nm { grid-area: name; font-weight: 800; font-size: 16px; }
.sw .cd { grid-area: code; font: 700 13px/1.2 Rubik, sans-serif; color: var(--slate); letter-spacing: 0.08em; }
.sw .ds { grid-area: desc; font-size: 13px; }
.sw .tg {
  grid-area: tog; align-self: center; min-width: 46px; padding: 4px 6px; text-align: center;
  font: 800 13px/1 Rubik, sans-serif; background: #D6CDB8; border: 3px solid var(--k);
}
.sw[aria-checked="true"] { background: var(--sunny); }
.sw[aria-checked="true"] .tg { background: var(--slime); }
.c-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.trophy-list li { padding: 8px 10px; border: 3px solid var(--k); background: #E4DDCC; color: var(--slate); }
.trophy-list li b { display: block; color: var(--ink); }
.trophy-list li.got { background: var(--glow); color: var(--ink); box-shadow: 3px 3px 0 var(--k); }
.trophy-list li small { font-size: 13px; }

/* Results */
.results-card { width: min(100%, 680px); }
.big-score { font: 800 46px/1 Rubik, sans-serif; margin-top: 8px; font-variant-numeric: tabular-nums; }
.big-score sup { font-size: 0.5em; color: var(--coral); }
.r-stats { margin-top: 6px; font-weight: 500; }
.r-cheats { margin-top: 4px; font-size: 22px; letter-spacing: 0.1em; }
.r-new { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.r-new li { padding: 4px 8px; background: var(--glow); border: 3px solid var(--k); font-weight: 700; font-size: 14px; }
.r-fine { margin-top: 8px; }
.status { font-size: 14px; font-weight: 500; width: 100%; }
.status:empty { display: none; }

/* ---- Layout by state ---- */
body:not(.st-play):not(.st-pause):not(.st-continue) .hud { display: none; }
body:not(.st-title) .ml-arcade { display: none !important; }

/* Short screens (phones sideways): text left, buttons in a column on the right. */
@media (max-height: 430px) {
  .screen { padding-top: max(50px, calc(env(safe-area-inset-top) + 46px)); padding-bottom: 8px; }
  .card { flex-direction: row; gap: 14px; padding: 12px 14px; align-items: stretch; }
  .tc-text { flex: 1; min-width: 0; overflow: auto; }
  .tc-btns { flex-direction: column; flex-wrap: nowrap; align-items: stretch; flex: none; width: 190px; gap: 7px; overflow: auto; padding: 0 5px 5px 0; }
  .btn { min-height: 34px; padding: 5px 10px; font-size: 15px; }
  .btn.small { min-height: 30px; }
  h1 { font-size: 34px; } h2 { font-size: 22px; }
  .title-card .kicker { display: none; }
  .dek { font-size: 15px; } .how { font-size: 14px; margin-top: 4px; }
  .cheats-card {
    display: grid; grid-template-columns: 1fr 170px; grid-template-rows: auto 1fr;
    grid-template-areas: "list head" "list foot"; gap: 8px 14px; height: 100%;
  }
  .cheats-card .c-head { grid-area: head; }
  .cheats-card .cheat-grid, .cheats-card .trophy-list, .cheats-card .field-list { grid-area: list; }
  .field-list { gap: 6px; } .field-list li { padding: 4px 8px; grid-template-columns: 48px 1fr; }
  .field-list canvas { width: 48px; height: 48px; } .field-list small { font-size: 12px; }
  .intro-card { padding: 8px 10px; width: min(52vw, 360px); } .intro-card h3 { font-size: 22px; }
  .i-line { font-size: 14px; margin-top: 3px; } .i-more { font-size: 13px; margin-top: 2px; }
  .i-foot { margin-top: 6px; } .i-stat { font-size: 12px; } .intro-card .btn.small { min-height: 30px; }
  .cheats-card .c-foot { grid-area: foot; align-items: flex-end; }
  .cheats-card .c-foot .btn { width: 100%; }
  .c-head .dek { font-size: 13px; }
  .cheat-grid, .trophy-list { gap: 6px; }
  .sw { padding: 4px 8px; }
  .trophy-list li { padding: 4px 8px; } .trophy-list li small { font-size: 12px; } .sw .ds { display: none; } .sw .nm { font-size: 14px; }
  .c-foot .fine { display: none; }
  .c-foot { justify-content: flex-end; }
  .big-score { font-size: 32px; margin-top: 4px; }
  .cheats-btn { height: 36px; font-size: 17px; min-width: 110px; }
  .chip { height: 26px; font-size: 12px; padding: 0 6px; }
  .chip.score { min-width: 6.5em; }
  .bomb-btn { width: 74px; height: 74px; font-size: 12px; }
  .announce { top: 45%; }
}
@media (max-width: 900px) { .hud .chip:nth-child(2) { display: none; } }
@media (max-width: 560px) { .cheat-grid, .trophy-list, .field-list { grid-template-columns: 1fr; } }

/* Phones held upright */
.rotate-hint {
  display: none; position: fixed; inset: 0; z-index: 50; place-content: center; gap: 12px; padding: 24px;
  text-align: center; background: var(--void); color: var(--paper); font: 700 22px/1.3 Rubik, sans-serif;
}
.rotate-icon { font-size: 56px; }
.rotate-tip { max-width: 30em; font: 400 15px/1.4 Rubik, sans-serif; color: #B9C2CC; }
body.portrait .rotate-hint { display: grid; }
