:root {
  color-scheme: light;
  --ink: #202020;
  --muted: #686b73;
  --quiet: #8b9099;
  --paper: #f7f7f2;
  --panel: #ffffff;
  --line: #dcded8;
  --line-strong: #bfc4ba;
  --shadow: 0 18px 48px rgba(19, 22, 28, 0.18);
  --red: #9e2a2b;
  --red-dark: #6f1d1b;
  --gold: #bc8a1b;
  --green: #2f7d55;
  --teal: #0b7a75;
  --blue: #315c96;
  --violet: #665191;
  --charcoal: #252729;
  --charcoal-2: #34373a;
  --radius: 8px;
  --focus: 0 0 0 3px rgba(11, 122, 117, 0.25);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #252729;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(158, 42, 43, 0.09), transparent 24%, transparent 76%, rgba(11, 122, 117, 0.08)),
    repeating-linear-gradient(0deg, #f1f2ed 0, #f1f2ed 28px, #eceee7 28px, #eceee7 29px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

img {
  max-width: 100%;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 68px;
  padding: 10px 18px;
  color: #f8f8f4;
  background: rgba(37, 39, 41, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(10, 10, 12, 0.18);
}

.brand {
  display: inline-grid;
  grid-template-columns: 34px auto;
  gap: 10px;
  align-items: center;
  min-width: 190px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 34px;
  height: 34px;
  image-rendering: auto;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand strong {
  font-size: 1.05rem;
}

.brand small {
  margin-top: 2px;
  color: #cfd3d8;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.nav-button,
.primary-action,
.secondary-action,
.danger-action,
.icon-button,
.text-button {
  min-height: 36px;
  border-radius: 6px;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.nav-button {
  padding: 8px 10px;
  color: #dfe3e6;
  background: transparent;
}

.nav-button:hover,
.nav-button.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.nav-button.locked {
  color: #9ea5aa;
  background: rgba(255, 255, 255, 0.04);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.primary-action,
.secondary-action,
.danger-action,
.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.primary-action {
  padding: 8px 14px;
  color: #ffffff;
  background: var(--red);
}

.primary-action:hover {
  background: var(--red-dark);
}

.secondary-action {
  padding: 8px 12px;
  color: var(--ink);
  background: #e7e9e3;
  border: 1px solid #cfd4cc;
}

.danger-action {
  padding: 8px 12px;
  color: #ffffff;
  background: #5a1e24;
}

.icon-button {
  width: 38px;
  padding: 0;
  color: #f8f8f4;
  background: rgba(255, 255, 255, 0.12);
}

.text-button {
  min-height: auto;
  padding: 4px 0;
  color: var(--teal);
  background: transparent;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr) minmax(230px, 300px);
  gap: 18px;
  width: min(1780px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.resource-rail,
.chronicle,
.play-surface {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.resource-rail,
.chronicle {
  position: sticky;
  top: 86px;
  align-self: start;
  max-height: calc(100vh - 104px);
  overflow: auto;
  border-radius: var(--radius);
}

.play-surface {
  min-width: 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.rail-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  color: #f8f8f4;
  background: var(--charcoal);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.resource-list {
  display: grid;
  gap: 1px;
  padding: 0;
}

.resource-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 10px 12px;
  background: rgba(248, 249, 245, 0.9);
  border-bottom: 1px solid #e1e4dd;
}

.resource-row img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.resource-row strong,
.resource-row small {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.resource-row strong {
  font-size: 0.94rem;
}

.resource-row small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.77rem;
}

.page-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding: 22px;
  color: #f9faf7;
  background:
    linear-gradient(135deg, rgba(49, 92, 150, 0.42), transparent 45%),
    linear-gradient(90deg, #2c3032, #3a302d);
}

.kicker {
  margin: 0 0 7px;
  color: #c8d9d7;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.55rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.page-heading p {
  max-width: 900px;
  margin: 8px 0 0;
  color: #e3e8e5;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
  min-width: 270px;
}

.metric {
  min-height: 62px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
}

.metric span {
  display: block;
  color: #cdd6d7;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric strong {
  display: block;
  margin-top: 3px;
  color: #ffffff;
  font-size: 1.05rem;
}

.active-alert {
  margin: 18px 18px 0;
  padding: 12px 14px;
  color: #1d3327;
  background: #e5f4ea;
  border: 1px solid #b9dcc8;
  border-radius: 6px;
}

.view-root {
  padding: 18px;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.wide-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.panel,
.shop-row,
.battle-row,
.save-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.panel {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
  background: #f5f6f2;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.action-button {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 9px 11px;
  color: var(--ink);
  text-align: left;
  background: #edf1ec;
  border: 1px solid #d1d8cf;
  border-radius: 6px;
}

.action-button img {
  width: 22px;
  height: 22px;
}

.action-button:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
}

.action-button small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.74rem;
}

.shop-list {
  display: grid;
  gap: 10px;
}

.shop-row,
.battle-row {
  display: grid;
  gap: 14px;
  align-items: center;
  padding: 13px;
}

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

.battle-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.shop-row.locked,
.battle-row.locked {
  background: #f2f2ef;
  opacity: 0.78;
}

.shop-row h3,
.battle-row h3 {
  margin: 0;
  font-size: 1rem;
}

.shop-row p,
.battle-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 3px 7px;
  color: #303236;
  background: #ecefea;
  border: 1px solid #d6dbd3;
  border-radius: 999px;
  font-size: 0.76rem;
}

.pill.good {
  color: #17472f;
  background: #e1f1e7;
  border-color: #b9d9c5;
}

.pill.warn {
  color: #68410b;
  background: #fff1ce;
  border-color: #e7cf8b;
}

.pill.bad {
  color: #7a1f20;
  background: #f7dfdf;
  border-color: #e5bbbb;
}

.cost-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.cost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 3px 6px;
  background: #f6f7f3;
  border: 1px solid #dfe3dc;
  border-radius: 5px;
  color: #323438;
  font-size: 0.76rem;
}

.cost.missing {
  color: #8b1f23;
  background: #fae6e6;
  border-color: #efbbbb;
}

.cost img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-start;
  min-width: 0;
}

.row-actions button,
.compact-button {
  min-height: 34px;
  padding: 7px 9px;
  color: #ffffff;
  background: var(--teal);
  border-radius: 6px;
}

.row-actions button:hover,
.compact-button:hover {
  background: #075f5b;
}

.battle-row .row-actions {
  justify-content: flex-end;
  min-width: 190px;
}

.row-actions button:disabled,
.compact-button:disabled,
.primary-action:disabled,
.secondary-action:disabled,
.danger-action:disabled {
  cursor: not-allowed;
  color: #777d82;
  background: #d9ddd7;
}

.progress-shell {
  width: 100%;
  height: 18px;
  overflow: hidden;
  background: #e0e5de;
  border-radius: 999px;
  border: 1px solid #cbd2c8;
}

.progress-bar {
  height: 100%;
  width: 0;
  min-width: 0;
  background: linear-gradient(90deg, var(--red), var(--gold));
  transition: width 160ms linear;
}

.battle-row.active {
  border-color: #c69735;
  box-shadow: inset 0 0 0 1px rgba(188, 138, 27, 0.35);
}

.battle-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 14px;
}

.event-log {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-log li {
  padding: 11px 13px;
  background: rgba(248, 249, 245, 0.9);
  border-bottom: 1px solid #e1e4dd;
  color: #35383d;
  font-size: 0.84rem;
}

.event-log time {
  display: block;
  margin-bottom: 2px;
  color: var(--quiet);
  font-size: 0.71rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  background: #f3f5f0;
  border: 1px dashed #cdd4c9;
  border-radius: var(--radius);
}

.save-block {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.save-block h3 {
  margin: 0;
}

.save-block p {
  margin: 0;
  color: var(--muted);
}

.save-dialog {
  width: min(720px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.save-dialog::backdrop {
  background: rgba(20, 22, 24, 0.55);
}

.save-dialog form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

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

.dialog-heading h2 {
  margin: 0;
  font-size: 1.1rem;
}

.dialog-heading .icon-button {
  color: var(--ink);
  background: #ecefea;
}

#save-text {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.toast-area {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: 12px 13px;
  color: #f8faf7;
  background: #273033;
  border-left: 4px solid var(--teal);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.toast.success {
  border-color: var(--green);
}

.toast.warn {
  border-color: var(--gold);
}

.toast.danger {
  border-color: var(--red);
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
}

.stat-table th,
.stat-table td {
  padding: 9px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.stat-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-table td:last-child,
.stat-table th:last-child {
  text-align: right;
}

@media (max-width: 1180px) {
  .game-layout {
    grid-template-columns: minmax(200px, 240px) minmax(0, 1fr);
  }

  .chronicle {
    grid-column: 1 / -1;
    position: static;
    max-height: 260px;
  }
}

@media (max-width: 860px) {
  .topbar {
    position: static;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .brand {
    min-width: 0;
  }

  .main-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .nav-button {
    flex: 0 0 auto;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .game-layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .resource-rail,
  .chronicle {
    position: static;
    max-height: none;
  }

  .resource-list {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .resource-row {
    border-right: 1px solid #e1e4dd;
  }

  .page-heading {
    grid-template-columns: 1fr;
  }

  .hero-metrics {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .battle-layout {
    grid-template-columns: 1fr;
  }

  .shop-row,
  .battle-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .hero-metrics,
  .section-grid {
    grid-template-columns: 1fr;
  }

  .view-root,
  .page-heading {
    padding: 14px;
  }

  .row-actions button {
    flex: 1 1 86px;
  }
}
