:root {
  --parchment: #e8dcc0;
  --ink: #1a1610;
  --gold: #d4a843;
  --gold-dim: #8a6f2c;
  --panel: #241d14;
  --panel-2: #17120c;
  --edge: #4a3c26;
  --blue: #5b8fd6;
  --red: #c65a4a;
  --green: #7ba24f;
  --focus: #ffd97a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--panel-2);
  color: var(--parchment);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

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

.screen { display: none; height: 100dvh; width: 100vw; }
.screen.active { display: block; }

/* ---------- Main menu ---------- */

#screen-menu {
  display: none;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px 24px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 0%, #3a2f1d 0%, #17120c 60%),
    var(--panel-2);
}
#screen-menu.active { display: grid; }

.menu-inner {
  width: min(560px, 100%);
  text-align: center;
  padding-bottom: 24px;
}

.crest {
  width: 76px; height: 76px;
  margin: 0 auto 18px;
  display: block;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 9vw, 3.4rem);
  letter-spacing: .06em;
  font-weight: 600;
  color: var(--gold);
  text-shadow: 0 2px 0 #000;
}

.tagline {
  margin: .6rem auto 2rem;
  max-width: 30ch;
  color: #c3b490;
  line-height: 1.55;
  font-size: 1.05rem;
}

.menu-actions { display: grid; gap: 12px; }

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 14px 20px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: linear-gradient(#2f2618, #211a10);
  color: var(--parchment);
  font-size: 1.1rem;
  letter-spacing: .02em;
  transition: transform .12s ease, background .18s ease, border-color .18s ease;
}
.btn:hover { background: linear-gradient(#3a301d, #282013); border-color: var(--gold-dim); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(#c9a13f, #9a7526);
  color: #201806;
  border-color: #e0c070;
  font-weight: 600;
}
.btn.primary:hover { background: linear-gradient(#dcb44e, #ab842c); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

.account {
  margin-top: 14px;
  font-size: .92rem;
  color: #c3b490;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 44px;
}
.account a.btn-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: #1e1810;
  color: var(--parchment);
  text-decoration: none;
}
.account a.btn-link:hover { border-color: var(--gold-dim); background: #251e13; }

.saves { margin-top: 26px; text-align: left; }
.saves h2 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: #c3b490;
  margin: 0 0 10px;
  font-weight: 600;
}
.save-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.save-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: #1e1810;
  text-align: left;
}
.save-row:hover { border-color: var(--gold-dim); background: #251e13; }
.save-row .when { flex: 1; }
.save-row .name { display: block; font-size: 1.02rem; }
.save-row .meta { display: block; font-size: .82rem; color: #9d8d68; margin-top: 2px; }
.tag {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  white-space: nowrap;
}
.empty-note {
  padding: 18px 16px;
  border: 1px dashed var(--edge);
  border-radius: 10px;
  color: #9d8d68;
  line-height: 1.5;
  font-size: .95rem;
}
.saves-foot { margin-top: 10px; display: flex; gap: 10px; flex-wrap: wrap; }
.linkish {
  background: none;
  border: 0;
  padding: 10px 4px;
  min-height: 44px;
  color: #c3b490;
  text-decoration: underline;
  font-size: .9rem;
}
.linkish:hover { color: var(--parchment); }

/* ---------- Game screen ---------- */

#screen-game { position: relative; background: #0d0b07; }
#screen-game.active { display: block; }

canvas#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(#12100bef, #12100bbb 70%, #12100b00);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.res {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #1d1710d9;
  border: 1px solid var(--edge);
  font-size: .95rem;
  white-space: nowrap;
}
.res .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.res.wood .dot { background: #7b5a33; }
.res.food .dot { background: #b5443f; }
.res.gold .dot { background: var(--gold); }
.res.stone .dot { background: #9a9a96; }
.res.pop .dot { background: var(--blue); }
.res b { font-weight: 600; }
.res.capped { border-color: var(--red); color: #f0b6ac; }
.res .lbl { color: #c3b490; }

.cmd-top {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.map-actions {
  display: flex;
  gap: 8px;
  flex: none;
}
.map-actions button { pointer-events: auto; }

.icon-btn {
  min-width: 48px;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: #1d1710e6;
  font-size: .92rem;
}
.icon-btn:hover { border-color: var(--gold-dim); }

.commands {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(#12100b00, #12100bcc 30%, #12100bf5);
  display: grid;
  gap: 8px;
}
.sel-line {
  font-size: .9rem;
  color: #c3b490;
  min-height: 1.2em;
  text-shadow: 0 1px 3px #000;
}
.cmd-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.cmd {
  flex: 0 0 auto;
  min-height: 56px;
  min-width: 92px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: linear-gradient(#2b2316, #1d1710);
  text-align: left;
  line-height: 1.25;
}
.cmd:hover:not([disabled]) { border-color: var(--gold-dim); }
.cmd .t { display: block; font-size: .98rem; }
.cmd .c { display: block; font-size: .74rem; color: #9d8d68; margin-top: 3px; }
.cmd[disabled] { opacity: .42; cursor: not-allowed; }
.cmd.armed { border-color: var(--focus); background: linear-gradient(#4a3c1c, #322710); }

.toast {
  position: absolute;
  left: 50%;
  top: 64px;
  transform: translate(-50%, -8px);
  background: #241d14f2;
  border: 1px solid var(--gold-dim);
  color: var(--parchment);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: .95rem;
  max-width: min(90vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.banner {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: #0d0b07e0;
  z-index: 8;
  padding: 20px;
}
.banner.show { display: grid; }
.banner-card {
  width: min(420px, 100%);
  text-align: center;
  padding: 28px 24px;
  border: 1px solid var(--gold-dim);
  border-radius: 14px;
  background: linear-gradient(#241d14, #17120c);
}
.banner-card h2 { margin: 0 0 8px; color: var(--gold); font-size: 1.8rem; }
.banner-card p { margin: 0 0 20px; color: #c3b490; line-height: 1.5; }
.banner-card .btn + .btn { margin-top: 10px; }

/* Phones: the resource strip keeps its numbers but drops the words, so the
   whole realm fits one row instead of pushing the map down three. */
@media (max-width: 620px) {
  .res .lbl { display: none; }
  .res { font-size: .92rem; padding: 6px 8px; gap: 5px; }
  /* The report button floats over the top-right corner (measured 190x40 at
     390px wide), so the strip drops below it rather than hiding under it. */
  .hud {
    gap: 5px;
    padding: calc(max(8px, env(safe-area-inset-top)) + 50px) 8px 8px;
    flex-wrap: nowrap;
    overflow: hidden;
  }
  .res.clock { margin-left: auto; }
  .cmd { min-width: 84px; }
  .cmd-top { flex-direction: column; align-items: stretch; gap: 6px; }
  /* Clear of the resource strip, which sits lower here. */
  .toast { top: 124px; }
  .map-actions { justify-content: flex-start; }
  .map-actions button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
