:root {
  --ink: #1d2226;
  --muted: #56616b;
  --blue: #0a66c2;
  --blue-dark: #004182;
  --paper: #ffffff;
  --hover: #eef3f8;
  --blood: #8e1b1b;
  --night: #2b3138;
  --gutter: 16px;
  --pixel: 'Pixelify Sans', ui-monospace, monospace;
  --text: 'Atkinson Hyperlegible', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
  color: var(--ink);
  font-family: var(--text);
  -webkit-text-size-adjust: 100%;
}

#game {
  position: fixed;
  inset: 0;
  /* Holding a finger down shouldn't select text, pop up the magnifier or
     a callout menu. Pinch-zoom still works on the panels. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* No double-tap zoom on controls, so quick taps register as taps. */
button, input, label { touch-action: manipulation; }
dialog { -webkit-user-select: text; user-select: text; -webkit-tap-highlight-color: transparent; }

/* The 3D view renders underneath; the 2D canvas on top carries the text. */
#game canvas { position: absolute; inset: 0; }
#game .screen3d { pointer-events: none; }
#game .screen3d[hidden] { display: none; }
/* Programmatic focus target only, not an interactive control. */
#game:focus { outline: none; }

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  image-rendering: pixelated;
}

/* ---------- Panels shared by the HUD, feed and toasts ---------- */

.hud,
.feed,
.toast {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--ink);
}

/* ---------- Top left: name and stats ---------- */

.hud {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: var(--gutter);
  display: grid;
  gap: 4px;
  padding: 8px 12px;
  max-width: calc(100vw - 2 * var(--gutter) - 256px);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-family: var(--pixel);
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  white-space: nowrap;
}

.wordmark img { display: block; flex: none; image-rendering: pixelated; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.stat { white-space: nowrap; }
#met, #total, #clock { color: var(--ink); font-weight: 700; }
#clock { font-variant-numeric: tabular-nums; }

.layoffs {
  justify-self: start;
  margin: 2px 0 0;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--blood);
  border-radius: 4px;
}

.layoffs[hidden] { display: none; }

.career {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

#xp, #ssi, #cvs { font-variant-numeric: tabular-nums; }
#ssi, #cvs { color: var(--ink); font-weight: 700; }

.burnout {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.burnout meter { width: 80px; height: 10px; }
#burnout-pct { min-width: 3.5ch; color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

.quest {
  margin: 0;
  max-width: 260px;
  font-size: 13px;
  line-height: 1.35;
}

.quest[hidden] { display: none; }

/* ---------- Top right: menu ---------- */

.menu {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  right: var(--gutter);
  display: flex;
  gap: 6px;
}

button {
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  min-height: 44px;
  padding: 6px 14px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

button:hover { background: var(--hover); }
button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
button[hidden] { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
}

#sound .icon-off { display: none; }
#sound[aria-pressed="true"] { color: #fff; background: var(--ink); }
#sound[aria-pressed="true"] .icon-on { display: none; }
#sound[aria-pressed="true"] .icon-off { display: block; }

.view-btn { font-family: var(--pixel); font-size: 16px; }
.view-btn[aria-busy="true"] { cursor: progress; opacity: 0.7; }

kbd {
  margin-left: 8px;
  padding: 1px 5px;
  font-family: var(--text);
  font-size: 12px;
  font-weight: 400;
  border: 1px solid var(--muted);
  border-radius: 3px;
  color: var(--muted);
}

/* ---------- Bottom: actions and feed ---------- */

.bottom {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  /* Let taps in the gaps reach the park. */
  pointer-events: none;
}

.bottom > * { pointer-events: auto; }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.actions[hidden] { display: none; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.action-row > * { pointer-events: auto; }

.throws { gap: 6px; }

.throw {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  padding: 0 8px;
  font-size: 18px;
}

.throw .count { font-size: 13px; font-variant-numeric: tabular-nums; }
.throw:disabled { cursor: not-allowed; opacity: 0.55; }
.throw:disabled:active { transform: none; box-shadow: 3px 3px 0 var(--ink); }

.reactions { display: flex; gap: 6px; }

.react {
  width: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.btn-icon, .btn-short { display: none; }

#connect.is-on { color: #fff; background: var(--blue); }
#connect.is-on kbd { color: #fff; border-color: #fff; }

.feed {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(720px, 100%);
  min-height: 40px;
  padding: 6px 10px;
}

.feed-label {
  flex: none;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--blue);
  border-radius: 4px;
}

.feed-text {
  margin: 0;
  min-width: 0;
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-text.is-new { animation: feed-in 0.35s ease-out; }

@keyframes feed-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(420px, calc(100vw - 2 * var(--gutter)));
  margin: 0;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
}

.toast[hidden] { display: none; }

/* ---------- Dialogs ---------- */

dialog {
  width: min(460px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - 2 * var(--gutter));
  overflow: auto;
  padding: 24px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 6px 6px 0 var(--ink);
}

dialog::backdrop { background: rgba(24, 30, 36, 0.5); }

dialog h2 {
  margin: 0 0 12px;
  font-family: var(--pixel);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
}

dialog .dialog-title { font-size: 30px; }

dialog p {
  margin: 0 0 20px;
  font-size: 17px;
  line-height: 1.5;
}

.intro-logo {
  display: block;
  margin-bottom: 12px;
  image-rendering: pixelated;
}

.controls {
  display: grid;
  gap: 6px;
  margin: 0 0 24px;
  padding: 14px 0;
  border-block: 2px solid var(--hover);
}

.controls div { display: flex; justify-content: space-between; gap: 16px; }
.controls dt { font-weight: 700; }
.controls dd { margin: 0; color: var(--muted); text-align: right; }

form { margin: 0; }

.primary {
  width: 100%;
  min-height: 48px;
  font-size: 17px;
  color: #fff;
  background: var(--blue);
  box-shadow: 4px 4px 0 var(--ink);
}

.primary:hover { background: var(--blue-dark); }

dialog .disclaimer {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

dialog .tip {
  margin: 12px 0 0;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}

.beer {
  font-weight: 700;
  color: var(--blue);
  text-underline-offset: 2px;
}

.beer:hover { color: var(--blue-dark); }
.beer:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 2px; }

/* Composer */

fieldset {
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 8px;
  padding: 0;
  font-weight: 700;
}

.choices { display: grid; gap: 6px; }

.choices label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  font-size: 15px;
  line-height: 1.35;
  border: 2px solid var(--hover);
  border-radius: 6px;
  cursor: pointer;
}

.choices label:hover { border-color: var(--muted); }
.choices label:has(input:checked) { border-color: var(--blue); background: var(--hover); }
.choices input { flex: none; margin: 2px 0 0; accent-color: var(--blue); }

dialog .preview-label {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

dialog .preview {
  padding: 12px;
  font-size: 16px;
  background: var(--hover);
  border-radius: 6px;
}

.dialog-buttons {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
}

/* Career, achievements, leaderboard */

/* Headings that take focus when a dialog opens; they aren't controls. */
dialog h2[tabindex="-1"]:focus { outline: none; }

dialog h3.dialog-subtitle {
  margin: 20px 0 8px;
  font-size: 17px;
}

.profile-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0 0 8px;
  font-size: 15px;
}

.profile-stats dt { color: var(--muted); }
.profile-stats dd { margin: 0; font-weight: 700; }

.achievement-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.achievement-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.35;
  border: 2px solid var(--hover);
  border-radius: 6px;
}

.achievement-list .badge { grid-row: span 2; font-size: 20px; }
.achievement-list .name { font-weight: 700; }
.achievement-list .desc { color: var(--muted); }
.achievement-list .locked { border-style: dashed; }
.achievement-list .locked .name { font-weight: 400; }
.achievement-list .locked .badge { filter: grayscale(1); opacity: 0.5; }

.leaderboard {
  margin: 0 0 12px;
  padding-left: 1.6em;
  font-size: 14px;
  line-height: 1.6;
}

.leaderboard .title { color: var(--muted); }
.leaderboard .score { font-weight: 700; font-variant-numeric: tabular-nums; }

.score-form { margin-bottom: 16px; }
.score-form label { display: block; margin-bottom: 4px; font-weight: 700; font-size: 14px; }
.score-row { display: flex; gap: 8px; }

.score-row input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 6px 10px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 6px;
}

.score-row input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
dialog .score-status { margin: 6px 0 0; font-size: 14px; min-height: 1.4em; }

/* The CEO pitch */

.pitch-round { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
dialog .pitch-ask { font-size: 20px; font-weight: 700; }

.pitch-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

dialog .pitch-feedback { min-height: 1.5em; margin: 0; font-weight: 700; }

/* Memorial wall */

.memorial-list {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.memorial-list li {
  padding: 12px 0;
  border-top: 2px solid var(--hover);
}

dialog .memorial-list p { margin: 0; font-size: 14px; line-height: 1.4; }
dialog .memorial-list .who { font-size: 16px; font-weight: 700; }
dialog .memorial-list .role { margin-top: 2px; color: var(--muted); }
dialog .memorial-list .how { margin-top: 4px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  :root { --gutter: 12px; }

  .hud { padding: 6px 10px; max-width: calc(100vw - 2 * var(--gutter) - 236px); }
  .wordmark { font-size: 17px; }
  .wordmark img { width: 24px; height: 24px; }
  .stats { font-size: 13px; }

  .menu { gap: 4px; }
  .icon-btn { width: 42px; min-height: 42px; }

  .feed-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    font-size: 13px;
  }

  dialog { padding: 20px; }
  dialog h2 { font-size: 32px; }
  dialog .dialog-title { font-size: 26px; }
  dialog p { font-size: 16px; }
}

@media (max-width: 480px) {
  /* The menu takes the top row; the HUD goes full width underneath it. */
  .hud {
    top: calc(max(var(--gutter), env(safe-area-inset-top)) + 52px);
    right: var(--gutter);
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
  }

  /* Keep the page heading for screen readers; there's no room to show it. */
  .hud .wordmark {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .hud > * { white-space: nowrap; }
  .burnout meter { width: 60px; }
  .quest { flex-basis: 100%; }

  .wordmark-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* One row of compact buttons: icons, plus a short word where it helps.
     The full label stays in the button for screen readers. */
  .bottom { gap: 6px; }
  .action-row, .actions, .reactions { gap: 4px; flex-wrap: nowrap; }
  .react { width: 40px; min-height: 42px; font-size: 18px; }
  .actions button:not(.react) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 40px;
    min-height: 42px;
    padding: 0 8px;
    font-size: 14px;
  }
  .throw { min-width: 40px; padding: 0 6px; font-size: 16px; }
  .btn-icon { display: inline; font-size: 17px; }
  .actions kbd { display: none; }
  .btn-short { display: inline; }
  .btn-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* The feed: one line, smaller. */
  .feed { min-height: 32px; padding: 4px 8px; gap: 8px; }
  .feed-label { padding: 1px 6px; font-size: 11px; }
  .feed-text { -webkit-line-clamp: 1; font-size: 12px; }

  /* The HUD: smaller type, tighter rows. */
  .hud { padding: 5px 8px; gap: 1px 8px; }
  .stats, .career, .burnout, .quest { font-size: 12px; }
  .layoffs { margin: 0; padding: 1px 6px; font-size: 11px; }
  .burnout meter { width: 48px; height: 8px; }
  .quest {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (pointer: coarse) {
  kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .feed-text.is-new { animation: none; }
  button:active { transform: none; }
}
