:root {
  --bg: #10242c;
  --panel: #192e36;
  --line: #3d5155;
  --text: #eee9d9;
  --muted: #a9b9b8;
  --gold: #d9bd78;
  --red: #e88973;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", Helvetica, Arial, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
}
body { position: fixed; inset: 0; display: flex; flex-direction: column; }
button {
  font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer;
  touch-action: manipulation; min-width: 44px; min-height: 44px;
}
button:disabled { opacity: .4; cursor: default; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }
button:active:not(:disabled) { filter: brightness(1.2); }

#bar {
  display: grid; grid-template-columns: auto 1fr auto 44px; align-items: center; column-gap: 4px;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: linear-gradient(#203940, #172d35); border-bottom: 1px solid #8c8059;
  box-shadow: 0 2px 8px #07151a66; z-index: 2;
}
.chip {
  display: flex; align-items: center; justify-content: center; gap: 5px; padding: 0 7px;
  font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 0;
}
#year { font-family: Georgia, serif; font-size: 16px; }
#gold { color: var(--gold); flex-wrap: wrap; align-content: center; row-gap: 0; }
#happy { color: #ced8b8; }
#happy.bad, #gold.bad { color: #ffa08c; }
#sci {
  grid-column: 1 / -1; position: relative; justify-content: space-between; gap: 10px;
  border-top: 1px solid #ffffff0c; font-size: 12px; padding: 0 7px; isolation: isolate;
}
#sci .research-name { white-space: normal; text-align: left; }
#sci .research-turns { color: var(--muted); flex: none; }
#sci::after { content: ''; position: absolute; bottom: 0; left: 0; height: 2px; width: var(--progress, 0%); background: #96bdb3; }
#menu { font-size: 20px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c); box-shadow: 0 0 0 1px #ffffff66; }

#wrap { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; background: #10242c; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map-tools {
  position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: 12px;
  display: flex; border: 1px solid #84958b66; border-radius: 7px; background: #142b33eb;
  box-shadow: 0 2px 10px #06121766;
}
#map-tools button { padding: 0 10px; font-size: 21px; }
#map-tools button + button { border-left: 1px solid #84958b44; }
#map-tools #recenter { font-size: 12px; }
#map-tools #diplomacy { font-size: 12px; }
.advisor { color: #dccba5; font: 16px/1.5 Georgia, serif; margin: 6px 0 18px; }
.happiness-icon { width: 20px; height: 20px; flex: none; }
#toast button { border: 1px solid var(--line); border-radius: 5px; padding: 4px 14px; margin-top: 8px; color: var(--gold); }
#toast {
  position: absolute; left: 10px; right: 10px; top: 10px; padding: 10px 12px; border-radius: 7px;
  background: #142b33f5; border: 1px solid var(--line); font-size: 13px; max-height: 35%; overflow: auto;
  box-shadow: 0 3px 16px #07151a55;
}
#toast div + div { margin-top: 4px; }

#tray {
  position: relative;
  background: linear-gradient(#20363c, #152b33); border-top: 1px solid #8c8059;
  padding: 7px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 6px; box-shadow: 0 -2px 12px #07151a44;
  container: tray / inline-size;
}
#info { display: flex; align-items: center; gap: 10px; min-height: 40px; }
#info canvas { width: 40px; height: 40px; flex: none; background: #0f242b; border: 1px solid #7b8b7766; border-radius: 50%; }
#info .what { flex: 1; min-width: 0; }
#info .name { font-size: 16px; font-family: Georgia, serif; overflow-wrap: break-word; }
#info .stats { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#actions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: #8c8059 transparent; }
#actions:empty { display: none; }
#actions button, #turnrow button, .card button {
  min-height: 44px; padding: 8px 13px; border-radius: 6px; background: #2b444a; white-space: nowrap; flex: none;
  border: 1px solid #8c9b8a33;
}
#actions button { font-size: 12px; }
#turnrow { display: flex; gap: 8px; }
#turnrow #next { flex: 1; color: #c6d4d1; background: #213a41; }
#turnrow #end { flex: 2; }
.primary { background: linear-gradient(#ddc589, #bc9a56) !important; color: #1b292b; font-weight: 650; border-color: #eddbac88 !important; }
.danger { background: #743f36 !important; }
@container tray (min-width: 680px) {
  #info { max-width: 360px; }
  #actions { position: absolute; left: 390px; right: 16px; margin-top: 0; }
  #turnrow { margin-top: 2px; }
  #turnrow #next { flex: 3; }
}

dialog {
  border: 1px solid #8c8059; border-bottom: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 88dvh; background: var(--panel); color: var(--text); border-radius: 14px 14px 0 0; overflow: auto;
  box-shadow: 0 -12px 70px #06151b66; scrollbar-color: #607877 transparent;
  scroll-padding-block: 76px 16px;
}
dialog::backdrop { background: #06151ba6; }
.card { padding: 18px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.card h2 { position: sticky; top: 0; z-index: 1; background: var(--panel); padding-bottom: 8px; margin: 0 0 14px; font: 23px/1.25 Georgia, serif; display: flex; align-items: center; gap: 8px; }
.card h3 { margin: 18px 0 8px; font-size: 11px; color: #b7c7c0; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.row { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 0; border-bottom: 1px solid #ffffff0c; font-variant-numeric: tabular-nums; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: break-word; }
.row .num { color: var(--muted); white-space: nowrap; }
.row.pick { width: 100%; text-align: left; border-radius: 0; background: none !important; height: auto; padding: 9px 0; border-width: 0 0 1px; }
.row.on { color: var(--gold); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.row input[type=number] { width: 84px; min-height: 44px; font-size: 16px; border-radius: 6px; border: 1px solid var(--line); background: #10242c; color: inherit; padding: 0 8px; }
.stepper span { min-width: 48px; text-align: center; align-self: center; font-size: 18px; font-variant-numeric: tabular-nums; }
.seg button.on { background: #c8af72; color: #142830; border-color: #eddbac88; }
.bar { height: 5px; background: #0c2229; border-radius: 3px; overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; background: var(--gold); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { padding: 4px 8px; border-radius: 4px; background: #2b444a; font-size: 12px; }
.muted { color: var(--muted); }
.row > .row { border-bottom: 0; }
.card button.mini { min-width: 44px; padding: 0; }
.card .row.pick .num { white-space: normal; text-align: right; max-width: 62%; font-size: 12px; }
#start { flex: 1; }
@media (max-height: 480px) and (min-width: 600px) {
  #bar { grid-template-columns: auto auto auto 1fr 44px; }
  #sci { grid-column: 4; grid-row: 1; border-top: 0; }
  #menu { grid-column: 5; grid-row: 1; }
  #tray { position: relative; padding-top: 5px; gap: 4px; }
  #info { position: absolute; left: 12px; width: 215px; top: 8px; }
  #info .stats { white-space: normal; }
  #actions { position: static; }
  #actions, #turnrow { margin-left: 228px; }
  #map-tools { bottom: 8px; }
}
.card button.dismiss { margin-left: auto; padding: 0; min-width: 44px; background: var(--panel); border: 0; font: 25px/1 sans-serif; color: var(--muted); }
.card h2 canvas { width: 36px; height: 36px; }
.city-yields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.city-yields > div { background: #10242c; border-radius: 5px; padding: 8px 4px; text-align: center; }
.city-yields span { display: block; font-size: 10px; color: var(--muted); }
.city-yields strong { display: block; font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
.row[data-queue] { display: grid; grid-template-columns: repeat(3, 44px) 1fr; gap: 5px; }
.row[data-queue] .grow { grid-column: 1 / 4; }
.row[data-queue] .num { grid-column: 4; text-align: right; }
.row[data-queue] button { min-height: 44px; }
