@font-face {
  font-family: Sarabun;
  src: url("/fonts/Sarabun-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Sarabun;
  src: url("/fonts/Sarabun-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  --ink: #071614;
  --panel: rgba(12, 28, 26, 0.92);
  --line: rgba(228, 194, 122, 0.45);
  --gold: #e7c98a;
  --gold-deep: #8a6430;
  --rice: #f4e6c4;
  --jade: #1d6b46;
  --sea: #0b1e24;
  --danger: #d46555;
  color: var(--rice);
  background: var(--ink);
  font-family: Sarabun, "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { min-height: 100dvh; background: radial-gradient(circle at top, #16352f, var(--ink) 55%); }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.screen { min-height: 100dvh; }

.crest { width: 92px; height: 92px; object-fit: cover; border-radius: 50%; border: 2px solid var(--gold); background: #12342a; }
.crest.small { width: 42px; height: 42px; }
.eyebrow { margin: 0; letter-spacing: 0.08em; text-transform: none; color: var(--gold); font-size: 0.85rem; }
h1, h2 { font-weight: 600; margin: 0.2rem 0; }
h1 { font-size: 3rem; line-height: 1; }
.lead { line-height: 1.55; color: #f7f0df; }
.fine { color: #cbbd9e; font-size: 0.86rem; line-height: 1.45; }
.center { text-align: center; }

button.gold, button.ghost, .tools button, .tools select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  background: transparent;
}
button.gold {
  background: linear-gradient(#f3ddb0, #c4964a);
  color: #2a1c08;
  border-color: transparent;
  font-weight: 600;
  min-width: 220px;
}
button.gold:disabled { opacity: 0.55; cursor: default; }
button.ghost { background: rgba(255, 255, 255, 0.04); }
button.ghost.active { border-color: var(--gold); color: var(--gold); }

#gate { display: grid; place-items: center; padding: 1.5rem; }
.gate-card { width: min(560px, 100%); text-align: center; }
.gate-card .crest { margin-bottom: 0.6rem; }

#play { display: flex; flex-direction: column; height: 100dvh; }
header {
  display: flex; gap: 0.8rem; align-items: center; justify-content: space-between;
  padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); background: rgba(7, 22, 20, 0.9);
}
.brand { display: flex; gap: 0.55rem; align-items: center; min-width: 0; }
.brand strong { display: block; }
.brand span { color: var(--gold); font-size: 0.85rem; }
nav { display: flex; gap: 0.4rem; }
.resources:not([hidden]) { display: flex; flex-wrap: wrap; gap: 0.35rem 0.7rem; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.resources b { color: var(--gold); font-weight: 600; }
.res small { display: block; color: #b7aa90; font-size: 0.72rem; }

#mapView, #baseView { position: relative; flex: 1; min-height: 0; }
#map { width: 100%; height: 100%; display: block; touch-action: none; background: var(--sea); cursor: grab; }
#map.drag { cursor: grabbing; }
.tools {
  position: absolute; top: 12px; left: 12px; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: end;
  max-width: calc(100% - 24px);
}
.tools label { display: grid; gap: 0.15rem; font-size: 0.75rem; color: var(--gold); }
.tools select, .tools button { background: var(--panel); padding: 0.45rem 0.7rem; }
.hint {
  position: absolute; top: 12px; right: 12px; margin: 0; padding: 0.35rem 0.6rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: 0.78rem;
}

.card {
  position: absolute; left: 12px; right: 12px; bottom: 12px; max-height: 48%;
  overflow: auto; padding: 0.9rem 1rem 1rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.card h3 { margin: 0.15rem 0; }
.card p { margin: 0.35rem 0; line-height: 1.45; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 0.8rem; margin: 0.5rem 0; font-size: 0.92rem; }
.cost { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0; }
.cost span, .tag {
  border: 1px solid var(--line); border-radius: 999px; padding: 0.15rem 0.55rem; font-size: 0.82rem;
}
.tag.warn { color: #ffd0c8; border-color: rgba(212, 101, 85, 0.6); }
.card .row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

#baseView:not([hidden]) { display: flex; }
.base-scroll { flex: 1; overflow: auto; padding: 1rem 1rem 7rem; }
.base-head { display: flex; justify-content: space-between; gap: 1rem; align-items: end; flex-wrap: wrap; }
#baseStats { display: flex; gap: 0.8rem; margin: 0; }
#baseStats div { min-width: 72px; }
#baseStats dt { color: var(--gold); font-size: 0.75rem; }
#baseStats dd { margin: 0; font-size: 1.15rem; }
.queue { margin: 0.7rem 0; padding: 0.55rem 0.8rem; border-left: 3px solid var(--gold); background: rgba(228, 194, 122, 0.08); }

#city {
  width: min(920px, 100%);
  margin: 0.8rem auto;
  aspect-ratio: 6 / 5;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 6px;
  padding: 10px;
  border: 2px solid var(--gold);
  border-radius: 22px;
  background:
    linear-gradient(rgba(8, 24, 18, 0.2), rgba(8, 24, 18, 0.45)),
    url("/art/ground.jpg") center / cover,
    repeating-linear-gradient(90deg, rgba(228, 194, 122, 0.08) 0 1px, transparent 1px 16px),
    linear-gradient(#214e38, #173628);
  box-shadow: inset 0 0 0 6px rgba(20, 40, 30, 0.35), 0 20px 50px rgba(0, 0, 0, 0.28);
}
.pad, .path {
  border-radius: 12px;
  min-width: 0;
  min-height: 0;
}
.path { background: rgba(7, 22, 20, 0.28); border: 1px dashed rgba(228, 194, 122, 0.25); }
.pad {
  position: relative;
  border: 1px solid rgba(228, 194, 122, 0.35);
  background: rgba(7, 18, 16, 0.55);
  color: inherit;
  padding: 0;
  overflow: hidden;
  text-align: left;
}
.pad img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pad .label {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0.15rem 0.3rem; background: linear-gradient(transparent, rgba(0, 0, 0, 0.78));
  font-size: clamp(0.62rem, 1.4vw, 0.82rem);
}
.pad .lv {
  position: absolute; top: 4px; right: 4px;
  background: rgba(7, 22, 20, 0.8); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 0.35rem; font-size: 0.72rem;
}
.pad.locked { opacity: 0.72; }
.pad.selected { outline: 2px solid var(--gold); outline-offset: -2px; }
.pad.empty-slot .ghost-name { display: grid; place-items: center; height: 100%; color: var(--gold); font-size: 0.78rem; padding: 0.2rem; text-align: center; }

#toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  margin: 0; padding: 0.55rem 0.9rem; background: #3a1d1a; color: white;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

@media (min-width: 900px) {
  .card { left: auto; width: 360px; top: 68px; bottom: 12px; max-height: none; }
  #baseView .card { top: 12px; }
  .hint { display: none; }
}
@media (max-width: 720px) {
  header { align-items: flex-start; flex-wrap: wrap; }
  .resources { width: 100%; justify-content: flex-start; }
  h1 { font-size: 2.4rem; }
}
