:root {
  --ink: #241a2e;
  --panel: #2b2438;
  --panel-2: #3a3149;
  --edge: #5b4d73;
  --edge-light: #8d7fae;
  --text: #f6eedb;
  --muted: #b9afc9;
  --gold: #ffd56b;
  --good: #9ee36a;
  --warn: #ffb35c;
  --bad: #ff6b6b;
  --font: "Pixelify Sans", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #141826;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: none;
}

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; }

/* ---------- pixel panels ---------- */

.card, .panel {
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--edge), inset 0 3px 0 3px var(--edge-light), 0 6px 0 rgba(0, 0, 0, 0.35);
  border-radius: 0;
}

.card {
  padding: 30px 36px;
  max-width: 780px;
  width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  overflow: auto;
}
.card.slim { max-width: 500px; text-align: center; }

h1 {
  font-weight: 700;
  font-size: 72px;
  margin: 0;
  text-align: center;
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 4px 4px 0 #8a4b1f, 8px 8px 0 var(--ink);
}
h2 { font-weight: 600; font-size: 28px; margin: 0 0 10px; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
h3 { font-weight: 600; font-size: 20px; margin: 18px 0 6px; color: var(--gold); }
p { font-size: 18px; line-height: 1.35; }
.tagline { text-align: center; font-size: 20px; margin: 10px 0 20px; color: var(--muted); }
.small { font-size: 15px; color: var(--muted); text-align: center; }
.error { color: var(--bad); min-height: 1.2em; font-size: 16px; }

.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 22px;
  background: #4f9a3c;
  color: #fff;
  border: 3px solid var(--ink);
  box-shadow: inset 0 -5px 0 #2f6b28, inset 0 3px 0 #8fd468;
  padding: 10px 26px 14px;
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { box-shadow: inset 0 3px 0 #2f6b28; padding: 13px 26px 11px; }
.btn.ghost { background: var(--panel-2); box-shadow: inset 0 -5px 0 #241d30, inset 0 3px 0 var(--edge-light); }

input {
  font-family: var(--font);
  font-size: 22px;
  color: var(--text);
  background: #181424;
  border: 3px solid var(--ink);
  box-shadow: inset 0 3px 0 #0e0b16;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input:focus { box-shadow: inset 0 3px 0 #0e0b16, 0 0 0 3px var(--gold); }
input::placeholder { color: #6f6584; }

/* ---------- 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: #141826; }
.modal { background: rgba(10, 8, 18, 0.55); z-index: 30; }

.creator { display: flex; gap: 30px; align-items: center; flex-wrap: wrap; justify-content: center; }
#preview {
  width: 240px;
  height: 240px;
  background: #3b7a33;
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px #2c5e28;
}
.fields { flex: 1; min-width: 280px; display: flex; flex-direction: column; gap: 14px; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-size: 18px; color: var(--muted); }
.pick { display: flex; align-items: center; gap: 12px; }
.pick > span { width: 58px; font-size: 18px; color: var(--muted); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px;
  height: 30px;
  border: 3px solid var(--ink);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), inset 0 3px 0 rgba(255, 255, 255, 0.25);
  cursor: pointer;
}
.swatch.on { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- 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: 30px; height: 28px; image-rendering: pixelated; }
#stamina { margin-top: 8px; height: 12px; border: 3px solid var(--ink); background: #181424; }
#stamina-fill { height: 100%; width: 100%; background: var(--gold); box-shadow: inset 0 -3px 0 #c98f2b; }
#weak { display: none; margin-top: 6px; font-size: 16px; color: var(--bad); }

#hud-right { top: 14px; right: 14px; text-align: right; min-width: 230px; }
#place { font-weight: 600; font-size: 24px; color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
#coords, #explored { font-size: 16px; color: var(--muted); }
#sketches { font-size: 16px; color: var(--good); }
#sketches.warn { color: var(--warn); }
#safe { display: none; font-size: 16px; color: var(--good); }

#inventory { bottom: 14px; left: 14px; display: flex; gap: 6px; padding: 8px; }
.slot {
  position: relative;
  width: 58px;
  height: 58px;
  background: #181424;
  border: 3px solid var(--ink);
  box-shadow: inset 0 3px 0 #0e0b16;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot img { width: 36px; height: 36px; image-rendering: pixelated; }
.slot.none img { opacity: 0.3; }
.slot .count { position: absolute; right: 4px; bottom: 0; font-size: 18px; font-weight: 600; text-shadow: 2px 2px 0 var(--ink); }
.slot .stored { position: absolute; left: 4px; top: 0; font-size: 13px; color: var(--good); text-shadow: 1px 1px 0 var(--ink); }

#chronicle { bottom: 14px; right: 14px; width: 380px; padding: 8px 12px; }
.chronicle-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; font-size: 18px; color: var(--gold); }
#online { font-weight: 400; font-size: 15px; color: var(--muted); margin-left: auto; }
#chronicle-toggle { background: none; border: none; font-family: var(--font); font-size: 18px; cursor: pointer; color: var(--text); }
#chronicle.collapsed #chronicle-list, #chronicle.collapsed #chat { display: none; }
#chronicle.collapsed #chronicle-toggle { transform: rotate(180deg); }
.feed { list-style: none; margin: 6px 0 0; padding: 0; max-height: 180px; overflow-y: auto; font-size: 16px; }
.feed li { padding: 3px 0; border-bottom: 2px solid #231d30; }
.feed li.chat { color: #9fd8ff; }
.feed li.name { color: var(--gold); }
.feed li.fall { color: #ff9a8a; }
.feed li.loot { color: var(--good); }
.feed .when { color: #7f7596; font-size: 14px; }
#chat { display: none; margin-top: 6px; }
#chat.open { display: block; }
#chat input { font-size: 17px; padding: 5px 8px; }

#toasts {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(640px, 60vw);
}
.toast {
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--edge), 0 4px 0 rgba(0, 0, 0, 0.35);
  padding: 9px 16px;
  font-size: 18px;
  text-align: center;
  transition: opacity 0.8s;
  animation: drop 0.25s steps(4);
}
.toast.good { box-shadow: inset 0 0 0 3px #4f9a3c, 0 4px 0 rgba(0, 0, 0, 0.35); color: #e8ffd6; }
.toast.fade { opacity: 0; }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }

#hint {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 640px;
  background: rgba(20, 16, 30, 0.92);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--gold);
  color: var(--text);
  padding: 10px 18px;
  font-size: 18px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s;
}
#hint.show { opacity: 1; }
#instance-badge {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--warn);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  padding: 1px 12px;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}
#keys-hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  color: var(--text);
  background: rgba(20, 16, 30, 0.7);
  padding: 4px 12px;
  white-space: nowrap;
}

.row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
#name-input { flex: 1; }
.help-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; font-size: 18px; }
.help-grid b { color: var(--gold); }
#help ul { font-size: 17px; padding-left: 22px; line-height: 1.4; }
#help .btn { display: block; margin: 18px auto 0; }

#companion .feed { max-height: 60vh; font-size: 17px; }

@media (max-width: 1100px) {
  #chronicle { width: 300px; }
  #keys-hint { display: none; }
}
@media (max-width: 600px) {
  h1 { font-size: 46px; letter-spacing: 1px; }
  .card { padding: 22px 18px; }
}

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

.card.wide { max-width: 880px; }
#nation-body { max-height: calc(100% - 40px); }
#realm { font-size: 16px; color: #ffd0a0; }
.btn.small { font-size: 17px; padding: 6px 14px 9px; }
.btn.small:active { padding: 8px 14px 7px; }
.small.left { text-align: left; }
.label { font-size: 16px; color: var(--muted); margin-top: 10px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 16px; 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: 54px; height: 36px; }
img.flag.big { width: 108px; height: 72px; }
.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: #181424; border: 3px solid var(--ink); cursor: pointer; }
.pattern.on { outline: 3px solid var(--gold); }
.flag-editor .swatch { width: 26px; height: 26px; }
.nation-row, .nation-head { display: flex; gap: 14px; align-items: center; padding: 8px 0; border-bottom: 2px solid #231d30; }
.nation-head h2 { margin: 0; }
.nation-name { font-size: 20px; font-weight: 600; }
.motto { color: var(--gold); 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: 18px; }
.office, .law { background: #221c2e; border: 3px solid var(--ink); padding: 8px 12px; margin: 8px 0; }
.office-title { font-size: 19px; font-weight: 600; }
.cand { padding: 4px 0; border-top: 2px solid #2e263d; }
.law.voting { box-shadow: inset 0 0 0 2px #5b4d73; }
.law.passed { color: #e8ffd6; font-size: 16px; padding: 6px 10px; margin: 4px 0; }
.law-text { font-size: 18px; margin-bottom: 4px; }
.members { display: flex; flex-wrap: wrap; gap: 6px; }
.member { background: #221c2e; border: 2px solid var(--ink); padding: 3px 8px; font-size: 16px; }
.member.office { color: var(--gold); }
.feed li.nationchat { color: #ffd0a0; }
.feed li.nation { color: #ffd0a0; }
