:root {
  --paper: #f6f1e3;
  --paper2: #ece4cc;
  --ink: #2a241b;
  --muted: #7a6f5c;
  --line: #c9bc98;
  --accent: #8b3a1a;
  --good: #2e7d32;
  --bad: #b3261e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font: 14px/1.4 Georgia, 'Times New Roman', serif; overflow: hidden; }
button, .button {
  font: inherit; font-size: 13px; padding: 4px 10px; border: 2px solid var(--ink); background: #fffaf0; color: var(--ink);
  border-radius: 3px; cursor: pointer; box-shadow: 2px 2px 0 var(--ink); display: inline-block;
}
button:hover:not(:disabled), .button:hover { background: #fff1c9; }
button:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: default; box-shadow: none; }
button.danger { border-color: var(--bad); color: var(--bad); box-shadow: 2px 2px 0 var(--bad); }
button.on { background: var(--ink); color: var(--paper); }
input, select, textarea { font: inherit; font-size: 13px; border: 1px solid var(--line); background: #fffdf6; padding: 3px 5px; border-radius: 2px; }
a { color: var(--accent); cursor: pointer; text-decoration: underline; }
h1, h2, h3, h4 { margin: .4em 0 .3em; font-weight: bold; }
h2 { font-size: 20px; } h3 { font-size: 15px; border-bottom: 1px solid var(--line); padding-bottom: 2px; margin-top: 14px; } h4 { font-size: 13px; color: var(--muted); margin: 10px 0 2px; }
small { color: var(--muted); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: normal; color: var(--muted); border-bottom: 1px solid var(--line); }
td, th { padding: 3px 4px; vertical-align: middle; }
tr.clickable:hover, .row.clickable:hover { background: var(--paper2); cursor: pointer; }
tr.me { background: #fff1c9; } tr.dead { opacity: .5; }
.good { color: var(--good); } .bad { color: var(--bad); }
.hint { color: var(--muted); font-style: italic; font-size: 13px; }
.chip { display: inline-block; width: 11px; height: 11px; border: 1px solid #222; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.chip.big { width: 16px; height: 16px; }
.badge { background: var(--bad); color: #fff; border-radius: 8px; padding: 0 5px; font-size: 11px; }

#app { display: flex; flex-direction: column; height: 100%; }
#topbar { display: flex; align-items: center; gap: 14px; padding: 6px 10px; border-bottom: 2px solid var(--ink); background: var(--paper2); flex-wrap: wrap; }
#topbar .nat { font-size: 16px; }
#topbar .year { font-size: 16px; }
#topbar .resources { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
#topbar .res { white-space: nowrap; cursor: default; }
#topbar .menu { display: flex; gap: 6px; }
#topbar .end { background: var(--accent); color: #fff; font-weight: bold; padding: 5px 16px; }
#topbar .end:hover { background: #a2471f; }
main { flex: 1; display: flex; min-height: 0; }
#mapwrap { flex: 1; position: relative; min-width: 0; }
#map { display: block; cursor: crosshair; }
#side { width: 420px; border-left: 2px solid var(--ink); display: flex; flex-direction: column; background: var(--paper); }
#tabs { display: flex; flex-wrap: wrap; gap: 3px; padding: 6px; border-bottom: 1px solid var(--line); }
.tab { box-shadow: none; padding: 3px 7px; font-size: 12px; border-width: 1px; }
.tab.on { background: var(--ink); color: var(--paper); }
#panel { overflow-y: auto; padding: 8px 12px 40px; flex: 1; }
#warhud { position: absolute; left: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; width: 250px; z-index: 5; }
#warhud .war { background: rgba(255, 250, 240, .94); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); padding: 5px 8px; cursor: pointer; font-size: 12.5px; }
#warhud .war:hover { background: #fff; }
#warhud .wtop { display: flex; gap: 6px; align-items: baseline; }
#warhud .wtop small { color: var(--muted); flex: 1; }
#warhud .wsides { display: flex; align-items: center; gap: 6px; margin: 3px 0 1px; }
#warhud .wsides .chip { margin-right: 1px; }
#warhud .wbar { flex: 1; height: 8px; background: #a4262c; border: 1px solid var(--ink); position: relative; }
#warhud .wbar i { position: absolute; left: 0; top: 0; bottom: 0; background: #2f7d4a; }
#warhud .wnames { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); }
#warhud .wnames small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 50%; }
#warhud .wsworn { color: #6b3d8f; }
#ticker { position: absolute; left: 10px; bottom: 10px; max-width: 55%; display: flex; flex-direction: column-reverse; gap: 2px; pointer-events: none; }
#ticker .tick { background: rgba(246, 241, 227, .9); border: 1px solid var(--line); padding: 2px 8px; font-size: 12.5px; pointer-events: auto; }
#tooltip { position: fixed; display: none; background: rgba(255, 252, 240, .97); border: 2px solid var(--ink); padding: 5px 8px; font-size: 12.5px; pointer-events: none; z-index: 20; max-width: 280px; }
.tick { padding: 2px 0; font-size: 13px; }
.tick[data-act] { cursor: pointer; }
.tick.mine { font-weight: bold; }
.tick.k-war::before { content: '⚔ '; } .tick.k-battle::before { content: '🗡 '; } .tick.k-conquest::before { content: '🏴 '; }
.tick.k-diplomacy::before { content: '📜 '; } .tick.k-tech::before { content: '💡 '; } .tick.k-colony::before { content: '⛵ '; }
.tick.k-legacy::before { content: '★ '; } .tick.k-economy::before { content: '🌾 '; } .tick.k-age::before { content: '⏳ '; } .tick.k-trade::before { content: '💰 '; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 2px 8px; font-size: 13px; margin: 6px 0; }
.kv > span:nth-child(odd) { color: var(--muted); }
.yields { background: var(--paper2); padding: 4px 8px; border-radius: 3px; margin: 6px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.card { display: flex; flex-direction: column; text-align: left; gap: 2px; padding: 6px 8px; box-shadow: 2px 2px 0 var(--ink); background: #fffaf0; border: 2px solid var(--ink); border-radius: 3px; }
.card small { font-size: 11.5px; }
.card span { font-size: 12px; }
.card.unit { grid-column: span 2; flex-direction: row; align-items: center; gap: 8px; }
.card.unit > div:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.card.tech.known { background: #e8f2df; opacity: .8; }
.card.tech.avail { background: #fffaf0; }
.card.tech.locked { background: #eee8d8; }
.card.tech.cur { outline: 3px solid var(--accent); }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; align-items: center; }
td.btns { margin: 0; gap: 3px; }
td.btns button { padding: 1px 6px; font-size: 12px; }
.filters button { padding: 2px 7px; font-size: 12px; box-shadow: none; border-width: 1px; }
.bar { display: inline-block; width: 140px; height: 9px; border: 1px solid var(--ink); background: #ddd; vertical-align: middle; }
.bar i { display: block; height: 100%; background: var(--accent); }
.row { display: flex; align-items: center; gap: 6px; padding: 3px 0; flex-wrap: wrap; }
.msg { border: 1px solid var(--line); padding: 6px 8px; margin: 6px 0; background: #fffdf6; }
.msg.open { border: 2px solid var(--accent); }
.msg p { margin: 4px 0; }
.preview { background: var(--paper2); padding: 4px 8px; margin: 6px 0; font-size: 12.5px; }
blockquote { margin: 6px 0; padding: 6px 10px; background: var(--paper2); font-style: italic; border-left: 3px solid var(--accent); }
.leader { display: flex; gap: 10px; align-items: flex-start; }
.leader h2 { margin-top: 0; }
.deal { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.deal label { display: flex; justify-content: space-between; gap: 4px; font-size: 12.5px; margin: 3px 0; align-items: center; }
.deal input[type=number] { width: 48px; }
.deal select { max-width: 84px; min-width: 0; }
.checks label { display: block; font-size: 13px; }
details { margin: 8px 0; background: var(--paper2); padding: 4px 8px; }
details .row { justify-content: space-between; font-size: 12.5px; padding: 1px 0; }
.chat { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); background: #fffdf6; padding: 6px; margin: 6px 0; }
.chat .line { margin: 4px 0; }
.chat .line.them { color: #3d2a12; }
.chat .line.you { color: #24466b; }
textarea { width: 100%; resize: vertical; }
.legacy { margin: 6px 0; }
.legacy .ms { display: flex; gap: 10px; font-size: 13px; }
.legacy .ms .done { color: var(--accent); font-weight: bold; }
canvas.mini { width: 40px; height: 40px; }

#start { position: fixed; inset: 0; background: var(--paper); z-index: 40; display: none; overflow-y: auto; padding: 30px; }
#start.show { display: block; }
#start .title { text-align: center; }
#start h1 { font-size: 44px; letter-spacing: 2px; margin: 10px 0; }
#start .btns { justify-content: center; }
.nations-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; max-width: 1200px; margin: 20px auto; }
.card.pick p { margin: 4px 0; font-size: 13px; }
.card.pick b { font-size: 17px; }
#modal { position: fixed; inset: 0; background: rgba(40, 30, 10, .45); display: none; align-items: center; justify-content: center; z-index: 50; }
#modal.show { display: flex; }
#modal .box { background: var(--paper); border: 3px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 14px 20px; max-width: 560px; width: 92%; max-height: 86vh; overflow-y: auto; }
#modal .box.wide { max-width: 760px; }
.options { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.options button { text-align: left; display: flex; flex-direction: column; padding: 8px 12px; }
.battle { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: flex; align-items: center; justify-content: center; z-index: 60; }
.battlebox { background: var(--paper); border: 3px solid var(--ink); padding: 10px 14px; box-shadow: 6px 6px 0 #000; }
.battlebox canvas { border: 1px solid var(--line); display: block; cursor: pointer; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 16px; border-radius: 4px; opacity: 0; transition: opacity .3s; z-index: 70; pointer-events: none; max-width: 80%; }
#toast.show { opacity: 1; }
code { background: var(--paper2); padding: 0 3px; }
.chart { margin: 4px 0 8px; }
.charttip { position: absolute; display: none; pointer-events: none; background: #fffdf6; border: 1px solid var(--ink); padding: 2px 6px; font-size: 12px; white-space: nowrap; }
.legend { position: absolute; right: 10px; bottom: 10px; background: rgba(246, 241, 227, .94); border: 2px solid var(--ink); padding: 6px 10px; font-size: 12.5px; display: none; }
.legend div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.pchips { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 4px; }
.pchip { background: #fffdf6; border: 1px solid var(--ink); border-radius: 3px; padding: 0 5px; font-size: 12px; }
.pchip a { text-decoration: none; color: var(--bad); margin-left: 2px; }
.legend .swatch { display: inline-block; width: 14px; height: 14px; border: 1px solid var(--ink); border-radius: 2px; }
.legend b { display: block; margin-bottom: 3px; }
img.ico { vertical-align: -3px; }
#topbar .vic { cursor: pointer; font-weight: bold; }
.bar.thin { width: 70px; height: 6px; margin-left: 4px; }
.techgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.techgrid h3 { font-size: 13px; }
.techgrid .card { margin-bottom: 6px; font-size: 12px; }
.card.tech b { font-size: 13px; }
.unitline { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.unitline canvas.mini { width: 30px; height: 30px; }
body.picking #topbar, body.picking #side { visibility: hidden; }
#start.show { display: block; }
#start { left: auto; width: 420px; border-left: 2px solid var(--ink); padding: 14px 18px; box-shadow: -4px 0 0 rgba(0,0,0,.08); }
#start h1 { font-size: 32px; margin: 4px 0 8px; }
#start .btns { justify-content: flex-start; }
.picklist { margin: 8px 0; border-top: 1px solid var(--line); }
.picklist .row { border-bottom: 1px solid var(--line); padding: 4px 2px; }
.picklist .row.on { background: #fff1c9; }
.picklist .sp { flex: 1; }
.pickcard { border: 2px solid var(--ink); background: #fffaf0; padding: 6px 10px; box-shadow: 3px 3px 0 var(--ink); margin: 8px 0; }
.pickcard h2 { margin: 2px 0; }
.pickcard p { margin: 4px 0; }
.tick.k-build::before { content: '🏠 '; }
#map { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

#home { position: fixed; inset: 0; background: var(--paper); z-index: 45; display: none; overflow-y: auto; padding: 40px 20px; }
#home.show { display: block; }
#home h1 { text-align: center; font-size: 44px; letter-spacing: 2px; margin: 10px 0 4px; }
#home .sub { text-align: center; color: var(--muted); margin: 0; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; max-width: 900px; margin: 30px auto; }
.mode { border: 2px solid var(--ink); background: #fffaf0; box-shadow: 4px 4px 0 var(--ink); padding: 14px 18px; }
.mode h2 { margin-top: 0; font-size: 24px; }
button.end { background: var(--accent); color: #fff; font-weight: bold; }
button.end:hover:not(:disabled) { background: #a2471f; }
button.big { font-size: 16px; padding: 8px 18px; }

/* Phones: map on top, panel below, compact top bar. */
@media (max-width: 800px) {
  #app { height: 100dvh; }
  #topbar { gap: 4px 8px; padding: 4px 6px; font-size: 12px; }
  #topbar .nat small, #topbar .year small { display: none; }
  #topbar .nat, #topbar .year { font-size: 13px; }
  #topbar .resources { gap: 6px; }
  #topbar .menu button { padding: 3px 7px; }
  main { flex-direction: column; }
  #mapwrap { flex: 1 1 55%; min-height: 0; }
  #side { width: auto; flex: 1 1 45%; min-height: 0; border-left: none; border-top: 2px solid var(--ink); }
  #ticker { display: none; }
  #warhud { width: 190px; left: 6px; top: 6px; }
  .legend { font-size: 11px; padding: 4px 6px; }
  #start { left: 0; top: auto; width: auto; height: 48dvh; padding: 8px 12px; border-left: none; border-top: 2px solid var(--ink); }
  #start h1 { font-size: 22px; margin: 0 0 4px; }
  input, select, textarea { font-size: 16px; }
  .deal { grid-template-columns: 1fr; }
  .techgrid { grid-template-columns: 1fr; }
  .battlebox { padding: 6px; max-width: 100%; }
  .battlebox canvas { width: 100%; height: auto; }
}
