/* Uncharted: a cartographer's palette. Dark ink panels with thin brass rules,
   an old-print serif for titles and place names, a plain humanist face for
   reading. The world itself stays pixel art. */

:root {
  --ink: #15120e;
  --ink-2: #1d1913;
  --panel: rgba(21, 18, 14, 0.88);
  --line: #4a4032;
  --line-soft: #2c261d;
  --text: #e9e1cf;
  --muted: #a39a86;
  --faint: #6f6757;
  --brass: #c9a55c;
  --brass-dim: #8a7240;
  --good: #a3c47a;
  --warn: #dba45f;
  --bad: #d4735f;
  --serif: "IM Fell English", Georgia, "Times New Roman", serif;
  --caps: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --sans: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #100e0b;
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
}

canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

#game { position: fixed; inset: 0; display: block; cursor: crosshair; }
#title-bg { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
body.playing #title-bg { display: none; }

/* ---------- type ---------- */

h1 {
  font-family: var(--caps);
  font-weight: 400;
  font-size: 84px;
  line-height: 1;
  margin: 0;
  letter-spacing: 0.02em;
  color: var(--text);
}
h2 { font-family: var(--caps); font-weight: 400; font-size: 30px; margin: 0 0 12px; color: var(--text); letter-spacing: 0.01em; }
h3 { font-family: var(--caps); font-weight: 400; font-size: 20px; margin: 22px 0 6px; color: var(--brass); letter-spacing: 0.02em; }
p { line-height: 1.5; margin: 0 0 12px; }
b { font-weight: 700; color: #f3ecdc; }
i { font-style: italic; }
.small { font-size: 15px; color: var(--muted); text-align: center; }
.small.left { text-align: left; }
.error { color: var(--bad); min-height: 1.2em; font-size: 15px; margin: 0; }
.note { color: var(--good); font-size: 15px; margin: 0; }
.note:empty { display: none; }
.tagline { text-align: center; color: var(--muted); font-family: var(--serif); font-style: italic; font-size: 19px; }

kbd {
  display: inline-block;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  background: #241f18;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 6px;
  min-width: 22px;
  text-align: center;
}

/* ---------- panels, buttons, fields ---------- */

.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.35);
  border-radius: 2px;
}

.card {
  padding: 28px 34px;
  max-width: 760px;
  width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  overflow: auto;
  background: rgba(21, 18, 14, 0.96);
}
.card.slim { max-width: 480px; text-align: center; }

.btn {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--brass);
  border: 1px solid var(--brass);
  border-radius: 2px;
  padding: 11px 26px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: #d8b76f; }
.btn:active { background: #b8964f; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--brass-dim); color: #fff; }
.btn.small { font-size: 13px; padding: 6px 14px; }

input {
  font-family: var(--sans);
  font-size: 18px;
  color: var(--text);
  background: #100d0a;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 9px 11px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--brass); }
input::placeholder { color: var(--faint); }

.link {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  align-self: flex-start;
}
.link:hover { color: var(--text); }

/* ---------- screens ---------- */

.screen, .modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.screen.open, .modal.open { display: flex; }
#loading, #companion { background: #100e0b; }
#loading h2 { font-size: 26px; }
.modal { background: rgba(8, 7, 5, 0.6); z-index: 30; }

/* ---------- main menu ---------- */

#title {
  align-items: stretch;
  justify-content: flex-start;
  background: linear-gradient(90deg, rgba(12, 10, 8, 0.94) 0%, rgba(12, 10, 8, 0.86) 34%, rgba(12, 10, 8, 0.55) 62%, rgba(12, 10, 8, 0.25) 100%);
}
.menu {
  width: 430px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 64px 0 36px 64px;
}
.eyebrow {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--muted);
  margin: 0 0 6px;
}
.menu-head h1 { font-size: 68px; padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.menu-nav { display: flex; flex-direction: column; gap: 2px; }
.menu-nav button {
  font-family: var(--caps);
  font-size: 25px;
  text-align: left;
  color: var(--muted);
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  padding: 6px 0 6px 16px;
  margin-left: -18px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.menu-nav button:hover { color: var(--text); }
.menu-nav button.on { color: var(--text); border-left-color: var(--brass); }
.menu-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--faint); }

.menu-pages {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  padding: 64px 64px 36px 40px;
  overflow-y: auto;
  min-width: 0;
}
.page {
  display: none;
  width: 100%;
  max-width: 660px;
  background: rgba(19, 16, 12, 0.9);
  border: 1px solid var(--line);
  padding: 30px 36px;
}
.page.on { display: block; animation: rise 0.25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.page p { color: #ddd5c3; }
.steps { padding-left: 22px; line-height: 1.5; color: #ddd5c3; }
.steps li { margin-bottom: 6px; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; align-items: center; font-size: 16px; color: #ddd5c3; }
.keys kbd { justify-self: start; }
.pieces { width: 100%; border-collapse: collapse; font-size: 15px; color: #ddd5c3; }
.pieces td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.pieces td:first-child { color: var(--text); font-weight: 500; white-space: nowrap; }
.pieces td:nth-child(2) { color: var(--muted); white-space: nowrap; }
.news ul { padding-left: 20px; margin: 4px 0 8px; line-height: 1.5; color: #ddd5c3; }
.news h3:first-child { margin-top: 0; }
.nation-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.nation-list .row-n { display: flex; gap: 10px; align-items: center; font-size: 15px; color: var(--muted); }
.nation-list .row-n b { font-weight: 500; }

.world-now { width: 100%; max-width: 660px; border-top: 1px solid var(--line); padding-top: 14px; }
.world-now h3 { margin: 0 0 10px; font-size: 17px; color: var(--muted); }
.figures { display: flex; gap: 30px; flex-wrap: wrap; }
.figure { display: flex; flex-direction: column; }
.figure .n { font-family: var(--sans); font-weight: 500; font-size: 28px; color: var(--text); line-height: 1; font-variant-numeric: lining-nums tabular-nums; }
.figure .l { font-size: 13px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-top: 4px; }
.latest { list-style: none; padding: 0; margin: 14px 0 0; font-family: var(--serif); font-style: italic; font-size: 16px; color: var(--muted); }
.latest li { padding: 2px 0; }

/* the account form on the Play page */
.tabs { display: flex; gap: 22px; margin: 0 0 22px; border-bottom: 1px solid var(--line-soft); }
.tab {
  font-family: var(--caps);
  font-size: 21px;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 0 8px;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--brass); }
.creator { display: flex; gap: 30px; align-items: flex-start; flex-wrap: wrap; }
#preview {
  width: 200px;
  height: 200px;
  background: #3b7a33;
  border: 1px solid var(--line);
  flex: none;
}
.fields { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 14px; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.fields .btn { align-self: flex-start; }
.pick { display: flex; align-items: center; gap: 12px; }
.pick > span { width: 52px; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  cursor: pointer;
}
.swatch.on { outline: 1px solid var(--brass); outline-offset: 2px; }
#title.back .tabs, #title.login #look-fields, #title.login #preview, #title.back #name-field, #title.back #pass-field { display: none; }
#title:not(.back) #welcome-back, #title:not(.back) #switch-account { display: none; }
#welcome-back { margin: 0; font-size: 28px; }

@media (max-width: 1000px) {
  #title { flex-direction: column; overflow-y: auto; }
  .menu { width: auto; padding: 36px 24px 0; }
  .menu-nav { flex-direction: row; flex-wrap: wrap; gap: 4px 18px; }
  .menu-nav button { font-size: 20px; margin-left: 0; padding: 4px 0; border-left: 0; border-bottom: 2px solid transparent; }
  .menu-nav button.on { border-bottom-color: var(--brass); }
  .menu-foot { display: none; }
  .menu-pages { padding: 20px 24px 36px; }
  h1 { font-size: 56px; }
}

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 10; }
body.playing #hud { display: block; }
body.atlas-open #hud > :not(#toasts) { opacity: 0; }

.panel { position: absolute; padding: 10px 14px; pointer-events: auto; }

#hud-left { top: 14px; left: 14px; }
#hearts { display: flex; gap: 4px; }
#hearts img { width: 26px; height: 24px; image-rendering: pixelated; }
#stamina { margin-top: 8px; height: 5px; background: #0d0b08; border: 1px solid var(--line-soft); }
#stamina-fill { height: 100%; width: 100%; background: var(--brass); }
#weak { display: none; margin-top: 6px; font-size: 14px; color: var(--bad); }

#hud-right { top: 14px; right: 14px; text-align: right; min-width: 220px; }
#place { font-family: var(--caps); font-size: 23px; color: var(--text); line-height: 1.1; }
#realm { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--brass); }
#coords, #explored { font-size: 14px; color: var(--muted); }
#sketches { font-size: 14px; color: var(--good); }
#sketches.warn { color: var(--warn); }
#safe { display: none; font-size: 14px; color: var(--good); }

#inventory { bottom: 14px; left: 14px; display: flex; gap: 5px; padding: 7px; }
.slot {
  position: relative;
  width: 50px;
  height: 50px;
  background: #0f0d0a;
  border: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot img { width: 32px; height: 32px; image-rendering: pixelated; }
.slot.none img { opacity: 0.28; }
.slot .count { position: absolute; right: 4px; bottom: 1px; font-size: 15px; font-weight: 700; }
.slot .stored { position: absolute; left: 4px; top: 1px; font-size: 12px; color: var(--good); }

#chronicle { bottom: 14px; right: 14px; width: 370px; padding: 8px 12px; }
.chronicle-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-family: var(--caps); font-size: 17px; color: var(--text); }
#online { font-family: var(--sans); font-size: 13px; color: var(--muted); margin-left: auto; }
#chronicle-toggle { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }
#chronicle.collapsed #chronicle-list, #chronicle.collapsed #chat { display: none; }
.feed { list-style: none; margin: 6px 0 0; padding: 0; max-height: 180px; overflow-y: auto; font-size: 15px; }
.feed li { padding: 3px 0; border-bottom: 1px solid var(--line-soft); line-height: 1.35; }
.feed li.chat { color: #b9d3e6; }
.feed li.name { color: var(--brass); }
.feed li.fall { color: #e0a090; }
.feed li.loot { color: var(--good); }
.feed li.nationchat, .feed li.nation { color: #e6c79a; }
.feed .when { color: var(--faint); font-size: 13px; }
#chat { display: none; margin-top: 6px; }
#chat.open { display: block; }
#chat input { font-size: 16px; padding: 6px 8px; }

#toasts {
  position: absolute;
  top: 26px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(620px, 60vw);
}
.toast {
  background: rgba(16, 13, 10, 0.92);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass-dim);
  padding: 8px 16px;
  font-size: 16px;
  text-align: center;
  transition: opacity 0.8s;
  animation: drop 0.2s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.fade { opacity: 0; }
@keyframes drop { from { transform: translateY(-6px); opacity: 0; } }

#hint {
  position: absolute;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 620px;
  background: rgba(16, 13, 10, 0.94);
  border: 1px solid var(--brass-dim);
  color: var(--text);
  padding: 10px 18px;
  font-size: 16px;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s;
}
#hint.show { opacity: 1; }
#instance-badge {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: #6d4a1f;
  color: #f5e7c8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 2px 12px;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}
#keys-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: #cfc6b2;
  white-space: nowrap;
  background: rgba(16, 13, 10, 0.78);
  border: 1px solid var(--line-soft);
  padding: 4px 12px 4px 2px;
}
#keys-hint kbd { margin: 0 3px 0 10px; font-size: 11px; padding: 0 5px; }

.row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
#name-input { flex: 1; }
#help ul { font-size: 16px; padding-left: 20px; line-height: 1.5; color: #ddd5c3; }
#help .keys { font-size: 15px; }

#companion .feed { max-height: 60vh; font-size: 16px; }
#companion h1 { text-align: center; font-size: 56px; }

@media (max-width: 1100px) {
  #chronicle { width: 300px; }
  #keys-hint { display: none; }
}
@media (max-width: 600px) {
  .card { padding: 22px 18px; }
}

/* ---------- building ---------- */

#buildbar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  pointer-events: auto;
  max-width: calc(100vw - 800px);
  min-width: 560px;
}
#buildbar.open { display: flex; }
body.building #keys-hint { display: none; }
body.building #game { cursor: cell; }
#build-pieces { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.piece {
  position: relative;
  width: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 2px 5px;
  font-family: var(--sans);
  color: var(--text);
  background: #0f0d0a;
  border: 1px solid var(--line-soft);
  cursor: pointer;
}
.piece:hover { border-color: var(--line); }
.piece img { width: 40px; height: 60px; image-rendering: pixelated; }
.piece .key { position: absolute; top: 2px; left: 5px; font-size: 12px; color: var(--faint); }
.piece-name { font-size: 13px; font-weight: 500; line-height: 1.1; text-align: center; }
.piece-cost { font-size: 12px; color: var(--muted); }
.piece.on { border-color: var(--brass); background: #1c1710; }
.piece.poor { opacity: 0.45; }
#build-tip { font-size: 13px; color: var(--muted); text-align: center; }
@media (max-width: 1500px) {
  #buildbar { max-width: calc(100vw - 40px); bottom: 84px; }
}

/* ---------- nation panel ---------- */

.card.wide { max-width: 860px; }
#nation-body { max-height: calc(100% - 40px); }
.label { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 12px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.form .btn { align-self: flex-start; margin-top: 6px; }
img.flag { image-rendering: pixelated; width: 36px; height: 24px; display: block; }
img.flag.mid { width: 48px; height: 32px; }
img.flag.big { width: 96px; height: 64px; }
.flag-editor { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.flag-controls { display: flex; flex-direction: column; gap: 8px; }
.patterns { display: flex; gap: 6px; flex-wrap: wrap; }
.pattern { padding: 3px; background: #0f0d0a; border: 1px solid var(--line-soft); cursor: pointer; }
.pattern.on { border-color: var(--brass); }
.flag-editor .swatch { width: 22px; height: 22px; }
.nation-row, .nation-head { display: flex; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.nation-head h2 { margin: 0; }
.nation-name { font-family: var(--caps); font-size: 20px; }
.motto { font-family: var(--serif); font-style: italic; color: var(--brass); font-size: 17px; }
.grow { flex: 1; min-width: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
#nation-body .row { justify-content: flex-start; }
#nation-body .row input { flex: 1; font-size: 16px; }
.office, .law { background: #100d0a; border: 1px solid var(--line-soft); padding: 9px 12px; margin: 8px 0; }
.office-title { font-size: 17px; font-weight: 500; }
.cand { padding: 5px 0; border-top: 1px solid var(--line-soft); }
.law.voting { border-color: var(--line); }
.law.passed { color: #e3dccb; font-family: var(--serif); font-style: italic; font-size: 16px; padding: 6px 10px; margin: 4px 0; }
.law-text { font-family: var(--serif); font-style: italic; font-size: 17px; margin-bottom: 4px; }
.members { display: flex; flex-wrap: wrap; gap: 6px; }
.member { background: #100d0a; border: 1px solid var(--line-soft); padding: 3px 8px; font-size: 14px; }
.member.office { color: var(--brass); border-color: var(--brass-dim); }
