:root {
  --ink: #1f1a17;
  --paper: #fff8ec;
  --orange: #f28c28;
  --blue: #2f8fdc;
  --red: #d64541;
  --green: #3aa55d;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fd3ff;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }

#topbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#job-title {
  font-family: 'Lilita One', sans-serif; font-size: 18px; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.35); letter-spacing: .5px;
}
#payout {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px;
  padding: 4px 18px 6px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center;
}
#payout .label { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 1.5px; opacity: .6; }
#payout-value { font-family: 'Lilita One', sans-serif; font-size: 34px; line-height: 1; color: var(--green); transition: transform .15s; }
#payout-value.neg { color: var(--red); }
#payout-value.bump { transform: scale(1.18); }
#job-sub { font-weight: 800; font-size: 13px; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.4); }

.pcard {
  position: absolute; top: 12px; left: 12px; width: 220px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 10px;
  box-shadow: var(--shadow); font-size: 13px; font-weight: 800;
}
.pcard.right { left: auto; right: 12px; }
.pcard .name { font-family: 'Lilita One', sans-serif; font-size: 17px; display: flex; justify-content: space-between; align-items: center; }
.pcard .bar { height: 12px; background: #e3d7c4; border-radius: 6px; overflow: hidden; margin: 5px 0 3px; border: 2px solid var(--ink); }
.pcard .bar > div { height: 100%; background: var(--green); transition: width .1s linear; }
.pcard .bar > div.low { background: var(--red); animation: blink .4s infinite alternate; }
.pcard .status { font-size: 12px; min-height: 16px; color: #6b4b3a; }
.pcard.waiting { opacity: .75; }
.pcard .join { font-size: 12px; color: #6b4b3a; }
.pcard .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 6px; vertical-align: -1px; }

@keyframes blink { from { opacity: 1; } to { opacity: .45; } }

#itemlist {
  position: absolute; left: 12px; bottom: 12px; width: 230px;
  background: rgba(255, 248, 236, .92); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 10px;
  font-size: 12px; font-weight: 800; box-shadow: var(--shadow);
}
#itemlist h4 { margin: 0 0 4px; font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 15px; }
#itemlist .row { display: flex; justify-content: space-between; gap: 6px; padding: 1px 0; }
#itemlist .row .st { opacity: .8; white-space: nowrap; }
#itemlist .row.done { color: var(--green); }
#itemlist .row.broken { color: var(--red); text-decoration: line-through; }
#itemlist .row.truck { color: #b86b12; }

#truckbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 12px; padding: 6px 14px;
  font-weight: 900; font-size: 13px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center;
}
#truckbar .hb { width: 120px; height: 12px; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; background: #e3d7c4; }
#truckbar .hb > div { height: 100%; background: var(--green); }
#truckbar .spd { font-family: 'Lilita One', sans-serif; font-size: 20px; min-width: 70px; text-align: right; }

#toasts {
  position: absolute; right: 12px; top: 120px; width: 300px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.toast {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 10px; padding: 5px 10px;
  font-weight: 800; font-size: 13px; box-shadow: 0 4px 0 rgba(0,0,0,.2);
  animation: toastIn .25s ease-out; max-width: 300px;
}
.toast.bad { background: #ffe1dc; }
.toast.med { background: #e3ecff; }
.toast.good { background: #dcf5e1; }
.toast.out { opacity: 0; transform: translateX(20px); transition: all .4s; }
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

#labels { position: absolute; inset: 0; }
.wlabel {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap; text-align: center;
  font-weight: 900; font-size: 12px; pointer-events: none;
}
.wlabel .tag {
  display: inline-block; padding: 1px 7px; border-radius: 8px; border: 2px solid var(--ink); color: #fff;
  font-family: 'Lilita One', sans-serif; font-size: 13px; letter-spacing: .5px;
}
.wlabel .prompt {
  display: block; margin-bottom: 3px; background: var(--paper); border: 2px solid var(--ink);
  border-radius: 8px; padding: 2px 8px; font-size: 12px;
}
.wlabel .prompt:empty { display: none; }
.wlabel .ko { display: block; font-size: 16px; }
.floaty {
  position: absolute; transform: translate(-50%, -50%); font-family: 'Lilita One', sans-serif;
  font-size: 22px; color: var(--red); -webkit-text-stroke: 1px #3a0d0b; pointer-events: none; white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.floaty.small { font-size: 15px; }

#hint {
  position: absolute; right: 12px; bottom: 12px; font-size: 12px; font-weight: 800; color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,.5);
}
#helppanel {
  position: absolute; right: 12px; bottom: 34px; width: 430px;
  background: rgba(255, 248, 236, .96); border: 3px solid var(--ink); border-radius: 12px; padding: 10px 12px;
  box-shadow: var(--shadow);
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(31, 26, 23, .45); padding: 16px; overflow-y: auto;
}
.panel {
  background: var(--paper); border: 4px solid var(--ink); border-radius: 20px; padding: 22px 26px;
  box-shadow: 0 10px 0 rgba(0,0,0,.3); max-width: 640px; width: 100%; text-align: center; margin: auto;
}
.panel.narrow { max-width: 460px; }
.panel h2 { font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 34px; margin: 0 0 12px; }
.logo {
  font-family: 'Lilita One', sans-serif; font-size: 52px; line-height: .95; color: var(--orange);
  -webkit-text-stroke: 2px var(--ink); text-shadow: 0 5px 0 var(--ink); letter-spacing: 1px;
}
.logo span { display: block; font-size: 28px; color: var(--blue); margin-top: 6px; }
.tag { font-weight: 800; font-size: 16px; margin: 14px 0 8px; }
.small { font-size: 12px; font-weight: 700; opacity: .7; margin: 10px 0 0; }
#save-info { font-weight: 800; font-size: 14px; margin-bottom: 10px; color: #6b4b3a; }

.btn {
  pointer-events: auto; font-family: 'Lilita One', sans-serif; font-size: 22px; padding: 10px 28px;
  background: var(--orange); color: #fff; border: 3px solid var(--ink); border-radius: 14px; cursor: pointer;
  box-shadow: 0 5px 0 var(--ink); margin: 6px; -webkit-text-stroke: .5px var(--ink);
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.btn.alt { background: #e9dcc6; color: var(--ink); -webkit-text-stroke: 0; font-size: 18px; }
#pause .btn { display: block; width: 100%; margin: 8px 0; }

.controls-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; margin: 14px 0;
  font-size: 13px; font-weight: 700;
}
.controls-grid.compact { font-size: 12px; margin-top: 16px; }
.controls-grid .col { background: #f3e8d6; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 10px; }
.controls-grid .col h4 { margin: 0 0 4px; font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 17px; }
.controls-grid .full { grid-column: 1 / -1; }
.controls-grid .kv { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
kbd {
  font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 11px; background: #fff; border: 2px solid var(--ink);
  border-bottom-width: 3px; border-radius: 6px; padding: 0 5px; white-space: nowrap;
}

.menu { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 6px 0 4px; }
.menu .btn { min-width: 300px; }
.join-row { display: flex; gap: 6px; align-items: center; }
.join-row .btn { min-width: 0; }
#code-input {
  font-family: 'Lilita One', sans-serif; font-size: 24px; width: 140px; text-align: center; letter-spacing: 4px;
  text-transform: uppercase; padding: 8px 6px; border: 3px solid var(--ink); border-radius: 12px; background: #fff;
}
.btn.blue { background: var(--blue); }
.btn:disabled { opacity: .55; cursor: wait; }
#net-status { font-weight: 800; font-size: 14px; min-height: 20px; margin-top: 4px; }
#net-status.err { color: var(--red); }
#pause-code { font-weight: 800; margin-bottom: 6px; }
.roomcode { font-family: 'Lilita One', sans-serif; font-size: 20px; letter-spacing: 3px; background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 0 8px; }
.pcard .join .roomcode { font-size: 18px; }
#banner {
  position: fixed; top: 46%; left: 50%; transform: translate(-50%, -50%);
  background: var(--paper); border: 4px solid var(--ink); border-radius: 16px; padding: 14px 26px;
  font-family: 'Lilita One', sans-serif; font-size: 26px; box-shadow: 0 8px 0 rgba(0,0,0,.3); text-align: center;
}
#banner small { display: block; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px; margin-top: 6px; }

#pc-lines { text-align: left; font-weight: 800; font-size: 14px; max-height: 42vh; overflow-y: auto; margin-bottom: 10px; }
#pc-lines .line { display: flex; justify-content: space-between; padding: 3px 2px; border-bottom: 1px dashed #c9b89e; }
#pc-lines .line.head { font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 16px; border: 0; margin-top: 8px; }
#pc-lines .line .neg { color: var(--red); }
#pc-lines .line.total { font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 24px; border-top: 3px solid var(--ink); border-bottom: 0; margin-top: 6px; }
#pc-review { background: #f3e8d6; border: 2px solid var(--ink); border-radius: 12px; padding: 10px; margin: 10px 0; }
#pc-review .stars { font-size: 30px; color: #f2b01e; -webkit-text-stroke: 1px var(--ink); letter-spacing: 2px; }
#pc-review .quote { font-style: italic; font-weight: 700; margin-top: 4px; }
#pc-review .who { font-size: 12px; opacity: .7; font-weight: 800; }
#pc-bank { font-weight: 900; font-size: 15px; margin-bottom: 6px; }

#loading, #error {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'Lilita One', sans-serif; font-size: 28px; color: #fff; background: #6fb7e8;
  text-shadow: 0 3px 0 rgba(0,0,0,.3); text-align: center; padding: 20px;
}
#error { background: #7a2b28; font-family: 'Nunito', sans-serif; font-size: 16px; white-space: pre-wrap; }

@media (max-width: 760px) {
  .pcard { width: 160px; font-size: 11px; }
  #itemlist { display: none; }
  #helppanel { width: calc(100% - 24px); }
  .logo { font-size: 38px; }
  .controls-grid { grid-template-columns: 1fr; }
  #toasts { width: 220px; }
}
