:root {
  color-scheme: dark;
  --bg: #120f0b;
  --panel: #211a12;
  --panel-2: #2a2117;
  --line: #604725;
  --line-soft: #3d2e1b;
  --gold: #d5a54a;
  --gold-bright: #efd084;
  --ink: #ecddbd;
  --muted: #aa9979;
  --green: #74b581;
  --red: #d57562;
  --blue: #6ca9ba;
  --shadow: 0 24px 80px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 75% 0, rgba(103, 67, 28, .34), transparent 32rem),
    linear-gradient(180deg, #17120c, var(--bg));
  color: var(--ink);
  font: 14px/1.55 system-ui, "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font: 700 30px/1.25 Georgia, "STSong", serif; }
h2 { margin-bottom: 6px; font-size: 23px; }
h3 { margin-bottom: 10px; font-size: 17px; }
code { color: var(--gold-bright); }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(12, 9, 6, .68), rgba(12, 9, 6, .92)),
    repeating-linear-gradient(120deg, transparent 0 14px, rgba(210, 166, 76, .03) 14px 15px);
}
.login-card {
  width: min(460px, 100%);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(34, 26, 17, .96);
  box-shadow: var(--shadow);
  position: relative;
}
.seal {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border: 2px solid #a64632;
  color: #d4765d;
  font: 700 18px/1.1 "STKaiti", serif;
  transform: rotate(-5deg);
}

label {
  display: block;
  margin: 16px 0 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
input, textarea, select {
  width: 100%;
  border: 1px solid #5b4527;
  border-radius: 9px;
  outline: 0;
  background: #120e09;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input, select { height: 42px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(213, 165, 74, .12);
}
button {
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #241606;
  background: var(--gold);
  font-weight: 750;
}
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: wait; }
button.ghost {
  color: var(--ink);
  border-color: var(--line-soft);
  background: #241c13;
}
button.danger {
  color: #fff;
  border-color: #7c382e;
  background: #713429;
}
button.small { min-height: 32px; padding: 5px 10px; font-size: 12px; }
button.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-size: 23px;
}
.primary { background: linear-gradient(180deg, #e0b45e, #bd8932); }
.message { min-height: 22px; margin: 14px 0 0; color: var(--muted); }
.message.error, .error { color: #ff9d88 !important; }
.message.ok, .ok { color: #98dca4 !important; }

.app { min-height: 100vh; }
.topbar {
  height: 72px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(20, 15, 10, .94);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); }
.mini-seal {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #9c4d39;
  color: #da785f;
  font: 700 16px "STKaiti", serif;
}
.top-actions { display: flex; align-items: center; gap: 10px; }
.save-state { color: var(--green); font-size: 12px; }
.save-state.dirty { color: #e4bd6b; }

.layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar {
  padding: 18px 14px;
  border-right: 1px solid var(--line-soft);
  background: rgba(25, 19, 13, .72);
}
.nav {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 4px;
  padding: 11px 12px;
  color: var(--muted);
  border: 0;
  background: transparent;
  text-align: left;
  font-weight: 650;
}
.nav span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  color: #c6a86a;
  font-size: 12px;
}
.nav:hover { color: var(--ink); background: rgba(213, 165, 74, .06); }
.nav.active {
  color: var(--gold-bright);
  background: linear-gradient(90deg, rgba(213, 165, 74, .16), transparent);
}
.nav.active span { border-color: var(--gold); }
.nav.subtle { margin-top: 24px; color: #82755e; }
.view { min-width: 0; padding: 28px; outline: none; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.page-head p { margin-bottom: 0; color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  padding: 19px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(42, 33, 23, .94), rgba(29, 23, 16, .94));
  box-shadow: 0 12px 35px rgba(0, 0, 0, .16);
}
.stat strong { display: block; margin: 8px 0 2px; font: 700 30px/1 Georgia, serif; color: var(--gold-bright); }
.stat small { color: var(--muted); }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--muted);
  background: #17120d;
  font-size: 12px;
}
.pill.gold { color: var(--gold-bright); border-color: #715628; }
.divider { height: 1px; margin: 20px 0; background: var(--line-soft); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field-hint { margin: -2px 0 10px; color: #85775f; font-size: 12px; }
.input-unit { position: relative; }
.input-unit input { padding-right: 54px; }
.input-unit span { position: absolute; right: 12px; top: 11px; color: var(--muted); font-size: 12px; }

.list-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; }
.item-list { display: grid; gap: 8px; align-content: start; }
.list-item {
  width: 100%;
  padding: 12px;
  color: var(--ink);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #1c1610;
  text-align: left;
}
.list-item small { display: block; margin-top: 3px; color: var(--muted); }
.list-item.active { border-color: var(--gold); background: rgba(213, 165, 74, .1); }

.map-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.map-picker button { color: var(--ink); border-color: var(--line-soft); background: #211a12; }
.map-picker button.active { color: #251706; border-color: var(--gold); background: var(--gold); }
.map-workspace { display: grid; grid-template-columns: minmax(360px, 1fr) 260px; gap: 18px; }
.map-wrap { overflow: auto; padding: 8px; }
.map-grid {
  width: min(100%, 620px);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d0b08;
}
.map-cell {
  aspect-ratio: 4 / 5;
  min-height: 42px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, .12);
  color: rgba(255, 255, 255, .74);
  font-size: 11px;
}
.map-cell.road { background: #cfb98c; color: #2c2114; }
.map-cell.deploy { background: #76a990; color: #10231a; }
.map-cell.grass { background: #765b4d; }
.map-cell.empty { background: #393126; }
.map-cell.start { box-shadow: inset 0 0 0 3px #e2ac4c; }
.map-cell.base { box-shadow: inset 0 0 0 3px #ce6351; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.legend i { width: 10px; height: 10px; display: inline-block; border-radius: 2px; margin-right: 5px; }
.tool-row { display: grid; gap: 8px; }
.tool-row button { color: var(--ink); border-color: var(--line-soft); background: #241c13; text-align: left; }
.tool-row button.active { color: #261707; background: var(--gold); }

.wave-list { display: grid; gap: 10px; margin-top: 12px; }
.wave-card { padding: 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: #17120d; }
.wave-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.wave-head strong { margin-right: auto; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; min-height: 30px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border: 1px solid #5f4929; border-radius: 999px; background: #241b11; }
.chip button { width: 19px; min-height: 19px; padding: 0; border-radius: 50%; color: var(--muted); background: transparent; }
.add-enemy { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; margin-top: 9px; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px 9px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-size: 12px; font-weight: 650; }
.data-table input, .data-table select { height: 36px; }
.data-table .number { width: 92px; }
.table-wrap { overflow-x: auto; }
.table-card { padding: 8px; }
.empty-state { padding: 52px 24px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 12px; }

.notice {
  padding: 12px 14px;
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  background: rgba(213, 165, 74, .08);
  color: #d5c5a5;
}
.notice.warn { border-color: #d7775f; background: rgba(215, 119, 95, .08); }
.json-editor { min-height: 64vh; font: 12px/1.6 Consolas, monospace; tab-size: 2; }
.history-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.history-row:last-child { border-bottom: 0; }

.dialog {
  width: min(620px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(6, 4, 2, .78); backdrop-filter: blur(4px); }
.dialog form { padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; gap: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.publish-summary {
  margin: 18px 0;
  padding: 13px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  color: var(--muted);
  background: #17120d;
}
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: 380px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #241b12;
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .grid.four, .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-workspace { grid-template-columns: 1fr; }
  .list-layout { grid-template-columns: 210px minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .topbar { height: auto; min-height: 68px; padding: 12px 14px; align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .save-state { width: 100%; text-align: right; }
  .layout { display: block; }
  .sidebar {
    position: sticky;
    top: 68px;
    z-index: 15;
    display: flex;
    overflow-x: auto;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    background: #17120d;
  }
  .nav { width: auto; min-width: max-content; margin: 0 3px 0 0; padding: 8px 10px; }
  .nav span, .nav.subtle { display: none; }
  .view { padding: 18px 14px 40px; }
  .grid.two, .grid.three, .grid.four, .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .list-layout { grid-template-columns: 1fr; }
  .item-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head { display: block; }
  .history-row { grid-template-columns: 1fr; }
}
