:root {
  --ink: #171512;
  --panel: rgba(24, 20, 15, 0.74);
  --panel-border: rgba(221, 191, 147, 0.42);
  --sand: #d5b787;
  --gold: #dcb068;
  --bronze: #7d5232;
  --steel: #c8c9c2;
  --ally: #5e8fb7;
  --enemy: #b25b4f;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  color: #eee7d8;
  background: #0f0f0f;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(1400px 500px at 50% -8%, rgba(188, 201, 210, 0.7), rgba(76, 87, 97, 0.2) 50%, transparent 80%),
    linear-gradient(180deg, #596875 0%, #6e7f8b 23%, #4e584f 24%, #333b31 100%);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

#hud-top {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  width: min(980px, calc(100% - 28px));
  pointer-events: none;
}

.stat {
  min-width: 120px;
  padding: 6px 10px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(43, 35, 27, 0.9), rgba(22, 17, 12, 0.72));
  box-shadow: 0 0 0 1px rgba(16, 14, 10, 0.75), inset 0 2px 0 rgba(244, 221, 182, 0.1);
}

.stat.wide {
  flex: 1;
}

.label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: #baa27f;
}

#hud-top .stat span:last-child {
  font-size: 18px;
  color: #f4e8d5;
}

#panel {
  position: absolute;
  left: 14px;
  bottom: 12px;
  width: clamp(286px, 26vw, 350px);
  max-height: calc(100vh - 24px);
  padding: 10px 10px 9px;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(223, 186, 133, 0.38);
  background:
    linear-gradient(180deg, rgba(40, 31, 23, 0.9), rgba(23, 18, 13, 0.78)),
    repeating-linear-gradient(90deg, rgba(191, 161, 114, 0.03) 0 2px, transparent 2px 4px);
  box-shadow:
    0 7px 24px rgba(0, 0, 0, 0.33),
    inset 0 0 0 1px rgba(14, 12, 9, 0.75);
  transition: padding 140ms ease, width 160ms ease, background 160ms ease;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#panelToggle {
  border: 1px solid rgba(200, 170, 123, 0.6);
  background: linear-gradient(180deg, rgba(86, 62, 39, 0.96), rgba(56, 40, 24, 0.96));
  color: #f2e7cf;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  cursor: pointer;
}

#panelToggle:hover {
  filter: brightness(1.08);
}

#panelBody {
  margin-top: 6px;
  overflow-y: auto;
  max-height: calc(100vh - 104px);
  padding-right: 3px;
}

#panel.collapsed {
  width: auto;
  max-width: calc(100% - 24px);
  max-height: none;
  padding: 8px 9px;
}

#panel.collapsed .panel-head {
  min-width: 220px;
}

#panel.collapsed #panelBody {
  display: none;
}

#panel.collapsed h1 {
  margin: 0;
  font-size: 17px;
}

#panel h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
  color: #eadfc4;
}

#panel h2 {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #d2be9a;
}

#panel p {
  margin: 0 0 6px;
  line-height: 1.25;
  color: #e6dbc6;
}

#selectionText {
  font-size: 11px;
}

#trainingPanel {
  margin-top: 6px;
  padding: 7px 8px 6px;
  border: 1px solid rgba(211, 174, 122, 0.22);
  background: rgba(17, 13, 10, 0.45);
}

#structurePanel {
  margin-top: 6px;
  padding: 7px 8px 6px;
  border: 1px solid rgba(211, 174, 122, 0.22);
  background: rgba(17, 13, 10, 0.45);
}

#settingsPanel {
  margin-top: 6px;
  padding: 0;
  border: none;
  background: transparent;
}

.foldable {
  margin-top: 6px;
}

.foldable > summary,
#settingsFold > summary {
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #d2be9a;
  padding: 5px 8px;
  list-style: none;
}

#settingsFold,
#helpFold {
  border: 1px solid rgba(211, 174, 122, 0.22);
  background: rgba(17, 13, 10, 0.45);
}

#settingsFold > summary::-webkit-details-marker,
#helpFold > summary::-webkit-details-marker {
  display: none;
}

#settingsFold[open] > summary,
#helpFold[open] > summary {
  border-bottom: 1px solid rgba(211, 174, 122, 0.18);
  margin-bottom: 6px;
}

.settings-body {
  padding: 0 8px 8px;
}

#helpFold {
  padding-bottom: 2px;
}

#helpFold[open] {
  padding-bottom: 6px;
}

#helpFold > summary {
  padding-left: 8px;
}

#tipText {
  margin-top: 2px;
  padding: 0 8px 0;
  font-size: 10px;
  color: #cdb690;
}

#settingsFold > summary::before,
#helpFold > summary::before {
  content: "+";
  display: inline-block;
  width: 12px;
  margin-right: 6px;
  color: #d9bb8c;
}

#settingsFold[open] > summary::before,
#helpFold[open] > summary::before {
  content: "−";
}

#settingsFold {
  margin: 0;
}

#settingsPanel .setting-line {
  margin: 0 0 5px;
  font-size: 11px;
}

#settingsPanel .setting-check {
  gap: 6px;
}

#settingsPanel .setting-line input[type="text"],
#settingsPanel .setting-line input[type="password"],
#settingsPanel .setting-line input[type="number"] {
  margin-top: 3px;
  font-size: 11px;
  padding: 4px 5px;
}

#settingsPanel .setting-line input[type="range"] {
  width: 100%;
  margin-top: 3px;
}

.setting-hint {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: #ceb186;
}

#llmSaveBtn {
  width: 100%;
  border: 1px solid rgba(195, 156, 105, 0.5);
  background: linear-gradient(180deg, rgba(100, 67, 40, 0.95), rgba(66, 45, 27, 0.95));
  color: #f2e7cf;
  font-family: inherit;
  font-size: 11px;
  padding: 5px 7px;
  cursor: pointer;
}

#llmSaveBtn:hover {
  filter: brightness(1.08);
}

#llmStatusText {
  margin-top: 5px;
  margin-bottom: 0;
  font-size: 11px;
}

.queue-wrap {
  margin-top: 7px;
  font-size: 11px;
}

#queueLeadText {
  margin-top: 3px;
  font-size: 11px;
}

.queue-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
  max-height: 54px;
  overflow: auto;
  padding-right: 2px;
}

.queue-badge {
  display: inline-block;
  border: 1px solid rgba(201, 167, 117, 0.42);
  background: rgba(74, 52, 33, 0.75);
  color: #efdec0;
  font-size: 10px;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  white-space: nowrap;
}

.queue-badge.empty {
  opacity: 0.75;
}

.train-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.train-buttons button {
  border: 1px solid rgba(195, 156, 105, 0.5);
  background: linear-gradient(180deg, rgba(100, 67, 40, 0.95), rgba(66, 45, 27, 0.95));
  color: #f2e7cf;
  font-family: inherit;
  font-size: 11px;
  padding: 5px 4px 4px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.train-buttons button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.train-buttons button:active {
  transform: translateY(0);
}

.train-buttons button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
  filter: grayscale(0.35);
}

.train-buttons button small {
  display: block;
  margin-top: 2px;
  font-size: 9px;
  color: #ddc193;
}

#buildTrainingCenterBtn {
  width: 100%;
  border: 1px solid rgba(195, 156, 105, 0.5);
  background: linear-gradient(180deg, rgba(100, 67, 40, 0.95), rgba(66, 45, 27, 0.95));
  color: #f2e7cf;
  font-family: inherit;
  font-size: 11px;
  padding: 6px 6px 5px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

#buildTrainingCenterBtn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

#buildTrainingCenterBtn:active {
  transform: translateY(0);
}

#buildTrainingCenterBtn:disabled {
  cursor: not-allowed;
  opacity: 0.44;
  filter: grayscale(0.35);
}

#buildTrainingCenterBtn small {
  display: block;
  font-size: 9px;
  color: #ddc193;
}

#centerInfo {
  margin-top: 5px;
  font-size: 11px;
}

.setting-line {
  display: block;
  margin: 0 0 7px;
  font-size: 12px;
  color: #d7c29f;
}

.setting-check {
  display: flex;
  align-items: center;
  gap: 7px;
}

.setting-line input[type="text"],
.setting-line input[type="password"],
.setting-line input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  border: 1px solid rgba(195, 156, 105, 0.42);
  background: rgba(32, 25, 18, 0.86);
  color: #f1e5cf;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 6px;
}

#announce {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translate(-50%, -50%);
  min-width: 240px;
  max-width: min(72vw, 700px);
  text-align: center;
  padding: 8px 12px;
  font-size: 24px;
  letter-spacing: 0.03em;
  color: #fff6e5;
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.65);
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

#announce.show {
  opacity: 1;
}

@media (max-width: 900px) {
  #hud-top {
    gap: 6px;
    width: calc(100% - 14px);
  }

  .stat {
    min-width: 74px;
    padding: 5px 7px;
  }

  #hud-top .stat span:last-child {
    font-size: 14px;
  }

  #panel {
    left: 7px;
    bottom: 7px;
    width: min(330px, calc(100% - 14px));
    max-height: calc(100vh - 14px);
    padding: 9px 8px;
  }

  #panelBody {
    max-height: calc(100vh - 95px);
  }

  #panel.collapsed {
    width: auto;
    max-width: calc(100% - 14px);
  }

  #panel.collapsed .panel-head {
    min-width: 190px;
  }

  #panel h1 {
    font-size: 17px;
  }

  .train-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
