:root {
  --bg: #14121a;
  --panel: #1f1b2b;
  --panel-2: #2b2540;
  --line: #463d66;
  --ink: #f1ecff;
  --muted: #a69cc8;
  --opt: #c7a6ff;
  --opt-visited: #7f74a3;
  --accent: #f2c744;
  --good: #6cf08e;
  --bad: #ff5c7a;
  --pink: #e0457b;
  --font: 'VT323', ui-monospace, monospace;
  --logo: 'Press Start 2P', ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 20px;
  line-height: 1.15;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ------------------------------------------------------------------ HUD */

.top {
  flex: none;
}

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: #0d0b12;
  border-bottom: 2px solid var(--line);
  font-size: 20px;
}

.hud__job {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1;
}

.hud__day {
  color: var(--muted);
  font-size: 16px;
}

.hud__jobname {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 28vw;
}

.hud__time {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hud__clock {
  font-size: 24px;
  color: var(--accent);
}

.hud__bar {
  position: relative;
  flex: 1;
  height: 8px;
  min-width: 40px;
  background: #2a2438;
  border: 1px solid var(--line);
}

.hud__fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #4f8cff, #f2c744 70%, #ff5c7a);
}

.hud__rival {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -55%);
  font-size: 16px;
}

.hud__eta {
  color: var(--muted);
  font-size: 16px;
  white-space: nowrap;
}

.hud.is-urgent .hud__clock,
.hud.is-urgent .hud__eta {
  color: var(--bad);
  animation: pulse 0.8s infinite alternate;
}

.hud.is-safe .hud__eta {
  color: var(--good);
}

@keyframes pulse {
  to {
    opacity: 0.45;
  }
}

.hud__right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud__money {
  color: var(--good);
  font-size: 22px;
  margin-right: 4px;
}

.hud__btn {
  position: relative;
  width: 40px;
  height: 36px;
  background: var(--panel-2);
  border: 2px solid var(--line);
  font-size: 18px;
  line-height: 1;
}

.hud__btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.hud__btn[data-count]:not([data-count=''])::after {
  content: attr(data-count);
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--pink);
  color: #fff;
  font-size: 15px;
  line-height: 18px;
}

/* ---------------------------------------------------------------- Stage */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.viewport {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}

canvas.world {
  display: block;
  width: min(100cqw, 100cqh * 16 / 9);
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* --------------------------------------------------------- Touch buttons */

.touch {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px max(14px, env(safe-area-inset-left)) calc(12px + var(--safe-b));
  pointer-events: none;
}

.touch__dpad,
.touch__act {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.tc {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 18, 26, 0.45);
  color: #fff;
  font-size: 24px;
  touch-action: none;
  backdrop-filter: blur(2px);
}

.tc.is-down {
  background: rgba(199, 166, 255, 0.45);
}

.tc--talk {
  opacity: 0.35;
  transition: opacity 0.2s;
}

.tc--talk.is-ready {
  opacity: 1;
  border-color: var(--accent);
  animation: bob 0.8s infinite alternate;
}

@keyframes bob {
  to {
    transform: translateY(-4px);
  }
}

/* Desktop with a mouse: hide touch controls. */
@media (hover: hover) and (pointer: fine) {
  .touch {
    display: none;
  }
}

/* Portrait phones: canvas on top, controls get their own row below. */
@media (orientation: portrait) {
  .touch {
    position: static;
    flex: none;
    height: 34vh;
    max-height: 240px;
    align-items: center;
    padding-bottom: calc(16px + var(--safe-b));
  }
  .tc {
    width: 74px;
    height: 74px;
  }
  .viewport {
    flex: 0 1 auto;
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: 100%;
  }
  .stage {
    justify-content: flex-start;
  }
  .touch {
    flex: 1;
    height: auto;
    max-height: none;
  }
  /* Keep the world visible above the conversation / notebook. */
  .dialog {
    max-height: calc(100dvh - 60px - 56.25vw);
  }
}

/* --------------------------------------------------------------- UI layer */

.ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

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

/* ---------------------------------------------------------------- Dialog */

.dialog {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(760px, 100%);
  max-height: 64%;
  overflow-y: auto;
  padding: 12px 16px calc(14px + var(--safe-b));
  background: rgba(16, 13, 24, 0.96);
  border: 2px solid var(--line);
  border-bottom: 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from {
    transform: translate(-50%, 30px);
    opacity: 0;
  }
}

.dialog__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.portrait {
  width: 60px;
  height: 66px;
  image-rendering: pixelated;
  border: 2px solid var(--line);
  flex: none;
}

.portrait--big {
  width: 80px;
  height: 88px;
}

.dialog__who {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.dialog__who strong {
  font-size: 24px;
  color: var(--accent);
}

.dialog__who small {
  color: var(--muted);
  font-size: 17px;
}

.mood {
  position: relative;
  color: #6a5f88;
  font-size: 20px;
  letter-spacing: 2px;
}

.mood .on {
  color: var(--pink);
}

.mood.is-low .on {
  color: #ff8a3c;
}

.mood__pop {
  position: absolute;
  left: 110px;
  top: -4px;
  font-size: 20px;
  animation: floatup 0.9s ease-out forwards;
}

.mood__pop.up {
  color: var(--good);
}

.mood__pop.down {
  color: var(--bad);
}

@keyframes floatup {
  to {
    transform: translateY(-16px);
    opacity: 0;
  }
}

.dialog__close {
  align-self: flex-start;
  width: 40px;
  height: 40px;
  background: none;
  border: 2px solid var(--line);
  font-size: 20px;
}

.dialog__say {
  min-height: 2.4em;
  margin: 10px 0 6px;
  font-size: 23px;
  color: #ffe9b8;
  cursor: pointer;
}

.dialog__note {
  display: inline-block;
  margin: 0 0 8px;
  padding: 2px 8px;
  background: #213a2b;
  border: 1px solid var(--good);
  color: var(--good);
  animation: rise2 0.3s ease-out;
}

@keyframes rise2 {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.dialog__opts {
  list-style: none;
  margin: 0;
  padding: 0;
}

.opt {
  display: flex;
  gap: 8px;
  width: 100%;
  padding: 7px 4px;
  min-height: 40px;
  text-align: left;
  background: none;
  border: 0;
  color: var(--opt);
  font-size: 22px;
}

.opt:hover,
.opt:focus-visible {
  color: #fff;
  background: rgba(199, 166, 255, 0.08);
  outline: none;
}

.opt.is-visited {
  color: var(--opt-visited);
}

.opt.is-meta {
  color: var(--accent);
}

.opt.is-locked {
  color: #5f577a;
  cursor: not-allowed;
}

.opt em {
  font-style: normal;
  color: #8a6a9a;
}

.opt__n {
  flex: none;
  width: 1.4em;
  color: #6a5f88;
}

/* -------------------------------------------------------------- Composer */

.composer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 6, 12, 0.78);
  padding: 10px;
}

.composer__panel {
  width: min(760px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 14px 16px 0;
}

.composer__head h2 {
  margin: 0;
  font-family: var(--logo);
  font-size: 14px;
  line-height: 1.5;
  color: var(--accent);
}

.composer__head p {
  margin: 4px 0 10px;
  color: var(--muted);
}

.composer__notes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.composer__notes-title {
  width: 100%;
  color: var(--muted);
  font-size: 17px;
}

.chip {
  padding: 1px 8px;
  border: 1px solid var(--good);
  color: var(--good);
  background: #1a2c22;
  font-size: 18px;
}

.chip--empty {
  border-color: var(--line);
  color: var(--muted);
  background: none;
}

.slot {
  border: 2px solid var(--line);
  margin-bottom: 8px;
  background: var(--panel-2);
}

.slot.is-set {
  border-color: #6a5aa0;
}

.slot__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: 0;
  text-align: left;
}

.slot__label {
  flex: none;
  width: 6.5em;
  color: var(--accent);
}

.slot__value {
  flex: 1;
  color: var(--ink);
}

.slot:not(.is-set) .slot__value {
  color: var(--muted);
}

.slot__chev {
  color: var(--muted);
}

.slot__opts {
  list-style: none;
  margin: 0;
  padding: 0 6px 6px;
}

.slot__opt {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  text-align: left;
  background: #1a1626;
  border: 1px solid #3a3256;
  color: var(--opt);
}

.slot__opt:hover {
  color: #fff;
  border-color: var(--opt);
}

.slot__opt.is-learned {
  color: #b8f5c8;
}

.slot__opt.is-sel {
  border-color: var(--accent);
  color: #fff;
  background: #3a2f1a;
}

.composer__preview {
  margin: 12px 0;
  border: 1px solid #333;
  background: #0b0a0f;
}

.composer__label {
  padding: 2px 8px;
  background: #222;
  color: #888;
  font-size: 16px;
}

.composer__preview pre {
  margin: 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  font-family: var(--font);
  font-size: 18px;
  color: #9ee3b0;
}

.composer__foot {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0 calc(12px + var(--safe-b));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

/* --------------------------------------------------------------- Buttons */

.btn {
  padding: 10px 16px;
  min-height: 44px;
  background: var(--panel-2);
  border: 2px solid var(--line);
  font-size: 22px;
}

.btn:hover:not(:disabled),
.btn:focus-visible {
  border-color: var(--opt);
  outline: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: #fff3c2;
  color: #1b1408;
}

.btn--primary:hover:not(:disabled) {
  background: #ffd85c;
  border-color: #fff;
}

.btn--big {
  font-size: 26px;
  padding: 12px 26px;
}

/* --------------------------------------------------------------- Overlay */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(8, 6, 12, 0.72);
  overflow-y: auto;
}

.card {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 #000;
  text-align: center;
  animation: pop 0.2s ease-out;
}

@keyframes pop {
  from {
    transform: scale(0.94);
    opacity: 0;
  }
}

.card .btn {
  margin: 6px 4px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 17px;
}

.logo {
  margin: 8px 0 10px;
  font-family: var(--logo);
  font-size: clamp(20px, 6vw, 34px);
  line-height: 1.4;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--pink), 6px 6px 0 #000;
}

.tag,
.lead {
  font-size: 23px;
  margin: 8px 0 14px;
}

.best {
  color: var(--muted);
  margin: 12px 0 0;
}

.card h2 {
  margin: 0 0 6px;
  font-family: var(--logo);
  font-size: 16px;
  line-height: 1.5;
  color: var(--accent);
}

.card h2.big {
  font-size: clamp(20px, 6vw, 30px);
  color: var(--bad);
  text-shadow: 3px 3px 0 #000;
}

.card--ending h2.big {
  color: var(--good);
}

.help {
  text-align: left;
  padding-left: 1.2em;
  font-size: 21px;
}

.help li {
  margin-bottom: 8px;
}

.help b {
  color: var(--accent);
  font-weight: normal;
}

.versus {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 10px 0;
}

.versus__side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 42%;
}

.versus__side strong {
  font-size: 22px;
}

.versus__side small {
  color: var(--muted);
  font-size: 17px;
}

.versus__side .salary {
  color: var(--good);
}

.versus__side .eta {
  color: var(--bad);
}

.versus__vs {
  font-family: var(--logo);
  color: var(--pink);
  font-size: 14px;
}

.need {
  color: var(--accent);
}

.terminal {
  text-align: left;
  background: #0b0a0f;
  border: 1px solid #333;
}

.terminal__bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  background: #222;
  color: #888;
  font-size: 16px;
}

.terminal__bar i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555;
}

.terminal__bar i:first-child {
  background: #ff5f57;
}

.terminal__bar span {
  margin-left: 6px;
}

.terminal__out {
  min-height: 4.5em;
  margin: 0;
  padding: 10px;
  font-size: 22px;
  color: #9ee3b0;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  list-style: none;
  padding: 0;
  margin: 12px 0 4px;
}

.checks .ok,
.verdict.ok {
  color: var(--good);
}

.checks .bad,
.verdict.bad {
  color: var(--bad);
}

.verdict {
  font-family: var(--logo);
  font-size: 14px;
  margin: 10px 0;
}

.stats {
  color: var(--accent);
}

.graves {
  list-style: none;
  padding: 0;
  margin: 10px auto 14px;
  max-width: 420px;
  text-align: left;
}

.graves li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px dashed #3a3256;
}

.graves small {
  margin-left: auto;
  color: var(--muted);
  font-size: 16px;
}

.rip {
  color: #8d93a0;
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 6px 14px;
  background: rgba(16, 13, 24, 0.95);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 20px;
  text-align: center;
  pointer-events: none;
}

.toast.is-in {
  animation: toast 2.6s ease forwards;
}

@keyframes toast {
  0% {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
  8%,
  85% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
  }
}

.noscript {
  padding: 20px;
}

/* Small phones */
@media (max-width: 520px) {
  html,
  body {
    font-size: 19px;
  }
  .hud {
    gap: 6px;
    padding: 4px 8px;
    padding-top: max(4px, env(safe-area-inset-top));
  }
  .hud__eta {
    display: none;
  }
  .hud__btn {
    width: 36px;
  }
  .dialog {
    max-height: 72%;
  }
  .slot__head {
    flex-wrap: wrap;
    gap: 2px 8px;
  }
  .slot__label {
    width: auto;
  }
  .slot__value {
    flex-basis: 100%;
    order: 3;
  }
}

/* Short landscape phones */
@media (max-height: 460px) and (orientation: landscape) {
  .dialog {
    max-height: 88%;
    width: min(680px, 74%);
  }
  .dialog__say {
    font-size: 21px;
    margin: 6px 0 4px;
  }
  .opt {
    font-size: 20px;
    padding: 4px;
    min-height: 34px;
  }
  .portrait {
    width: 44px;
    height: 48px;
  }
  .tc {
    width: 58px;
    height: 58px;
  }
}
