/* "Bureau" art direction: a sheet of graph paper on a wooden desk, ink, markers and sticky notes. */
:root {
  color-scheme: light;
  --paper: #fbf8ef;
  --paper-2: #fffdf6;
  --grid: rgba(70, 130, 200, 0.18);
  --ink: #22305a;
  --ink-soft: rgba(34, 48, 90, 0.55);
  --muted: #5b6487;
  --red: #d7263d;
  --green: #2f855a;
  --gold: #b45309;
  --sticky: #ffe66d;
  --wood: #a9764a;
  --wood-dark: #8b5a2b;
  --ruler: #e9c46a;
  --highlight: #fff176;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  --script: "Caveat", "Patrick Hand", cursive;
  --marker: "Permanent Marker", "Patrick Hand", cursive;
  font-family: var(--hand);
  font-size: 17px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background-color: var(--wood);
  background-image: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 3px, transparent 3px 41px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 13px);
}
.hidden { display: none !important; }
h1 { margin: 0; font-family: var(--marker); font-weight: 400; letter-spacing: 0.02em; }
small, .muted { color: var(--muted); font-size: 0.85rem; }
kbd { font-family: var(--hand); font-size: 0.8rem; color: var(--muted); }
button {
  background: var(--paper-2); color: var(--ink); border: 1.5px solid var(--ink); border-radius: 6px;
  padding: 5px 10px; font: inherit; font-size: 1rem; cursor: pointer;
}
button:hover:not(:disabled) { background: #fff9d6; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.active { background: var(--highlight); }
.cta { background: var(--sticky); font-weight: 700; box-shadow: 2px 3px 0 var(--ink); }
.cta.big { height: 52px; font-size: 1.15rem; border-radius: 10px; }
input {
  background: transparent; border: none; border-bottom: 2px solid var(--ink); color: var(--ink);
  padding: 6px 2px; font: inherit; font-size: 1.1rem; width: 100%;
}
input:focus { outline: none; border-bottom-color: var(--red); }
.row { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.error { color: var(--red); margin: 0; min-height: 1.2em; }
.hint { color: var(--muted); margin: 0; text-align: center; }
.hint.left { text-align: left; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; border: 1.5px solid var(--ink); }
.tag { font-size: 0.85rem; color: var(--muted); }
.bonus { color: var(--green); }
.malus { color: var(--red); font-weight: 700; }
.gold-text { color: var(--gold); font-family: var(--marker); }

/* paper surfaces */
.card {
  position: relative; background: var(--paper-2); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 2px 6px 12px rgba(60, 40, 0, 0.22);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.eyebrow { font-family: var(--script); font-weight: 700; font-size: 1.6rem; line-height: 1; }
.eyebrow.teal { color: var(--red); }
.postit { background: var(--sticky); transform: rotate(-1.2deg); }
.postit::before {
  content: ""; position: absolute; left: 38%; top: -11px; width: 84px; height: 22px;
  background: rgba(255, 255, 255, 0.55); transform: rotate(3deg);
}
.index-card {
  background-color: #fff;
  background-image: linear-gradient(#e88 0 0), repeating-linear-gradient(transparent 0 23px, rgba(70, 130, 200, 0.3) 23px 24px);
  background-size: 100% 2px, 100% 100%; background-position: 0 40px, 0 40px; background-repeat: no-repeat, repeat;
  transform: rotate(0.8deg);
}
.scrap { transform: rotate(-0.6deg); }
.notebook {
  background-color: #fff;
  background-image: linear-gradient(90deg, transparent 26px, rgba(215, 38, 61, 0.45) 26px 28px, transparent 28px),
    repeating-linear-gradient(transparent 0 25px, rgba(70, 130, 200, 0.28) 25px 26px);
  padding-left: 36px;
}

/* join and lobby */
.screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100%; padding: 16px; gap: 14px; }
.screen h1 { color: var(--paper); font-size: 2.6rem; text-shadow: 2px 3px 0 rgba(0, 0, 0, 0.3); }
.subtitle { color: var(--paper); margin: 0; text-align: center; font-size: 1.15rem; }
.card.form { width: min(380px, 100%); padding: 22px; background: var(--sticky); transform: rotate(-1deg); }
label { display: flex; flex-direction: column; gap: 2px; font-size: 1rem; color: var(--muted); }
#lobby-players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#lobby-players li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--ink-soft); font-size: 1.1rem; }
#lobby-players li .name { flex: 1; }
#lobby-players li button { padding: 0 8px; }
.lang-toggle { font-family: var(--marker); padding: 3px 10px; }

/* game shell */
#game { display: grid; grid-template-columns: 290px 92px minmax(0, 1fr) 340px; grid-template-rows: 58px minmax(0, 1fr); height: 100dvh; }
#topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 18px; padding: 10px 16px 0; min-width: 0;
  margin: 6px 10px 0; border-radius: 4px; background-color: var(--ruler);
  background-image: repeating-linear-gradient(90deg, rgba(60, 40, 10, 0.6) 0 1px, transparent 1px 10px),
    repeating-linear-gradient(90deg, rgba(60, 40, 10, 0.7) 0 1px, transparent 1px 50px);
  background-size: 100% 9px, 100% 15px; background-repeat: repeat-x; box-shadow: 0 4px 10px rgba(40, 20, 0, 0.35);
}
.brand { font-family: var(--marker); font-size: 1.3rem; color: #3a2a12; }
.stats { display: flex; align-items: center; gap: 16px; }
.stat { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; color: #3a2a12; }
.stat .label { font-size: 1rem; }
.stat .value { font-family: var(--marker); font-size: 1.6rem; color: var(--gold); }
.stat .unit-label { font-size: 0.9rem; }
.stat.gold .unit-label { display: none; }
.stat.mobile-only { display: none; }
.pills { flex: 1; display: none; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.pill { flex: none; height: 30px; padding: 0 10px; border-radius: 6px 6px 0 0; border: 1.5px solid var(--ink); border-bottom: 3px solid var(--pill); background: var(--paper-2); font-size: 0.95rem; display: flex; align-items: center; gap: 4px; }
.pill.focused { background: var(--highlight); }
.pill.dead { opacity: 0.4; text-decoration: line-through; }
.pill .role { font-size: 0.75rem; color: var(--muted); }
.top-actions { display: flex; gap: 8px; margin-left: auto; }
.top-actions button { background: var(--paper-2); }

.column { display: flex; flex-direction: column; gap: 16px; padding: 18px 14px; overflow-y: auto; min-height: 0; }
#left { grid-column: 1; grid-row: 2; }
#right { grid-column: 4; grid-row: 2; }
.sheet-handle { display: none; }

/* leaderboard post-it with my income and lives */
.income { display: flex; flex-direction: column; gap: 3px; }
.income .line { display: flex; justify-content: space-between; font-size: 1rem; }
.income .line b { font-family: var(--marker); font-weight: 400; color: var(--gold); }
.bar { height: 7px; border: 1.5px solid var(--ink); border-radius: 4px; overflow: hidden; background: var(--paper-2); }
.bar > span { display: block; height: 100%; background: var(--green); }
#my-status { font-family: var(--marker); color: var(--red); }
#scoreboard { width: 100%; border-collapse: collapse; font-size: 1rem; }
#scoreboard td { padding: 2px 2px; border-bottom: 1px dashed rgba(34, 48, 90, 0.25); }
#scoreboard tr { cursor: pointer; }
#scoreboard tr.dead { opacity: 0.5; text-decoration: line-through; }
#scoreboard tr.me td { color: var(--red); font-weight: 700; }
#scoreboard td.num { text-align: right; white-space: nowrap; }
#scoreboard td:nth-child(2) { white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
#minimap { width: 100%; height: 150px; display: block; cursor: pointer; }
#feed { display: flex; flex-direction: column; gap: 2px; font-size: 0.95rem; min-height: 40px; }
#feed .Warn { color: var(--gold); }
#feed .Error { color: var(--red); }
#feed .Info { color: var(--green); }
#chat-form input { font-size: 1rem; }

/* build palette: stickers */
#palette { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; gap: 8px; padding: 18px 6px; overflow-y: auto; }
#palette button {
  width: 78px; min-height: 70px; padding: 4px 2px; border-style: dashed; border-radius: 8px; background: rgba(255, 253, 246, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#palette button:nth-child(odd) { transform: rotate(-1deg); }
#palette button:nth-child(even) { transform: rotate(1deg); }
#palette button.active { background: var(--highlight); border-style: solid; }
#palette .swatch { width: 20px; height: 20px; border: 1.5px solid var(--ink); border-radius: 3px; }
#palette .name { font-size: 0.95rem; }
#palette .cost { font-size: 0.8rem; color: var(--gold); }

#board-wrap { grid-column: 3; grid-row: 2; position: relative; min-width: 0; min-height: 0; margin: 12px 4px 12px 0; box-shadow: 0 10px 30px rgba(40, 20, 0, 0.35); }
#board { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.lane-hint { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); font-size: 0.95rem; color: var(--muted); pointer-events: none; white-space: nowrap; }
.tower-card { position: absolute; left: 8px; top: 8px; width: 250px; z-index: 5; transform: rotate(-0.8deg); background: var(--paper-2); border: 1.5px solid var(--ink); }
.tower-card .row button { flex: 1; min-height: 40px; }
.pips { letter-spacing: 2px; color: var(--red); }
#radial { position: absolute; inset: 0; pointer-events: none; }
#radial button {
  position: absolute; pointer-events: auto; width: 54px; height: 54px; border-radius: 50%; border: 2px solid var(--ink);
  font-family: var(--marker); font-size: 0.8rem; padding: 0; box-shadow: 2px 3px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
#radial button span { font-family: var(--hand); font-size: 0.7rem; }

/* right column: clipboard */
#right { background: var(--wood-dark); margin: 12px 10px 12px 0; border-radius: 14px; padding: 30px 12px 12px; box-shadow: 0 8px 18px rgba(40, 20, 0, 0.4); position: relative; }
#right::before { content: ""; position: absolute; left: calc(50% - 50px); top: 6px; width: 100px; height: 22px; border-radius: 6px; background: #c0c4cc; box-shadow: inset 0 -4px 0 #8a8f99; }
#right .card { box-shadow: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 0 8px; border: 1.5px solid var(--ink-soft); border-radius: 12px; font-size: 0.9rem; }
.chip.good { border-color: var(--red); color: var(--red); }
.segmented { display: inline-flex; gap: 6px; }
.segmented button { border-radius: 14px; padding: 1px 12px; }
.segmented button.active { border-color: var(--red); color: var(--red); background: transparent; border-width: 2px; }

.unit-list { display: flex; flex-direction: column; }
.unit {
  position: relative; display: grid; grid-template-columns: 14px minmax(0, 1fr) auto 14px; gap: 8px; align-items: center;
  text-align: left; padding: 4px 4px; border: none; border-bottom: 1px solid rgba(70, 130, 200, 0.35); border-radius: 0; background: transparent;
}
.unit .swatch { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--ink); }
.unit .title { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit .badge { font-family: var(--script); font-weight: 700; font-size: 1rem; color: var(--red); margin-left: 4px; }
.unit .income-tag { display: block; font-size: 0.85rem; }
.unit .why { display: none; font-size: 0.85rem; color: var(--muted); }
.unit .cost { padding: 0 6px; background: var(--sticky); transform: rotate(-3deg); font-size: 0.95rem; }
.unit .key { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; }
.unit.best .why { display: block; }
.unit.best::after { content: ""; position: absolute; left: -6px; right: 34px; top: -3px; bottom: -3px; border: 2px solid var(--red); border-radius: 50%; transform: rotate(-1.5deg); pointer-events: none; }
.unit.selected { background: var(--highlight); }
#send-cta { display: none; }

/* research notebook */
.research-summary { margin: 0; font-size: 0.95rem; color: var(--green); }
.research-list { display: flex; flex-direction: column; gap: 4px; }
.research-list button {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  text-align: left; padding: 4px 6px; border: 1.5px dashed var(--ink-soft); background: rgba(255, 255, 255, 0.6);
}
.research-list .icon { grid-row: 1 / 3; font-size: 1.3rem; color: var(--red); text-align: center; }
.research-list .name { font-size: 1.05rem; }
.research-list .pips { font-size: 1rem; text-align: right; }
.research-list .effect { grid-column: 2 / 4; font-size: 0.85rem; color: var(--muted); }
.research-list .effect b { color: var(--ink); font-weight: 400; }
.research-list .effect .next { color: var(--gold); }
.research-list button.owned { border-style: solid; border-color: var(--ink); }
.research-list button.suggested { border-color: var(--red); border-width: 2px; }

#mobile-bar, #sheet-backdrop { display: none; }
#overlay { position: fixed; inset: 0; background: rgba(40, 25, 10, 0.45); display: flex; align-items: center; justify-content: center; z-index: 40; }
#overlay .card { align-items: center; text-align: center; padding: 24px 28px; background: var(--sticky); transform: rotate(-1deg); }
#overlay ol { text-align: left; margin: 0; font-size: 1.1rem; }
#overlay.passive { background: transparent; pointer-events: none; }
.countdown { font-family: var(--marker); font-size: 5rem; color: var(--red); text-shadow: 2px 3px 0 rgba(0, 0, 0, 0.15); }

@media (max-width: 1200px) {
  #game { grid-template-columns: 240px 86px minmax(0, 1fr) 300px; }
  .top-actions kbd { display: none; }
}

/* phones */
@media (max-width: 800px) {
  :root { font-size: 16px; }
  #game { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
  #topbar { flex-wrap: wrap; gap: 8px; padding: 12px 10px 6px; margin: 4px 6px 0; }
  .brand, #overview-toggle, kbd, .desktop-only { display: none; }
  .stats { flex: 1; gap: 10px; }
  .stat .label { display: none; }
  .stat .value { font-size: 1.3rem; }
  .stat.gold .unit-label, .stat.lives .unit-label { display: inline; }
  .stat.mobile-only { display: flex; }
  .pills { display: flex; order: 3; flex-basis: 100%; }
  .top-actions { margin-left: 0; }
  #left, #right, #palette { display: none; }
  #board-wrap { grid-column: 1; grid-row: 2; margin: 8px 6px; }
  #mobile-bar { display: flex; grid-row: 3; gap: 8px; padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  #mobile-bar .tab { flex: 1; height: 56px; font-size: 1.15rem; border-style: dashed; background: var(--paper-2); }
  #mobile-bar .tab.send { background: var(--sticky); border-style: solid; box-shadow: 2px 3px 0 var(--ink); }

  body.sheet-send #right, body.sheet-research #right, body.sheet-players #left {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; max-height: 78dvh; z-index: 30; margin: 0;
    border-radius: 18px 18px 0 0; padding: 30px 12px calc(14px + env(safe-area-inset-bottom));
  }
  body.sheet-players #left { background: var(--wood-dark); }
  body.sheet-send #right > section:not(#attack),
  body.sheet-research #right > section:not(#research) { display: none; }
  body.sheet-tower .tower-card { position: fixed; left: 8px; right: 8px; top: auto; bottom: 12px; width: auto; z-index: 30; transform: none; }
  body[class*="sheet-"] #sheet-backdrop { display: block; position: fixed; inset: 0; background: rgba(40, 25, 10, 0.45); z-index: 25; }
  .unit-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .unit { grid-template-columns: 14px minmax(0, 1fr) auto; min-height: 60px; border: 1.5px dashed var(--ink-soft); border-radius: 8px; }
  .unit .key { display: none; }
  .unit.best::after { right: -4px; }
  #send-cta { display: block; height: 56px; position: sticky; bottom: 0; z-index: 1; flex: none; }
  .research-list button { min-height: 52px; }
  #minimap { height: 130px; }
}
