:root {
  --paper: #efe6cf;
  --paper-2: #e4d8b8;
  --ink: #2b2a24;
  --ink-soft: #5d5747;
  --us: #2f5f9e;
  --jp: #b8322b;
  --space: #121a22;
  --typewriter: "Special Elite", "Courier New", monospace;
  --serif: "IM Fell English", "Iowan Old Style", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--space);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  overflow: hidden;
  background-color: var(--space);
  background-repeat: repeat, no-repeat;
  background-size: auto, cover;
}
#stage canvas { position: absolute; inset: 0; display: block; }
#stage canvas, #grain { pointer-events: none; }
#stage #units { pointer-events: auto; }
/* paper grain over the map, blended by the compositor (no per-frame drawing) */
#grain { position: absolute; inset: 0; mix-blend-mode: multiply; opacity: .55; }
#units { cursor: grab; }
#units.grabbing { cursor: grabbing; }
#units.pointer { cursor: pointer; }

.panel {
  position: fixed;
  background: var(--paper);
  background-image: linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0) 40%);
  border: 1px solid #b9a97f;
  box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 6px 18px rgba(0,0,0,.35);
  border-radius: 3px;
  padding: 10px 14px;
}

.eyebrow {
  font-family: var(--typewriter);
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

#title-card { top: 14px; left: 14px; min-width: 230px; }
#title-card h1 { margin: 2px 0 6px; font-size: 26px; font-weight: normal; letter-spacing: .02em; }

#clock { font-family: var(--typewriter); font-size: 14px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
#clock-time { font-size: 20px; }
#clock .zone { font-size: 11px; color: var(--ink-soft); }

#time-controls { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }

#sun {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed #b9a97f;
  font-family: var(--typewriter);
  font-size: 12px;
}
#sun-icon { width: 14px; height: 14px; border-radius: 50%; flex: none; background: #e9a23b; box-shadow: 0 0 0 2px rgba(233,162,59,.25); }
#sun-icon.twilight { background: linear-gradient(180deg, #e9a23b 50%, #4c4f7a 50%); }
#sun-icon.night { background: #2e3456; box-shadow: inset -4px -2px 0 0 #c9cde0; }
#sun-detail { color: var(--ink-soft); }
#zoom-controls button[aria-pressed="false"] { opacity: .55; }
button {
  font-family: var(--typewriter);
  font-size: 13px;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid #a8976b;
  border-radius: 2px;
  padding: 4px 8px;
  cursor: pointer;
  min-width: 34px;
}
button:hover { background: #f6eedb; }
button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button:focus-visible { outline: 2px solid var(--us); outline-offset: 1px; }

#forces { top: 14px; right: 14px; width: 250px; }
#force-list { list-style: none; margin: 6px 0 0; padding: 0; }
#force-list li { margin: 0; }
#force-list button {
  all: unset;
  display: grid;
  grid-template-columns: 12px 1fr;
  column-gap: 8px;
  width: 100%;
  padding: 5px 4px;
  border-radius: 2px;
  cursor: pointer;
  font-family: var(--serif);
}
#force-list button:hover { background: rgba(0,0,0,.06); }
#force-list button:focus-visible { outline: 2px solid var(--us); }
#force-list .swatch { width: 10px; height: 10px; margin-top: 5px; border: 1px solid rgba(0,0,0,.4); }
#force-list .swatch.us { background: var(--us); }
#force-list .swatch.jp { background: var(--jp); border-radius: 50%; }
#force-list .swatch.place { background: transparent; border-color: var(--ink); border-radius: 50%; }
#force-list .name { font-size: 16px; }
#force-list .sub { grid-column: 2; font-size: 12.5px; color: var(--ink-soft); font-style: italic; }

#info { left: 14px; top: 196px; width: 270px; max-height: calc(100% - 290px); overflow-y: auto; }
#info .eyebrow { padding-right: 22px; }
#info h2 { margin: 2px 0 2px; font-weight: normal; font-size: 22px; }
#info .cls { font-style: italic; color: var(--ink-soft); margin-bottom: 6px; }
#info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-size: 14px; }
#info dt { font-family: var(--typewriter); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); padding-top: 3px; }
#info dd { margin: 0; }
#info .close { position: absolute; top: 6px; right: 6px; min-width: 0; padding: 0 6px; }
#info.us { border-top: 4px solid var(--us); }
#info.jp { border-top: 4px solid var(--jp); }
#info .src { margin: 8px 0 0; font-size: 12.5px; font-style: italic; color: var(--ink-soft); }

#zoom-controls { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
#zoom-controls button { width: 36px; height: 36px; font-size: 18px; padding: 0; background: var(--paper); box-shadow: 0 3px 10px rgba(0,0,0,.3); }

#readout {
  position: fixed;
  left: 14px;
  bottom: 12px;
  font-family: var(--typewriter);
  font-size: 12px;
  color: #f1e9d4;
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
  pointer-events: none;
}
#scalebar { margin-bottom: 4px; }
#scalebar-bar { display: flex; height: 6px; border: 1px solid #f1e9d4; width: 100px; box-shadow: 0 1px 2px rgba(0,0,0,.6); }
#scalebar-bar span { flex: 1; background: #f1e9d4; }
#scalebar-bar span + span { background: rgba(0,0,0,.45); }
#scalebar-label { margin-top: 3px; }
#hint { opacity: .75; margin-top: 4px; }

#compass {
  position: fixed;
  right: 62px;
  bottom: 14px;
  width: 64px;
  height: 64px;
  color: #f1e9d4;
  font-family: var(--serif);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.7));
  pointer-events: none;
}
#compass text { fill: #f1e9d4; }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--typewriter);
  color: var(--paper);
  font-size: 18px;
  letter-spacing: .1em;
  pointer-events: none;
  transition: opacity .6s;
}
#loading.done { opacity: 0; }

@media (max-width: 720px) {
  #title-card { left: 8px; top: 8px; right: 8px; min-width: 0; padding: 8px 10px; }
  #title-card h1 { font-size: 20px; }
  #forces { top: auto; bottom: 64px; left: 8px; right: auto; width: auto; max-width: calc(100% - 70px); padding: 6px 8px; }
  #forces .eyebrow { display: none; }
  #force-list { display: flex; flex-wrap: wrap; gap: 2px 8px; margin: 0; }
  #force-list button { width: auto; }
  #force-list .sub { display: none; }
  #info { left: 8px; right: 8px; width: auto; top: 128px; bottom: auto; }
  #hint { display: none; }
  #compass { display: none; }
  #zoom-controls { right: 8px; bottom: 8px; }
  #readout { left: 8px; bottom: 8px; }
}
