:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --panel-2: #1e2229;
  --line: #2a2f38;
  --text: #e8eaed;
  --muted: #8b929c;
  --ok: #3fb950;
  --warn: #e3b341;
  --err: #f85149;
  --age1: #9aa0a8;   /* Dark: grey */
  --age2: #3fb950;   /* Feudal: green */
  --age3: #4c8dff;   /* Castle: blue */
  --age4: #a371f7;   /* Imperial: purple */
  --accent: var(--age1);
}
body[data-age="2"] { --accent: var(--age2); }
body[data-age="3"] { --accent: var(--age3); }
body[data-age="4"] { --accent: var(--age4); }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 20px/1.35 "Segoe UI", system-ui, -apple-system, sans-serif;
  height: 100vh; overflow: hidden; display: flex; flex-direction: column;   /* always one screen */
}
button, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
a { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px; background: var(--panel);
  border-bottom: 4px solid var(--accent);
}
.age-block { display: flex; align-items: center; gap: 16px; }
.badge {
  min-width: 72px; height: 72px; padding: 0 12px; border-radius: 14px; display: grid; place-items: center;
  font: 800 40px/1 Georgia, serif; color: #0e1013; background: var(--accent);
}
.age-name { font-size: 40px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.age-time { font-size: 20px; color: var(--muted); }
.mid { display: flex; align-items: center; gap: 16px; }
.clock { font: 700 36px/1 Consolas, monospace; color: var(--text); }
.soon { font-size: 20px; font-weight: 700; color: var(--warn); border: 2px solid var(--warn); padding: 4px 10px; border-radius: 8px; }
.popc { font: 700 24px/1 Consolas, monospace; color: var(--muted); }
.late { font-size: 20px; font-weight: 700; color: var(--err); border: 2px solid var(--err); padding: 4px 10px; border-radius: 8px; }
.controls { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.age-buttons { display: flex; gap: 4px; }
.age-buttons button { min-width: 48px; font-weight: 700; }
.age-buttons button[data-age="1"].on { background: var(--age1); color: #000; }
.age-buttons button[data-age="2"].on { background: var(--age2); color: #000; }
.age-buttons button[data-age="3"].on { background: var(--age3); color: #000; }
.age-buttons button[data-age="4"].on { background: var(--age4); color: #000; }
#btn-auto.on { background: var(--text); color: #000; }
.mode { font-size: 14px; color: var(--muted); }
.mode .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.mode .dot.live { background: var(--ok); }
.mode .dot.manual { background: var(--warn); }

.status { padding: 0 20px; }
.status div { margin-top: 8px; padding: 8px 12px; border-radius: 8px; font-size: 17px; }
.status .info { background: #1b2430; color: #a9c1dd; }
.status .warn { background: #2e2713; color: var(--warn); }
.status .error { background: #341716; color: #ffb4ad; font-weight: 700; }

/* ---------- page ---------- */
main {
  flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 16px 20px; display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-content: start;
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card h2 {
  margin: 0 0 10px; font-size: 16px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent);
}
ul.items { list-style: none; margin: 0; padding: 0; }
ul.items li {
  display: flex; gap: 12px; align-items: flex-start; padding: 7px 4px; border-radius: 8px; cursor: pointer;
  user-select: none;
}
ul.items li:hover { background: var(--panel-2); }
.box {
  flex: none; width: 26px; height: 26px; margin-top: 2px; border-radius: 6px; border: 2px solid var(--muted);
  display: grid; place-items: center; font-size: 18px; font-weight: 900; color: #000;
}
li.done .box { background: var(--accent); border-color: var(--accent); }
li.done .box::after { content: "✓"; }
li.done .txt { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(255,255,255,.25); }
.txt { flex: 1; }
li.next { background: var(--panel-2); box-shadow: inset 4px 0 0 var(--accent); }
li.next .box { border-color: var(--accent); }
.key { font: 700 13px Consolas, monospace; color: #000; background: var(--accent); border-radius: 5px; padding: 1px 6px; margin-left: 8px; white-space: nowrap; }
li.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { background: var(--accent); } 100% { background: transparent; } }
.hotkeys { padding: 8px 20px 0; font-size: 15px; color: var(--muted); }
.hotkeys b { color: var(--text); font-family: Consolas, monospace; }
.tag { font-size: 14px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 6px; white-space: nowrap; }
.tag.auto { color: var(--accent); border-color: var(--accent); }
.live { font: 700 16px Consolas, monospace; margin-left: 6px; white-space: nowrap; }
.live.met { color: var(--ok); }
.live.unmet { color: var(--warn); }
ul.notes { margin: 0; padding-left: 20px; color: #c9cdd3; }
ul.notes li { margin: 6px 0; }
ul.notes.hints { color: inherit; }
.next { font-size: 19px; }

/* carry forward: fills whatever height the age page leaves, scrolls inside itself if it must */
.carry { flex: 1 1 0; min-height: 130px; overflow-y: auto; margin: 0 20px 12px; padding: 10px 14px; border-color: var(--warn); }
.carry h2 { color: var(--warn); margin-bottom: 6px; }
.carry-grid { column-width: 270px; column-gap: 24px; }
.carry-age { margin-bottom: 6px; }
.carry h3 { margin: 0 0 2px; font-size: 14px; color: var(--muted); font-weight: 600; break-after: avoid; }
.carry ul.items li { padding: 2px 4px; gap: 8px; font-size: 16px; line-height: 1.25; break-inside: avoid; }
.carry .box { width: 18px; height: 18px; margin-top: 1px; border-width: 1.5px; border-radius: 4px; font-size: 13px; }
.carry .tag { font-size: 12px; }
.carry .live { font-size: 13px; }
.carry-empty { color: var(--muted); font-size: 16px; }

/* split target */
.split { margin-top: 12px; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.split-label { font-size: 15px; color: var(--muted); margin-bottom: 8px; }
.split-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; }
.res { text-align: center; border-radius: 8px; padding: 6px 4px; background: var(--panel); border: 2px solid var(--line); }
.res.met { border-color: var(--ok); }
.res .name { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.res .nums { font: 700 24px Consolas, monospace; }
.res .nums small { font-size: 16px; color: var(--muted); }
.res.food .name { color: #ff7b72; } .res.wood .name { color: #7ee787; }
.res.gold .name { color: #e3b341; } .res.stone .name { color: #c9d1d9; }
.idle { margin-top: 8px; font-size: 16px; color: var(--muted); }
.idle.bad { color: var(--err); font-weight: 700; }

footer {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 20px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 15px;
}
footer select, footer button { font-size: 14px; padding: 4px 10px; }
.keys { margin-left: auto; }
.conn.ok { color: var(--ok); } .conn.bad { color: var(--err); }

@media (max-width: 600px) {
  body { font-size: 17px; height: auto; overflow: visible; }
  main { overflow: visible; }
  .carry { flex: none; margin-left: 16px; margin-right: 16px; }
  header, main, footer, .status { padding-left: 16px; padding-right: 16px; }
  .age-name { font-size: 28px; }
  .badge { min-width: 56px; height: 56px; font-size: 30px; }
  main { grid-template-columns: 1fr; }
  .keys { display: none; }
}
