/*
 * Earthward map viewer — Europa Universalis' lacquer-and-gilt interface redrawn as flat vector
 * shapes: chamfered plates, hairline gilt frames, octagonal map-mode buttons.
 */
:root {
  --ink: #141922;
  --ink-2: #1b2230;
  --lacquer: #1a2a42;
  --lacquer-2: #22385a;
  --gilt: #c9a44c;
  --gilt-hi: #e8d39a;
  --gilt-line: rgba(201, 164, 76, 0.62);
  --gilt-faint: rgba(201, 164, 76, 0.22);
  --vellum: #efe7d4;
  --vellum-2: #d9cfb8;
  --muted: #9c9687;
  --crimson: #a33a2f;
  --sea: #8fb6d6;
  --serif-ko: 'Noto Serif KR', 'Nanum Myeongjo', 'AppleMyungjo', serif;
  --serif-en: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --c: 10px;
  --cham: polygon(var(--c) 0, calc(100% - var(--c)) 0, 100% var(--c), 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, var(--c) 100%, 0 calc(100% - var(--c)), 0 var(--c));
  --oct: polygon(29% 0, 71% 0, 100% 29%, 100% 71%, 71% 100%, 29% 100%, 0 71%, 0 29%);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0c111a;
  color: var(--vellum);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

#map,
#labels {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#map {
  cursor: default;
  touch-action: none;
}

#map.grabbing {
  cursor: grabbing;
}

#labels {
  pointer-events: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--gilt-hi);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ panel frame */
.panel {
  position: relative;
  padding: 1px;
  background: var(--gilt-line);
  clip-path: var(--cham);
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45));
}

.panel-body {
  position: relative;
  clip-path: var(--cham);
  background:
    linear-gradient(180deg, rgba(34, 56, 90, 0.35), rgba(20, 25, 34, 0) 90px),
    var(--ink);
  box-shadow:
    inset 0 0 0 3px var(--ink),
    inset 0 0 0 4px var(--gilt-faint);
}

/* ------------------------------------------------------------------ top bar */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: linear-gradient(180deg, #1c2638, #141922);
  border-bottom: 1px solid var(--gilt-line);
  box-shadow:
    0 1px 0 #0a0d13,
    0 3px 0 rgba(201, 164, 76, 0.18),
    0 10px 24px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: none;
}

.bm-plate {
  fill: var(--lacquer);
  stroke: var(--gilt);
  stroke-width: 1.5;
}

.bm-needle {
  fill: var(--gilt);
}

.bm-cross {
  fill: rgba(232, 211, 154, 0.35);
}

.bm-hub {
  fill: var(--ink);
  stroke: var(--gilt-hi);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}

.brand-name {
  font: 600 24px/1 var(--serif-en);
  letter-spacing: 0.04em;
  color: var(--gilt-hi);
}

.brand-sub {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

/* Scenario dial — the six start dates as one gilt-rimmed strip */
.scenarios {
  display: flex;
  padding: 1px;
  background: var(--gilt-line);
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 14px 100%, 0 50%);
}

.scenario {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 42px;
  border: 0;
  background: var(--ink-2);
  cursor: pointer;
  padding: 0 4px;
  transition: background 120ms;
}

.scenario:first-child {
  padding-left: 12px;
  width: 98px;
}

.scenario:last-child {
  padding-right: 12px;
  width: 98px;
}

.scenario + .scenario {
  margin-left: 1px;
}

.scenario .year {
  font: 600 19px/1 var(--serif-en);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--vellum);
}

.scenario .event {
  font-size: 10.5px;
  line-height: 1.2;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.scenario:hover {
  background: #232d3f;
}

.scenario[aria-pressed='true'] {
  background: linear-gradient(180deg, #e3c77d, var(--gilt) 60%, #a8863a);
}

.scenario[aria-pressed='true'] .year {
  color: #1a1408;
}

.scenario[aria-pressed='true'] .event {
  color: #3a2c10;
}

.tools {
  position: relative;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  width: min(280px, 24vw);
  padding: 0 10px;
  background: #0f141c;
  border: 1px solid var(--gilt-faint);
}

.search:focus-within {
  border-color: var(--gilt-line);
}

.search svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}

.search input::placeholder {
  color: #6f6a5f;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: -1px;
  width: 340px;
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--ink);
  border: 1px solid var(--gilt-line);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
}

.search-results li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 7px 9px;
  cursor: pointer;
}

.search-results li[aria-selected='true'],
.search-results li:hover {
  background: var(--lacquer);
}

.search-results .r-name {
  font-family: var(--serif-ko);
  font-weight: 600;
}

.search-results .r-en {
  grid-column: 1;
  font: italic 500 13px/1.2 var(--serif-en);
  color: var(--muted);
}

.search-results .r-kind {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-size: 11px;
  color: var(--gilt);
}

.tool-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #0f141c;
  border: 1px solid var(--gilt-faint);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--vellum-2);
}

.tool-btn:hover {
  border-color: var(--gilt-line);
  color: var(--vellum);
}

.tool-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.settings {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 250px;
}

.settings .panel-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  font-size: 13px;
}

.settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.settings input {
  accent-color: var(--gilt);
}

/* ------------------------------------------------------------------ inspector */
.inspector {
  position: fixed;
  top: 72px;
  left: 14px;
  width: 372px;
  max-height: calc(100vh - 88px);
  z-index: 8;
  display: flex;
}

.inspector .panel-body {
  overflow: auto;
  padding: 0 0 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--gilt-faint) transparent;
  width: 100%;
}

.insp-head {
  position: sticky;
  top: 0;
  padding: 16px 18px 12px;
  background: linear-gradient(180deg, var(--lacquer-2), var(--lacquer));
  border-bottom: 1px solid var(--gilt-line);
  z-index: 1;
}

.insp-kind {
  display: inline-block;
  margin-bottom: 6px;
  padding: 1px 8px;
  font-size: 11.5px;
  color: #1a1408;
  background: var(--gilt);
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 6px 100%, 0 50%);
}

.insp-name {
  margin: 0;
  font: 700 25px/1.2 var(--serif-ko);
  color: var(--vellum);
}

.insp-en {
  margin: 2px 0 0;
  font: italic 500 17px/1.2 var(--serif-en);
  color: var(--vellum-2);
}

.insp-aka {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--gilt-hi);
}

.insp-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--gilt-faint);
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  color: var(--vellum-2);
}

.insp-close:hover {
  border-color: var(--gilt-line);
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 12px 18px 0;
  padding: 0;
  list-style: none;
}

.crumbs button {
  border: 1px solid var(--gilt-faint);
  background: var(--ink-2);
  padding: 2px 9px;
  font-size: 12px;
  cursor: pointer;
  color: var(--vellum-2);
}

.crumbs button:hover {
  border-color: var(--gilt-line);
  color: var(--vellum);
}

.crumbs .lvl {
  color: var(--gilt);
  margin-right: 4px;
}

.insp-section {
  margin: 16px 18px 0;
}

.insp-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font: 600 14px/1.3 var(--serif-ko);
  color: var(--gilt-hi);
}

.insp-section h3::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--gilt-line), transparent);
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0;
}

.facts div {
  padding: 7px 10px;
  background: var(--ink-2);
  border-left: 2px solid var(--gilt-faint);
}

.facts dt {
  font-size: 11.5px;
  color: var(--muted);
}

.facts dd {
  margin: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.mixbar {
  display: flex;
  height: 12px;
  margin-bottom: 8px;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.mixbar span {
  display: block;
  height: 100%;
}

.mixlist {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
}

.mixlist li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.mixlist .sw {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.6);
}

.mixlist .pct {
  font-variant-numeric: tabular-nums;
  color: var(--vellum-2);
}

.mixlist .rep {
  color: var(--gilt-hi);
}

.linklist {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.linklist button {
  border: 0;
  background: var(--ink-2);
  padding: 3px 8px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--vellum-2);
  box-shadow: inset 0 -1px 0 var(--gilt-faint);
}

.linklist button:hover {
  background: var(--lacquer);
  color: var(--vellum);
}

.linklist button.sea {
  color: var(--sea);
}

.note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ tooltip */
.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  pointer-events: none;
  max-width: 320px;
  --c: 7px;
}

.tooltip .panel-body {
  padding: 10px 13px 11px;
}

.tt-name {
  font: 700 16px/1.25 var(--serif-ko);
}

.tt-en {
  font: italic 500 14px/1.2 var(--serif-en);
  color: var(--vellum-2);
}

.tt-kind {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--gilt);
}

.tt-chain {
  margin-top: 2px;
  font-size: 12px;
  color: var(--vellum-2);
}

.tt-rows {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1px 10px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--gilt-faint);
  font-size: 12px;
}

.tt-rows dt {
  color: var(--muted);
}

.tt-rows dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.tt-hint {
  margin-top: 6px;
  font-size: 11px;
  color: #7c776b;
}

/* ------------------------------------------------------------------ console: map modes + minimap */
.console {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 9;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.modes {
  display: flex;
  gap: 6px;
  padding: 8px 10px 6px;
  background: linear-gradient(180deg, rgba(27, 34, 48, 0.94), rgba(20, 25, 34, 0.94));
  border: 1px solid var(--gilt-faint);
  border-bottom-color: var(--gilt-line);
}

.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 52px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.mode .oct {
  width: 40px;
  height: 40px;
  padding: 1px;
  background: var(--gilt-line);
  clip-path: var(--oct);
}

.mode .oct-in {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  clip-path: var(--oct);
  background: radial-gradient(circle at 50% 35%, var(--lacquer-2), var(--lacquer) 70%);
}

.mode svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--vellum);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.mode .mlabel {
  max-width: 56px;
  overflow: hidden;
  font-size: 11.5px;
  color: var(--vellum-2);
  white-space: nowrap;
  text-overflow: ellipsis;
}

:lang(en) .mode .mlabel {
  font-size: 10px;
  letter-spacing: 0.01em;
}

.mode:hover .oct {
  background: var(--gilt);
}

.mode[aria-pressed='true'] .oct {
  background: var(--gilt-hi);
}

.mode[aria-pressed='true'] .oct-in {
  background: radial-gradient(circle at 50% 35%, #f0dc9f, var(--gilt) 75%);
}

.mode[aria-pressed='true'] svg {
  stroke: #1a1408;
}

.mode[aria-pressed='true'] .mlabel {
  color: var(--gilt-hi);
}

.mode[disabled] {
  cursor: not-allowed;
}

.mode[disabled] .oct-in {
  background: #151a23;
}

.mode[disabled] svg,
.mode[disabled] .mlabel {
  opacity: 0.38;
}

.mode-sep {
  width: 1px;
  margin: 2px 2px 16px;
  background: var(--gilt-faint);
}

.minimap {
  --c: 12px;
}

.minimap .panel-body {
  padding: 6px;
}

#minimap {
  display: block;
  width: 288px;
  height: 108px;
  cursor: crosshair;
}

/* ------------------------------------------------------------------ status & legend */
.status {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.readout:empty {
  display: none;
}

.readout {
  padding: 4px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--vellum-2);
  background: rgba(15, 20, 28, 0.82);
  border: 1px solid var(--gilt-faint);
}

.legend {
  pointer-events: auto;
  width: 260px;
}

.legend .panel-body {
  padding: 12px 14px;
}

.legend h4 {
  margin: 0 0 8px;
  font: 600 13px/1.3 var(--serif-ko);
  color: var(--gilt-hi);
}

.legend ul {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend .sw {
  width: 11px;
  height: 11px;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------------ loading */
.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 42%, #1c2a42, #0b1019 70%);
  transition: opacity 500ms ease;
}

.loading.done {
  opacity: 0;
  pointer-events: none;
}

.loading-mark {
  width: 72px;
  height: 72px;
  animation: spin 9s linear infinite;
}

.loading-title {
  margin: 0;
  font: 600 20px/1.3 var(--serif-ko);
  color: var(--gilt-hi);
}

.loading-bar {
  width: 260px;
  height: 4px;
  background: rgba(201, 164, 76, 0.15);
}

.loading-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--gilt);
  transition: width 200ms;
}

.loading-step {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.loading.error .loading-title {
  color: #e39b8f;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-mark {
    animation: none;
  }
  .loading {
    transition: none;
  }
}

/* ------------------------------------------------------------------ small screens */
@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
  }
  .scenario {
    width: 64px;
  }
  .scenario:first-child,
  .scenario:last-child {
    width: 74px;
  }
  .scenario .event {
    display: none;
  }
  .brand-sub {
    display: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    grid-template-columns: 1fr auto;
    grid-template-areas: 'brand tools' 'dial dial';
    padding: 8px 12px;
    row-gap: 8px;
  }
  .brand {
    grid-area: brand;
  }
  .tools {
    grid-area: tools;
  }
  .scenarios {
    grid-area: dial;
    justify-self: center;
  }
  .search {
    width: 150px;
  }
  .inspector {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 52vh;
  }
  .modes {
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100vw - 28px);
  }
  #minimap {
    width: 192px;
    height: 72px;
  }
  .legend {
    display: none;
  }
}
