:root {
  --paper: #f4f1e7;
  --paper-deep: #e6dfcf;
  --paper-soft: rgba(250, 248, 240, 0.9);
  --ink: #202624;
  --ink-soft: #59615d;
  --wash: #d8d5c8;
  --line: #b9b1a1;
  --moss: #3f665b;
  --moss-dark: #263f3a;
  --seal: #a43d2b;
  --indigo: #3d526d;
  --shadow: 0 12px 28px rgba(33, 31, 26, 0.1);
  color-scheme: light;
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgba(40, 37, 31, 0.035) 0 1px, transparent 1px 11px),
    repeating-linear-gradient(90deg, rgba(40, 37, 31, 0.025) 0 1px, transparent 1px 17px),
    var(--paper);
}

button {
  border: 1px solid var(--line);
  border-radius: 4px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease,
    opacity 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.game-shell {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 16px 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0 10px;
}

.kicker {
  margin: 0 0 2px;
  color: var(--seal);
  font-size: 0.72rem;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: "KaiTi", "STKaiti", "Microsoft YaHei", serif;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 0.96rem;
  line-height: 1.2;
}

.top-controls,
.top-actions,
.speed-control,
.speed-options,
.strategy-control,
.strategy-options {
  display: flex;
  align-items: center;
}

.top-controls {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top-actions,
.speed-options,
.strategy-options {
  gap: 5px;
}

.speed-control,
.strategy-control {
  gap: 7px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(250, 248, 240, 0.72);
}

.speed-control > span,
.strategy-control > span {
  padding: 0 3px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.speed-button,
.strategy-button {
  min-width: 40px;
  height: 28px;
  padding: 0 7px;
  background: #eee9dc;
  font-weight: 850;
}

.speed-button.active,
.strategy-button.active,
.auto-button.active,
.icon-button.active,
.tab.active {
  color: #fffdf5;
  background: var(--moss-dark);
  border-color: var(--moss-dark);
}

.auto-button {
  height: 40px;
  min-width: 112px;
  padding: 0 12px;
  background: #eee9dc;
  font-weight: 850;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  background: #f9f5ea;
  font-weight: 850;
}

.icon-button.danger {
  color: var(--seal);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.status-strip div {
  min-width: 0;
  padding: 8px 11px;
  background: rgba(251, 248, 239, 0.9);
}

.status-strip span,
.resource-meta,
.cost-line,
.item-note,
.need-list {
  color: var(--ink-soft);
  font-size: 0.73rem;
}

.status-strip strong {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overview-grid,
.play-grid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.overview-grid {
  grid-template-columns: minmax(460px, 1.35fr) minmax(330px, 0.95fr) minmax(300px, 0.75fr);
  align-items: stretch;
}

.play-grid {
  grid-template-columns: minmax(0, 1.72fr) minmax(280px, 0.58fr);
}

.scene-wrap,
.era-panel,
.log-panel,
.goal-panel,
.jobs-panel,
.random-event-panel,
.exploration-panel,
.resource-panel,
.action-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper-soft);
  box-shadow: var(--shadow);
}

.scene-wrap {
  position: relative;
  overflow: hidden;
  min-height: 178px;
  background:
    linear-gradient(180deg, rgba(227, 229, 222, 0.9), rgba(241, 237, 224, 0.96)),
    var(--paper-deep);
}

.scene-wrap::after {
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(70, 64, 54, 0.18);
  content: "";
  pointer-events: none;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
}

.era-panel,
.log-panel,
.goal-panel,
.jobs-panel,
.random-event-panel,
.exploration-panel,
.resource-panel,
.action-panel {
  padding: 10px;
}

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

.section-heading.compact {
  margin-bottom: 8px;
}

#advanceEra {
  min-width: 92px;
  padding: 8px 10px;
  color: #fffdf5;
  background: var(--seal);
  border-color: #7e2e21;
  font-weight: 850;
}

.ghost {
  padding: 5px 8px;
  background: transparent;
}

.progress-track {
  height: 8px;
  margin: 10px 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #d7d0c1;
}

.progress-track.small {
  grid-column: 1 / -1;
  height: 6px;
  margin: 3px 0 0;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--moss), var(--seal));
}

.need-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.need-list li {
  min-width: 0;
}

.event-log {
  display: grid;
  gap: 6px;
  max-height: 258px;
  padding: 0 4px 0 18px;
  margin: 0;
  overflow: auto;
  color: #333b38;
  font-size: 0.82rem;
  line-height: 1.45;
}

.side-stack {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  gap: 10px;
  min-height: 0;
}

.side-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
}

.side-tab {
  min-height: 32px;
  padding: 6px 4px;
  background: #eee9dc;
  font-size: 0.82rem;
  font-weight: 850;
}

.side-tab.active {
  color: #fffdf5;
  background: var(--moss-dark);
  border-color: var(--moss-dark);
}

.side-page {
  display: none;
}

.side-page.active {
  display: block;
  max-height: calc(100vh - 328px);
  min-height: 260px;
  overflow: auto;
}

.small-mark {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(255, 253, 245, 0.55);
  font-size: 0.72rem;
  font-weight: 850;
}

.goal-card {
  display: grid;
  gap: 7px;
}

.random-event-card {
  display: grid;
  gap: 8px;
}

.exploration-card,
.exploration-list {
  display: grid;
  gap: 8px;
}

.goal-title {
  font-weight: 900;
}

.goal-desc,
.job-row p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.42;
}

.goal-progress-list {
  display: grid;
  gap: 6px;
}

.goal-progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.goal-progress-row strong {
  color: var(--ink);
}

.job-list {
  display: grid;
  gap: 6px;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 7px;
  border: 1px solid #cbc3b4;
  border-radius: 5px;
  background: rgba(255, 253, 245, 0.58);
}

.job-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}

.job-title span {
  color: var(--seal);
  font-size: 0.72rem;
  font-weight: 850;
  white-space: nowrap;
}

.job-buttons {
  display: grid;
  grid-template-columns: repeat(2, 30px);
  gap: 4px;
  align-self: center;
}

.job-buttons .ghost {
  min-height: 28px;
  padding: 0;
  font-weight: 900;
}

.mini-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 7px;
}

.event-choice-list {
  display: grid;
  gap: 6px;
}

.event-choice {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 8px;
  text-align: left;
  background: rgba(255, 253, 245, 0.68);
}

.event-choice strong {
  font-size: 0.84rem;
}

.event-choice span {
  color: var(--ink-soft);
  font-size: 0.74rem;
  line-height: 1.35;
}

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

.resource-card {
  min-width: 0;
  padding: 7px;
  border: 1px solid #cbc3b4;
  border-radius: 5px;
  background: rgba(255, 253, 245, 0.75);
}

.resource-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 0.8rem;
  font-weight: 850;
}

.resource-icon {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 4px;
  color: #fffdf5;
  background: var(--indigo);
  font-size: 0.64rem;
}

.resource-value {
  font-size: 0.95rem;
  font-weight: 850;
  line-height: 1.15;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
  margin-bottom: 8px;
}

.tab {
  min-height: 32px;
  padding: 6px;
  background: #eee9dc;
  font-weight: 850;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: calc(100vh - 328px);
  min-height: 260px;
  overflow: auto;
  padding-right: 2px;
}

.empty-panel {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 5px;
  color: var(--ink-soft);
  background: rgba(255, 253, 245, 0.5);
  font-size: 0.84rem;
}

.action-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
  padding: 9px;
  border: 1px solid #cbc3b4;
  border-radius: 5px;
  background: rgba(255, 253, 245, 0.78);
}

.wide-item {
  grid-column: 1 / -1;
}

.war-summary .progress-track {
  margin-bottom: 0;
}

.battle-fill {
  background: linear-gradient(90deg, var(--seal), #6b5d2e);
}

.item-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-bottom: 3px;
  font-weight: 850;
}

.item-title span:last-child {
  overflow-wrap: anywhere;
}

.item-badge {
  flex: 0 0 auto;
  min-width: 28px;
  padding: 1px 6px;
  border-radius: 999px;
  color: #fffdf5;
  background: var(--indigo);
  font-size: 0.68rem;
  text-align: center;
}

.item-note {
  margin: 0 0 6px;
  line-height: 1.42;
}

.cost-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cost-pill {
  padding: 1px 6px;
  border-radius: 999px;
  background: #e9e2d3;
}

.buy-button {
  align-self: center;
  min-width: 66px;
  padding: 7px 9px;
  color: #fffdf5;
  background: var(--moss);
  border-color: var(--moss-dark);
  font-weight: 850;
}

.button-stack {
  display: grid;
  align-self: center;
  gap: 5px;
  min-width: 66px;
}

.formation-board {
  grid-template-columns: minmax(0, 1fr);
}

.formation-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.formation-button {
  display: grid;
  gap: 3px;
  min-height: 82px;
  padding: 7px;
  text-align: left;
  background: #f5f0e4;
}

.formation-button.active {
  color: #fffdf5;
  background: var(--moss-dark);
  border-color: var(--moss-dark);
  opacity: 1;
}

.formation-button strong,
.formation-button em,
.formation-button small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.formation-button strong {
  font-size: 0.82rem;
}

.formation-button em {
  color: inherit;
  font-size: 0.7rem;
  font-style: normal;
  line-height: 1.35;
  opacity: 0.82;
}

.formation-button small {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  color: inherit;
  font-size: 0.64rem;
  opacity: 0.92;
}

.formation-button small span {
  padding: 1px 5px;
  border: 1px solid rgba(79, 92, 85, 0.22);
  border-radius: 999px;
  background: rgba(255, 253, 245, 0.48);
}

.formation-button.active small span {
  border-color: rgba(255, 253, 245, 0.36);
  background: rgba(255, 253, 245, 0.14);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fbf8ef;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 38, 36, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(560px, 100%);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    repeating-linear-gradient(0deg, rgba(40, 37, 31, 0.035) 0 1px, transparent 1px 11px),
    var(--paper-soft);
  box-shadow: 0 20px 60px rgba(28, 30, 28, 0.26);
}

.field-row {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 0.76rem;
  font-weight: 850;
}

.field-row input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: #fffdf5;
  font: inherit;
}

.cloud-status {
  min-height: 34px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 5px;
  color: var(--ink-soft);
  background: rgba(255, 253, 245, 0.52);
  font-size: 0.78rem;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.modal-actions .buy-button,
.modal-actions .ghost {
  min-height: 34px;
}

@media (max-width: 1180px) {
  .overview-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  }

  .scene-wrap {
    grid-column: 1 / -1;
    min-height: 150px;
  }

  canvas {
    aspect-ratio: 18 / 4;
  }

  .resource-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .game-shell {
    padding: 10px;
  }

  .topbar,
  .top-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .speed-control {
    justify-content: space-between;
  }

  .speed-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }

  .strategy-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }

  .speed-button,
  .strategy-button {
    min-width: 0;
  }

  .status-strip,
  .overview-grid,
  .play-grid,
  .resource-grid,
  .need-list,
  .tab-panel.active {
    grid-template-columns: 1fr;
  }

  .tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .scene-wrap {
    min-height: 126px;
  }

  .tab-panel.active {
    max-height: none;
    min-height: 0;
    overflow: visible;
  }

  .side-page.active {
    max-height: none;
    min-height: 0;
    overflow: visible;
  }

  .action-item {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 520px) {
  .section-heading {
    align-items: flex-start;
  }

  .action-item {
    grid-template-columns: 1fr;
  }

  .buy-button {
    width: 100%;
  }

  .formation-options {
    grid-template-columns: 1fr;
  }
}
