/* Varsity yearbook: school maroon + trophy gold, pixel display type, rounded body type. */
:root {
  --maroon: #5c1a28;
  --maroon-2: #7d2738;
  --gold: #e8b04a;
  --gold-2: #f6cf7d;
  --ink: #1d1820;
  --paper: #f3f1f7;
  --paper-2: #e4e0ec;
  --muted: #625a6b;
  --good: #2f8a57;
  --bad: #b3261e;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--maroon);
  color: var(--ink);
  font: 500 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
input, textarea { font: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ----- Screens ----- */
.screen { position: fixed; inset: 0; }
.paper-screen {
  overflow-y: auto;
  display: grid;
  place-items: start center;
  padding-block: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.035) 0 12px, transparent 12px 24px),
    var(--maroon);
}
.card {
  width: 100%;
  max-width: 460px;
  background: var(--paper);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(0,0,0,.35);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.title-card { align-items: center; text-align: center; margin-top: 4vh; }
#title-art { width: 100%; max-width: 352px; image-rendering: pixelated; border: 3px solid var(--ink); background: #6fae4f; }
.logo {
  font: 28px/1.25 var(--pixel);
  margin: 6px 0 0;
  color: var(--maroon);
  text-shadow: 3px 3px 0 var(--gold);
  letter-spacing: 1px;
}
.class-name { font: 11px/1.6 var(--pixel); margin: 0; color: var(--ink); text-transform: uppercase; letter-spacing: .06em; }
.countdown-line { margin: 0; font-weight: 800; color: var(--maroon-2); }
.stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.fine { font-size: 14px; color: var(--muted); margin: 0; }
.error { margin: 0; color: var(--bad); font-weight: 700; }

.btn {
  border: 3px solid var(--ink);
  background: #fff;
  padding: 12px 16px;
  font-weight: 800;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.gold { background: var(--gold); }
.btn.maroon { background: var(--maroon); color: #fff; }
.btn.small { padding: 7px 10px; font-size: 14px; box-shadow: 2px 2px 0 var(--ink); }
.btn:disabled { background: var(--paper-2); color: var(--muted); cursor: not-allowed; box-shadow: none; border-color: #9a93a3; }

.pixel-h { font: 14px/1.5 var(--pixel); margin: 0; color: var(--maroon); text-wrap: balance; }
.form-card p { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; }
.field em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 14px; }
.field input, .field textarea {
  border: 3px solid var(--ink);
  background: #fff;
  padding: 10px 12px;
  border-radius: 0;
  width: 100%;
  font-weight: 600;
  font-size: 16px;
}
.field textarea { resize: vertical; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.row-btns .btn { flex: 1 1 140px; }
code { font: 12px var(--pixel); background: var(--paper-2); padding: 2px 4px; }
.code-box {
  font: 18px/1.4 var(--pixel);
  text-align: center;
  background: #fff;
  border: 3px dashed var(--maroon);
  padding: 18px 8px;
  letter-spacing: 2px;
  user-select: all;
  word-break: break-all;
}

/* ----- Character creator ----- */
.creator { display: grid; grid-template-columns: 116px 1fr; gap: 14px; align-items: start; }
.creator canvas { width: 116px; height: 130px; image-rendering: pixelated; background: #8cc06a; border: 3px solid var(--ink); }
.opts { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.opt { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: 6px; }
.opt button { height: 34px; border: 3px solid var(--ink); background: #fff; font-weight: 800; padding: 0; }
.opt .label { text-align: center; font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.swatch { width: 14px; height: 14px; border: 2px solid var(--ink); display: inline-block; flex: none; }
@media (max-width: 380px) { .creator { grid-template-columns: 1fr; justify-items: center; } .opts { width: 100%; } }

/* ----- Game ----- */
#screen-game { background: #3b6e3a; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hud-right { align-items: flex-end; }
.pill {
  background: var(--paper); border: 3px solid var(--ink); padding: 5px 9px;
  box-shadow: 2px 2px 0 rgba(0,0,0,.35); font-weight: 800; white-space: nowrap; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
.pill.money { font: 14px/1.2 var(--pixel); color: var(--good); padding: 8px 10px; font-variant-numeric: tabular-nums; }
.pill.small { font-size: 13px; padding: 3px 8px; }
.pill.countdown { background: var(--maroon); color: var(--gold-2); border-color: var(--ink); }
.hud-btns { display: flex; gap: 6px; }
.hbtn {
  position: relative; border: 3px solid var(--ink); background: var(--gold);
  font: 10px/1 var(--pixel); padding: 10px 9px; box-shadow: 2px 2px 0 rgba(0,0,0,.4);
}
.hbtn:active { transform: translate(1px, 1px); }
.dot { position: absolute; top: -6px; right: -6px; width: 12px; height: 12px; background: var(--bad); border: 2px solid var(--ink); border-radius: 50%; }

#chatlog {
  position: absolute; left: max(10px, env(safe-area-inset-left)); top: calc(max(10px, env(safe-area-inset-top)) + 88px);
  width: min(360px, 62vw); display: flex; flex-direction: column; gap: 4px; pointer-events: none;
}
.logline { background: rgba(29,24,32,.78); color: #fff; padding: 4px 8px; font-size: 14px; line-height: 1.3; transition: opacity .6s; overflow-wrap: anywhere; }
.logline b { color: var(--gold-2); }
.logline.fade { opacity: 0; }

.keys-hint {
  position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  margin: 0; background: rgba(29,24,32,.75); color: #fff; padding: 6px 12px; font-size: 13px; text-align: center;
  width: max-content; max-width: calc(100% - 32px); pointer-events: none;
}
.controls { display: none; }
body.touch .keys-hint { display: none; }
body.touch .controls {
  display: block; position: absolute; left: 0; right: 0; bottom: 0; height: 0; pointer-events: none;
}
.dpad {
  position: absolute; pointer-events: auto; touch-action: none;
  left: max(18px, env(safe-area-inset-left)); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 4px);
  width: 150px; height: 150px;
}
.dpad .d, .dpad .hub { position: absolute; background: rgba(29,24,32,.72); border: 3px solid rgba(255,255,255,.55); }
.dpad .up, .dpad .down { left: 50px; width: 50px; height: 52px; }
.dpad .up { top: 0; border-bottom: 0; }
.dpad .down { bottom: 0; border-top: 0; }
.dpad .left, .dpad .right { top: 50px; height: 50px; width: 52px; }
.dpad .left { left: 0; border-right: 0; }
.dpad .right { right: 0; border-left: 0; }
.dpad .hub { left: 50px; top: 50px; width: 50px; height: 50px; border: 0; }
.dpad .d::after { content: ""; position: absolute; left: 50%; top: 50%; width: 0; height: 0; border: 9px solid transparent; transform: translate(-50%, -50%); }
.dpad .up::after { border-bottom-color: #fff; margin-top: -5px; }
.dpad .down::after { border-top-color: #fff; margin-top: 5px; }
.dpad .left::after { border-right-color: #fff; margin-left: -5px; }
.dpad .right::after { border-left-color: #fff; margin-left: 5px; }
.dpad .d.on { background: rgba(232,176,74,.85); }
.abtn {
  position: absolute; pointer-events: auto;
  right: max(22px, env(safe-area-inset-right)); bottom: calc(max(22px, env(safe-area-inset-bottom)) + 34px);
  width: 76px; height: 76px; border-radius: 50%; border: 4px solid var(--ink);
  background: var(--maroon-2); color: #fff; font: 20px var(--pixel); box-shadow: 3px 3px 0 rgba(0,0,0,.4);
}
.abtn:active { transform: translate(2px, 2px); background: var(--maroon); }

#toast {
  position: absolute; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 92px); transform: translate(-50%, -8px);
  background: var(--ink); color: #fff; border: 3px solid var(--gold); padding: 8px 14px; font-weight: 800;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: #ff8a80; }
#banner {
  position: absolute; left: 50%; bottom: 50%; transform: translate(-50%, 50%);
  background: var(--ink); color: #fff; border: 3px solid var(--gold); padding: 16px 18px; text-align: center;
  font-weight: 800; max-width: calc(100% - 32px); display: flex; flex-direction: column; gap: 12px; align-items: center;
}

/* ----- Sheet ----- */
#sheet-wrap {
  position: fixed; inset: 0; background: rgba(15,10,18,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 86dvh; display: flex; flex-direction: column;
  background: var(--paper); border: 4px solid var(--ink); border-bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise .18s ease-out;
}
@media (min-width: 700px) {
  #sheet-wrap { align-items: center; }
  .sheet { border-bottom: 4px solid var(--ink); box-shadow: 8px 8px 0 rgba(0,0,0,.4); max-height: 82vh; }
}
@keyframes rise { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } #toast { transition: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--maroon); color: var(--gold-2); padding: 12px 14px; }
.sheet-head h2 { font: 12px/1.5 var(--pixel); margin: 0; text-wrap: balance; }
.sheet-close { background: transparent; border: 2px solid var(--gold-2); color: var(--gold-2); width: 36px; height: 36px; font-size: 18px; flex: none; }
#sheet-body { overflow-y: auto; padding: 16px max(16px, env(safe-area-inset-left)) 20px; display: flex; flex-direction: column; gap: 14px; }

.lede { margin: 0; color: var(--muted); }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { flex: 1 1 120px; background: #fff; border: 3px solid var(--ink); padding: 8px 10px; min-width: 0; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.stat .v { font: 13px/1.5 var(--pixel); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  background: #fff; border: 3px solid var(--ink); padding: 10px 12px;
}
.item.current { border-color: var(--good); box-shadow: inset 6px 0 0 var(--good); padding-left: 16px; }
.item.locked { opacity: .6; }
.item .name { font-weight: 800; }
.item .meta { font-size: 14px; color: var(--muted); }
.item .price { font: 11px var(--pixel); color: var(--maroon-2); }
.section-h { font: 11px/1.5 var(--pixel); color: var(--maroon); margin: 4px 0 0; }
.big-btn { width: 100%; padding: 16px; font-size: 17px; }
.note { font-size: 14px; color: var(--muted); margin: 0; }

.person { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; background: #fff; border: 3px solid var(--ink); padding: 8px 10px; text-align: left; width: 100%; }
.person canvas { width: 48px; height: 54px; image-rendering: pixelated; background: #8cc06a; border: 2px solid var(--ink); }
.person .name { font-weight: 800; overflow-wrap: anywhere; }
.person .meta { font-size: 14px; color: var(--muted); }
.online-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); background: #bbb; }
.online-dot.on { background: #3ad06a; }

.profile-top { display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: center; }
.profile-top canvas { width: 108px; height: 122px; image-rendering: pixelated; background: #8cc06a; border: 3px solid var(--ink); }
.profile-top h3 { margin: 0; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.profile-top .aka { color: var(--muted); font-weight: 700; }
.superl { font: 10px/1.6 var(--pixel); color: var(--maroon-2); margin-top: 6px; }
.bio { background: #fff; border: 3px solid var(--ink); padding: 10px 12px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.emote-row { display: flex; gap: 8px; flex-wrap: wrap; }
.emote-row .btn { flex: 1 1 90px; }

.award { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; background: #fff; border: 3px solid var(--ink); padding: 8px 10px; }
.award canvas { width: 48px; height: 54px; image-rendering: pixelated; background: #8cc06a; border: 2px solid var(--ink); }
.award .title { font: 9px/1.6 var(--pixel); color: var(--maroon); }
.award .who { font-weight: 800; overflow-wrap: anywhere; }
.award .meta { font-size: 14px; color: var(--muted); }
.rank { counter-reset: r; display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.rank li { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; padding: 6px 8px; background: #fff; border: 2px solid var(--ink); align-items: center; }
.rank li .n { font: 10px var(--pixel); color: var(--maroon); }
.rank li .w { font: 10px var(--pixel); font-variant-numeric: tabular-nums; }
.rank li.me { background: #fff5dc; }
.big-count { font: 26px/1.3 var(--pixel); color: var(--maroon); text-align: center; margin: 6px 0 0; }

.chat-list { display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.msg { background: #fff; border: 2px solid var(--ink); padding: 6px 10px; overflow-wrap: anywhere; }
.msg .who { font-weight: 800; color: var(--maroon-2); }
.msg .when { color: var(--muted); font-size: 12px; margin-left: 6px; }
.chat-form { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--paper); padding-top: 6px; }
.chat-form input { flex: 1; min-width: 0; border: 3px solid var(--ink); padding: 10px; font-size: 16px; }
.code-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.code-inline .code-box { flex: 1 1 220px; padding: 10px; font-size: 14px; }
