@font-face {
  font-family: "Jersey 15";
  src: url("/assets/fonts/Jersey15.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
  size-adjust: 106%;
}
/* Jersey's capital K reads as an H, so that one letter comes from VT323. */
@font-face {
  font-family: "Jersey 15";
  src: url("/assets/fonts/VT323.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+004B;
  size-adjust: 122%;
}

:root {
  --bg: #16121d;
  --panel: #231c2e;
  --panel2: #2d2439;
  --line: #3b3148;
  --text: #f0ecff;
  --dim: #a79fba;
  --gold: #ffd75e;
  --red: #e5484d;
  --green: #58d66b;
  --blue: #6fb8ff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Jersey 15", ui-monospace, monospace;
  font-variant-ligatures: none;
  font-size: 16px;
  line-height: 1.25;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body { min-height: 100dvh; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
input { user-select: text; -webkit-user-select: text; }

#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; position: relative; }
.screen { padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; min-height: 100dvh; }

.spr { background-image: url("/assets/atlas.png"); background-repeat: no-repeat; image-rendering: pixelated; flex: none; }

button { font: inherit; color: inherit; }
.btn {
  background: var(--panel2);
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
.btn:active { transform: translateY(2px); border-bottom-width: 2px; margin-bottom: 2px; }
.btn.big { font-size: 20px; padding: 14px; width: 100%; }
.btn.primary { background: #c8372d; border-color: #7d1f1a; color: #fff; }
.btn:disabled { opacity: 0.45; cursor: default; }
.link { background: none; border: 0; color: var(--dim); text-decoration: underline; padding: 10px; cursor: pointer; align-self: center; }
.label { color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.msg { color: var(--dim); text-align: center; margin: 0; min-height: 1.25em; }
.fine { color: var(--dim); text-align: center; font-size: 14px; margin: 0; }

/* ---------- home ---------- */
#home { justify-content: center; max-width: 420px; margin: 0 auto; }
.hero-row { display: flex; justify-content: center; align-items: flex-end; gap: 10px; height: 96px; }
.logo { font-size: 52px; margin: 0; text-align: center; letter-spacing: 1px; color: #fff; text-shadow: 0 4px 0 #7d1f1a, 0 8px 0 #0b0810; }
.tag { text-align: center; color: var(--dim); margin: 0 0 6px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
input {
  font: inherit;
  font-size: 20px;
  color: var(--text);
  background: #0f0c15;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 48px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--blue); }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: 6px; text-align: center; }
.join .btn { flex: none; width: 96px; }

/* ---------- lobby ---------- */
.lobby-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.code { font-size: 44px; letter-spacing: 6px; color: var(--gold); line-height: 1; }
.lobby-players { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lp { background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 108px; text-align: center; }
.lp.me { border-color: var(--blue); }
.lp.empty { border-style: dashed; color: var(--dim); justify-content: center; font-size: 13px; }
.lp-name { font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lp-cls { font-size: 12px; color: var(--dim); }
.lp-cls b { color: var(--gold); font-weight: 400; }
.class-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cc { background: var(--panel); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 8px; padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; min-height: 92px; }
.cc.on { border-color: var(--gold); background: var(--panel2); }
.cc-name { font-size: 14px; }
.class-info { background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 14px; min-height: 172px; }
.class-info .blurb { color: var(--text); margin-bottom: 4px; }
.class-info .stats { color: var(--dim); margin-bottom: 8px; }
.class-info .ab-row { margin-top: 5px; color: var(--dim); }
.class-info .ab-row b { color: var(--blue); font-weight: 400; }
.class-info .swap { float: right; margin: 0 0 6px 8px; min-height: 36px; padding: 6px 10px; font-size: 13px; }
.lobby-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 8px; }

/* ---------- game ---------- */
#game { padding: 0 0 calc(10px + env(safe-area-inset-bottom)); gap: 0; }
.bar { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 12px; }
.bar-code { color: var(--dim); font-size: 14px; letter-spacing: 2px; }
.pips { display: flex; gap: 4px; align-items: center; flex: 1; justify-content: center; }
.pip { width: 10px; height: 10px; background: var(--line); border-radius: 2px; }
.pip.boss { width: 14px; height: 14px; background: #5a2530; }
.pip.done { background: var(--green); }
.pip.boss.done { background: var(--green); }
.pip.now { background: var(--gold); box-shadow: 0 0 0 2px #0b0810, 0 0 0 3px var(--gold); }
.gold { color: var(--gold); font-size: 15px; min-width: 52px; text-align: right; }
.icon { background: var(--panel); border: 2px solid var(--line); border-radius: 6px; width: 36px; height: 32px; cursor: pointer; font-size: 15px; padding: 0; }
.icon.off { color: var(--dim); text-decoration: line-through; }

.stage { position: relative; display: flex; justify-content: center; background: #0b0810; overflow: hidden; }
#view { display: block; image-rendering: pixelated; }
.banner { position: absolute; left: 0; right: 0; top: 22%; padding: 10px 12px; text-align: center; background: rgba(11, 8, 16, 0.86); border-top: 2px solid var(--gold); border-bottom: 2px solid var(--gold); pointer-events: none; animation: bannerIn 0.25s ease-out; }
.banner.boss { border-color: var(--red); }
.banner.boss .banner-t { color: #ff6b6b; }
.banner.wipe .banner-t { color: #ff6b6b; }
.banner.win .banner-t { color: var(--gold); }
.banner.out { animation: bannerOut 0.25s ease-in forwards; }
.banner-t { font-size: 28px; line-height: 1.05; }
.banner-s { font-size: 14px; color: var(--dim); margin-top: 2px; }
@keyframes bannerIn { from { transform: scaleY(0); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }
@keyframes bannerOut { to { transform: scaleY(0); opacity: 0; } }
.toast { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); background: rgba(11, 8, 16, 0.86); border: 2px solid var(--line); border-radius: 6px; padding: 3px 10px; font-size: 14px; white-space: nowrap; pointer-events: none; }
.toast.warn { border-color: var(--gold); color: var(--gold); }
.toast.err { border-color: var(--red); color: #ffb3b3; }

.timer { height: 4px; background: #0b0810; }
.timer i { display: block; height: 100%; width: 0; background: var(--blue); }
.timer i.low { background: var(--red); }

.log { height: 42px; padding: 4px 12px; font-size: 14px; color: var(--dim); overflow: hidden; display: flex; align-items: center; }

.party { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 8px; }
.chip { position: relative; background: var(--panel); border: 2px solid var(--line); border-radius: 6px; padding: 4px 6px 5px; height: 52px; text-align: left; overflow: hidden; cursor: default; display: block; width: 100%; }
.chip.me { border-color: #4f6f98; }
.chip.pick { border-color: var(--green); cursor: pointer; }
.chip.nopick { opacity: 0.45; }
.chip.down .chip-name { color: #ff8a8a; }
.chip.away { opacity: 0.5; }
.chip-top { display: flex; justify-content: space-between; gap: 4px; font-size: 13px; line-height: 16px; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-hp { color: var(--dim); flex: none; }
.hpbar { height: 5px; background: #0f0c15; border-radius: 2px; overflow: hidden; margin-top: 2px; }
.hpbar i { display: block; height: 100%; background: var(--green); transition: width 0.25s; }
.hpbar i.mid { background: #e8c63e; }
.hpbar i.low { background: #ff6b5e; }
.foe .hpbar i { background: var(--red); }
.chip-sub { font-size: 11px; line-height: 13px; margin-top: 2px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-sub .ok { color: var(--green); }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 1px; margin-right: 3px; }

.panel { padding: 8px 8px 0; display: flex; flex-direction: column; gap: 8px; }
.panel.busy .ab, .panel.busy .opt { opacity: 0.5; pointer-events: none; }
.panel.busy .foe { pointer-events: none; }
.foes { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: 58px 58px; gap: 6px; }
.foe { height: 58px; cursor: pointer; }
.foe.sel { border-color: var(--gold); background: var(--panel2); }
.foe.gone { visibility: hidden; }
.foe .chip-sub.atk { color: #ffb3b3; }
.foe .chip-sub.aoe { color: #ffbe7a; }
.foe .chip-sub.charge { color: var(--gold); }
.foe .chip-sub.heal { color: #9af0b0; }
.foe .chip-sub.summon { color: #d5baff; }
.abs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.ab { position: relative; grid-column: span 2; background: var(--panel2); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 8px; height: 58px; padding: 4px 4px; cursor: pointer; text-align: center; display: flex; flex-direction: column; justify-content: center; gap: 2px; overflow: hidden; }
.ab.wide { grid-column: span 3; height: 48px; }
.ab.full { grid-column: span 6; }
.ab-name { font-size: 16px; line-height: 17px; }
.ab-tag { font-size: 11px; line-height: 12px; color: var(--dim); }
.ab.on { border-color: var(--gold); background: #4a3a22; }
.ab.arm { border-color: var(--green); }
.ab.cd { opacity: 0.45; }
.ab .cdn { position: absolute; right: 4px; top: 2px; font-size: 12px; color: var(--gold); }
.ab:disabled { opacity: 0.45; cursor: default; }
.hint { font-size: 14px; color: var(--dim); text-align: center; min-height: 36px; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
.hint b { color: var(--text); font-weight: 400; }

.choice-title { font-size: 20px; }
.choice-text { color: var(--dim); font-size: 14px; margin-top: -4px; }
.opts { display: flex; flex-direction: column; gap: 6px; }
.opt { background: var(--panel2); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 8px; padding: 8px 12px; min-height: 56px; text-align: left; cursor: pointer; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.opt.on { border-color: var(--gold); background: #4a3a22; }
.opt:disabled { opacity: 0.45; cursor: default; }
.opt-name { font-size: 17px; }
.opt-desc { font-size: 13px; color: var(--dim); }
.results { display: flex; flex-direction: column; gap: 6px; }
.res { background: var(--panel); border: 2px solid var(--line); border-left-width: 5px; border-radius: 6px; padding: 6px 10px; font-size: 14px; }
.res.ok { border-left-color: var(--green); }
.res.bad { border-left-color: var(--red); }
.res-top { display: flex; justify-content: space-between; gap: 8px; }
.res-top span { color: var(--dim); font-size: 12px; flex: none; }
.res-text { color: var(--dim); font-size: 13px; }
.res-fx { color: var(--gold); font-size: 13px; }

/* ---------- summary ---------- */
.sum-head { text-align: center; padding-top: 8px; }
.grade { font-size: 96px; line-height: 0.95; color: var(--gold); text-shadow: 0 5px 0 #7a5a12, 0 10px 0 #0b0810; }
.grade.D, .grade.C { color: #c9c0da; text-shadow: 0 5px 0 #4a4158, 0 10px 0 #0b0810; }
.sum-title { font-size: 26px; margin-top: 12px; }
.sum-score { color: var(--dim); }
.sum-score b { color: var(--text); font-weight: 400; font-size: 20px; }
.sum-lines { background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.sum-lines div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--dim); }
.sum-lines div b { font-weight: 400; color: var(--text); }
.sum-lines div.neg b { color: #ff8a8a; }
.sum-players { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.sp { background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 10px; }
.sp.me { border-color: var(--blue); }
.sp-top { display: flex; gap: 10px; align-items: center; }
.sp-id { flex: 1; min-width: 0; }
.sp-name { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-award { color: var(--gold); font-size: 15px; }
.sp-award span { color: var(--dim); font-size: 12px; display: block; }
.sp-score { font-size: 26px; text-align: right; line-height: 1; }
.sp-score span { display: block; font-size: 11px; color: var(--dim); }
.sp-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 8px; }
.sp-stats div { background: #1a1522; border-radius: 4px; padding: 4px 2px; text-align: center; font-size: 16px; }
.sp-stats div span { display: block; font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; }
.sp-perks { font-size: 12px; color: var(--dim); margin-top: 6px; }

/* ---------- overlays ---------- */
.conn { position: fixed; left: 50%; top: 8px; transform: translateX(-50%); background: #4a3a22; border: 2px solid var(--gold); border-radius: 6px; padding: 4px 12px; font-size: 14px; z-index: 20; }
.modal { position: fixed; inset: 0; background: rgba(8, 6, 12, 0.8); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; }
.modal-card { background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 16px; max-width: 440px; max-height: 90dvh; overflow: auto; }
.modal-card h2 { margin: 0 0 8px; font-weight: 400; font-size: 24px; }
.modal-card ul { margin: 0 0 14px; padding-left: 18px; color: var(--dim); font-size: 15px; }
.modal-card li { margin-bottom: 6px; }

@media (min-width: 620px) {
  .lobby-players { grid-template-columns: repeat(6, 1fr); }
  .log { font-size: 15px; }
}
@media (max-height: 700px) {
  .log { height: 34px; font-size: 13px; }
  .ab { height: 52px; }
  .foes { grid-template-rows: 54px 54px; }
  .foe { height: 54px; }
}
