:root {
  --bg: #0e1411;
  --panel: #17211b;
  --panel-2: #1e2b23;
  --line: #2d3d32;
  --text: #e8f0e8;
  --muted: #9fb3a4;
  --accent: #d9a441;
  --danger: #d96b5f;
  --good: #6fbf73;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 700px at 20% -10%, #1d2b22 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 20, 17, 0.86);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.mark {
  font-family: Georgia, "Songti SC", serif;
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--accent);
}
.sub { color: var(--muted); font-size: 12px; letter-spacing: 1px; }

.status { color: var(--muted); font-size: 13px; text-align: center; }
.status b { color: var(--text); }
.controls { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.controls label { color: var(--muted); font-size: 12px; display: flex; gap: 5px; align-items: center; }
select, button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #1d1608; border-color: var(--accent); font-weight: 700; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  padding: 16px 22px 28px;
  max-width: 1580px;
  margin: 0 auto;
}

.board-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.board {
  display: grid;
  gap: 4px;
  width: 100%;
  height: clamp(380px, 68vh, 760px);
  grid-auto-rows: minmax(0, 1fr);
}

.tile {
  position: relative;
  min-height: 0;
  border: 1px solid #223026;
  border-radius: 6px;
  background: #1a251e;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: transform 80ms ease, border-color 80ms ease;
}
.tile:hover { transform: translateY(-1px); border-color: #6f8a74; }
.tile.selected { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 2; }
.tile.water { background: #14252b; color: #6ea3ad; }
.tile.damaged::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(135deg, rgba(217, 107, 95, 0.32) 0 6px, transparent 6px 12px);
  pointer-events: none;
}
.tile .glyph { position: absolute; left: 5px; bottom: 3px; font-size: 13px; color: #91a595; }
.tile .owner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, "Songti SC", serif;
  font-size: 15px;
  font-weight: 700;
  color: rgba(255,255,255,0.82);
  text-shadow: 0 1px 5px rgba(0,0,0,0.5);
}
.tile .yield {
  position: absolute;
  right: 5px;
  top: 3px;
  font-size: 10px;
  color: rgba(255,255,255,0.65);
}
.tile .dmg {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 9px;
  color: #ffb3a8;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
  font-size: 11px;
}
.legend b { color: var(--accent); font-size: 14px; margin-right: 3px; }
.legend .hint { margin-left: auto; }

aside { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.panel h2 {
  margin: 0 0 8px 0;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}

.groups { display: flex; flex-direction: column; gap: 7px; max-height: 250px; overflow: auto; }
.group {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 7px;
  background: rgba(255,255,255,0.02);
  border: 1px solid transparent;
}
.group.current { border-color: var(--accent); background: rgba(217,164,65,0.08); }
.group.dead { opacity: 0.45; }
.group .dot { width: 10px; height: 10px; border-radius: 3px; }
.group .name { font-size: 12px; font-weight: 600; }
.group .meta { color: var(--muted); font-size: 10px; margin-top: 2px; }
.group .score { font-size: 12px; color: var(--accent); font-weight: 700; }

.tileinfo { color: var(--muted); font-size: 12px; line-height: 1.55; }
.tileinfo b { color: var(--text); }

.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.actions button { padding: 8px 6px; font-size: 12px; }
.actions .techrow { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; }
.actions .techrow select { flex: 1; }
.actions .hint { grid-column: 1 / -1; color: var(--muted); font-size: 11px; line-height: 1.4; }

.log { max-height: 230px; overflow: auto; display: flex; flex-direction: column; gap: 5px; }
.log-entry { font-size: 11px; line-height: 1.4; color: var(--muted); border-left: 2px solid var(--line); padding-left: 7px; }
.log-entry b { color: var(--text); font-weight: 600; }
.log-entry.destroy { border-left-color: var(--danger); }
.log-entry.deal { border-left-color: var(--good); }
.log-entry.encounter { border-left-color: var(--accent); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 6, 0.72);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(560px, 96vw);
  background: #1b2820;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 80px rgba(0,0,0,0.5);
}
.modal-card h2 { margin: 0 0 10px 0; font-family: Georgia, "Songti SC", serif; color: var(--accent); }
.modal-card p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-actions button { padding: 8px 14px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.offer-label { color: var(--text); font-size: 14px; margin: 8px 0; }
.offer-label b { color: var(--accent); font-size: 22px; }

/* ------------------------------------------------------------------ */
/* start / setup screen                                                */
/* ------------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(217,164,65,0.10);
  border: 1px solid rgba(217,164,65,0.35);
  color: var(--accent);
  font-size: 11px;
  white-space: nowrap;
}
.start-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 600px at 18% 8%, rgba(92, 132, 95, 0.20), transparent 60%),
    radial-gradient(900px 600px at 88% 90%, rgba(217, 164, 65, 0.10), transparent 60%),
    rgba(7, 12, 9, 0.94);
  overflow: auto;
}
.start-screen.hidden { display: none; }
.hidden { display: none !important; }
.start-card {
  width: min(1040px, 100%);
  background: linear-gradient(160deg, rgba(30, 43, 35, 0.98), rgba(17, 26, 21, 0.98));
  border: 1px solid #3a4d3e;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 40px 120px rgba(0,0,0,0.55), inset 0 1px rgba(255,255,255,0.06);
}
.start-hero {
  display: flex;
  gap: 24px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}
.crest {
  width: 96px;
  height: 112px;
  position: relative;
  flex: 0 0 auto;
  filter: drop-shadow(0 14px 20px rgba(0,0,0,0.45));
}
.crest::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, #e1b45a, #9a6a1f 55%, #5d3f13);
  clip-path: polygon(50% 0, 94% 16%, 94% 62%, 50% 100%, 6% 62%, 6% 16%);
  border-radius: 8px;
}
.crest::after {
  content: "";
  position: absolute;
  inset: 7px;
  background: linear-gradient(160deg, #22352a, #101a14);
  clip-path: polygon(50% 0, 94% 16%, 94% 62%, 50% 100%, 6% 62%, 6% 16%);
}
.crest-inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  font-family: Georgia, "Songti SC", serif;
  font-size: 38px;
  color: #f0cf86;
  text-shadow: 0 2px 0 #6b4a15, 0 0 22px rgba(240,207,134,0.35);
}
.crest-glow {
  position: absolute;
  width: 120px;
  height: 30px;
  left: -12px;
  bottom: -8px;
  background: radial-gradient(ellipse, rgba(217,164,65,0.35), transparent 70%);
  filter: blur(8px);
}
.eyebrow {
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--accent);
  text-transform: uppercase;
}
.hero-copy h1 {
  margin: 4px 0 8px 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: 44px;
  letter-spacing: 8px;
  line-height: 1;
}
.hero-copy h1 span {
  font-size: 18px;
  letter-spacing: 3px;
  color: var(--muted);
  font-family: "Segoe UI", sans-serif;
  margin-left: 8px;
}
.hero-copy p {
  margin: 0;
  max-width: 650px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}
.start-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 22px;
}
.setup-block {
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.setup-block h2 {
  margin: 0 0 12px 0;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}
.setup-block h2 .optional {
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: none;
  margin-left: 6px;
}
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed rgba(255,255,255,0.06);
}
.field label { color: var(--text); font-size: 12px; }
.field select, .field input[type="number"] { width: 110px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 28px; height: 28px; padding: 0;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
}
.stepper span {
  width: 26px;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
}
.note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
  margin: 10px 0 0 0;
}
.key-note { color: #c9b98e; }
.providers { display: flex; flex-direction: column; gap: 9px; margin-bottom: 10px; }
.provider-row {
  background: rgba(0,0,0,0.18);
  border: 1px solid #33463a;
  border-radius: 9px;
  padding: 10px;
}
.provider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.provider-head .provider-title {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 1px;
}
.provider-head .remove {
  background: transparent;
  border: 0;
  color: var(--danger);
  font-size: 16px;
  padding: 0 4px;
}
.provider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.provider-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
}
.provider-grid input, .provider-grid select {
  width: 100%;
  padding: 6px 7px;
  font-size: 11px;
}
.provider-grid .wide { grid-column: 1 / -1; }
.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
}
.switch input { display: none; }
.switch .slider {
  width: 38px; height: 20px;
  border-radius: 999px;
  background: #2a3a2e;
  border: 1px solid #3b5142;
  position: relative;
  transition: background 120ms ease;
}
.switch .slider::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  top: 2px; left: 2px;
  background: #9fb3a4;
  transition: transform 120ms ease, background 120ms ease;
}
.switch input:checked + .slider { background: rgba(217,164,65,0.28); }
.switch input:checked + .slider::after { transform: translateX(18px); background: var(--accent); }
button.ghost {
  background: transparent;
  border: 1px dashed #4b604f;
  color: var(--muted);
  width: 100%;
}
button.ghost:hover { color: var(--accent); border-color: var(--accent); }
.start-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
button.big { padding: 11px 28px; font-size: 14px; letter-spacing: 2px; }
.start-actions .ghost { width: auto; padding: 9px 16px; }
.start-error {
  color: #ffb3a8;
  font-size: 12px;
  line-height: 1.5;
  flex: 1;
}

/* ------------------------------------------------------------------ */
/* 3D-ish tiles                                                       */
/* ------------------------------------------------------------------ */
.board { perspective: 1200px; }
.tile {
  box-shadow:
    inset 0 1px rgba(255,255,255,0.10),
    inset 0 -3px rgba(0,0,0,0.22),
    0 4px 0 #0a110d,
    0 7px 12px rgba(0,0,0,0.28);
  transform: translateZ(0);
}
.tile:hover { transform: translateY(-2px) translateZ(4px); }
.tile.selected {
  transform: translateY(-3px) translateZ(8px) scale(1.015);
  box-shadow:
    inset 0 1px rgba(255,255,255,0.18),
    0 5px 0 #0a110d,
    0 0 0 2px var(--accent),
    0 10px 24px rgba(217,164,65,0.18);
}
.tile .terrain-icon {
  position: absolute;
  left: 50%;
  top: 44%;
  width: 54%;
  height: 54%;
  transform: translate(-50%, -50%);
  opacity: 0.92;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35));
  pointer-events: none;
}
.tile.water .terrain-icon { opacity: 0.85; }
.tile .owner-token {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -58%);
  width: 34px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  font-family: Georgia, "Songti SC", serif;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.4));
  z-index: 2;
}
.tile .owner-token::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--owner);
  background: linear-gradient(145deg, var(--owner), color-mix(in srgb, var(--owner) 55%, #000));
  clip-path: polygon(50% 0, 100% 18%, 100% 62%, 50% 100%, 0 62%, 0 18%);
  border-radius: 3px;
  box-shadow: inset 0 2px rgba(255,255,255,0.25);
}
.tile .owner-token span { position: relative; z-index: 1; }
.tile .resource-gem {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 9px; height: 9px;
  background: linear-gradient(135deg, #f0d58a, #b3832e);
  transform: rotate(45deg);
  box-shadow: 0 0 6px rgba(217,164,65,0.5);
  border-radius: 1px;
}
.tile .yield {
  right: 16px;
  top: 3px;
}
.tile .ruin-mark {
  position: absolute;
  left: 5px;
  top: 4px;
  color: #ff9d8e;
  font-size: 11px;
  z-index: 3;
}

@media (max-width: 980px) {
  .start-grid { grid-template-columns: 1fr; }
  .start-card { padding: 20px; }
  .start-hero { align-items: flex-start; }
  .crest { width: 72px; height: 84px; }
  .hero-copy h1 { font-size: 34px; }
  header { grid-template-columns: 1fr; gap: 8px; }
  .status { text-align: left; }
  .controls { justify-content: flex-start; }
  main { grid-template-columns: 1fr; padding: 12px; }
  .board { height: 58vh; min-height: 340px; }
  aside { order: 2; }
}

/* ------------------------------------------------------------------ */
/* room create / join / lobby                                          */
/* ------------------------------------------------------------------ */
.start-card { width: min(1080px, 100%); }
.start-grid { grid-template-columns: 1fr 1fr; }
.setup-block .field input[type="text"],
.setup-block .field input[type="number"],
.setup-block .field select {
  width: 150px;
}
.setup-block .field input.room-input {
  width: 150px;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 700;
  color: var(--accent);
}
.setup-block > button.big {
  width: 100%;
  margin-top: 14px;
}
.server-ai {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid rgba(111, 160, 122, 0.28);
  border-radius: 8px;
  background: rgba(95, 145, 105, 0.07);
}
.server-ai.small { margin-top: 18px; }
.server-ai b { font-size: 11px; color: #cfe3d1; }
.server-ai .note { margin-top: 3px; }
.ai-dot {
  width: 8px; height: 8px;
  margin-top: 4px;
  border-radius: 50%;
  background: #7fc98b;
  box-shadow: 0 0 8px rgba(127, 201, 139, 0.55);
  flex: 0 0 auto;
}
.lobby-card {
  width: min(620px, 100%);
  padding: 30px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(30, 43, 35, 0.99), rgba(15, 24, 19, 0.99));
  border: 1px solid #3a4d3e;
  box-shadow: 0 40px 120px rgba(0,0,0,0.55);
}
.lobby-card h1 {
  margin: 4px 0 8px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 30px;
  letter-spacing: 2px;
}
.lobby-card h1 span { color: var(--accent); letter-spacing: 5px; }
.room-code-wrap {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0;
  padding: 14px;
  border: 1px dashed #4b604f;
  border-radius: 10px;
  background: rgba(0,0,0,0.18);
}
.room-code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 30px;
  letter-spacing: 8px;
  color: var(--accent);
  font-weight: 700;
}
.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 16px 0;
}
.player-pill {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid #33463a;
  border-radius: 8px;
  background: rgba(255,255,255,0.025);
  font-size: 12px;
}
.player-pill .tag { color: var(--accent); font-size: 10px; }
.player-pill.empty { color: var(--muted); border-style: dashed; }
.lobby-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.lobby-actions .ghost { width: auto; padding: 9px 18px; }
.room-code-wrap .ghost { width: auto; white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* more room for the board + non-overlapping tile badges               */
/* ------------------------------------------------------------------ */
main { grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; }
.board { height: clamp(420px, calc(100vh - 220px), 880px); gap: 3px; }
.controls { flex-wrap: wrap; }
.controls button.ghost { width: auto; padding: 7px 12px; }
.tile .terrain-icon {
  top: 40%;
  width: 52%;
  height: 52%;
  opacity: 0.88;
}
.tile .owner-token {
  left: 4px;
  bottom: 2px;
  top: auto;
  transform: none;
  width: auto;
  min-width: 28px;
  max-width: calc(100% - 30px);
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 9px;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
}
.tile .owner-token::before {
  clip-path: none;
  border-radius: 4px;
  inset: 0;
}
.tile .owner-token span { font-size: 9px; }
.tile .yield {
  top: 2px;
  right: 14px;
  font-size: 9px;
}
.tile .resource-gem {
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
}
.tile .dmg {
  right: 4px;
  bottom: 2px;
  font-size: 8px;
}
.tile .ruin-mark { font-size: 10px; top: 3px; left: 4px; }

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  .start-grid { grid-template-columns: 1fr; }
  .board { height: 58vh; }
  .room-code { font-size: 24px; letter-spacing: 5px; }
  .lobby-actions { flex-direction: column; }
  .lobby-actions button { width: 100%; }
}

