:root {
  --bg: #f4f1eb;
  --panel: #fffaf3;
  --ink: #1d1b18;
  --muted: #6f685f;
  --line: #dfd5c8;
  --accent: #8a4b26;
  --accent-soft: #f2dfcf;
  --good: #237a57;
  --warn: #b26a00;
  --bad: #b83b3b;
  --shadow: 0 18px 45px rgba(47, 33, 21, 0.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff7ed, var(--bg) 42%);
  color: var(--ink);
}
body[data-theme="dark"] {
  --bg: #14110f;
  --panel: #221b17;
  --ink: #f4ede6;
  --muted: #b8aa9d;
  --line: #45362e;
  --accent: #c67b46;
  --accent-soft: #3a281f;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  background: radial-gradient(circle at top left, #33241b, var(--bg) 42%);
}
body[data-theme="dark"] .metrics-grid div,
body[data-theme="dark"] .staff-row,
body[data-theme="dark"] .menu-item,
body[data-theme="dark"] .report-row,
body[data-theme="dark"] .log-row,
body[data-theme="dark"] .report-highlights div,
body[data-theme="dark"] .advisor-item,
body[data-theme="dark"] .yearly-card,
body[data-theme="dark"] .option-card {
  background: #2a211d;
}
body[data-theme="dark"] .panel,
body[data-theme="dark"] .wizard-card,
body[data-theme="dark"] .game-over-card {
  background: #221b17;
}
button, select, input { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  padding: .72rem 1rem;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.hidden { display: none !important; }
.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.eyebrow { text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-size: .74rem; }
.muted { color: var(--muted); }
.wizard-screen, .game-over {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.wizard-card, .game-over-card {
  width: min(760px, 100%);
  background: color-mix(in srgb, var(--panel) 95%, transparent);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: clamp(1.2rem, 3vw, 2rem);
  box-shadow: var(--shadow);
}
.wizard-card h1 { margin: .35rem 0 1rem; font-size: clamp(1.5rem, 3vw, 2.3rem); }
.wizard-progress { display: flex; gap: .45rem; margin: 1rem 0 1.4rem; }
.wizard-progress span { flex: 1; height: 8px; border-radius: 999px; background: #e8ddd0; }
.wizard-progress span.active { background: var(--accent); }
.option-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px,1fr)); gap: .8rem; }
.option-card {
  display: block;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: white;
  cursor: pointer;
}
.option-card input { margin-right: .5rem; }
.option-card strong { display: block; margin-bottom: .35rem; }
.wizard-form { display: grid; gap: 1rem; }
.wizard-form input, .wizard-form select, .control-panel input, .control-panel select {
  width: 100%;
  padding: .72rem .85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
}
.wizard-actions { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1.4rem; }
#game {
  height: 100vh;
  padding: 0;
  max-width: none;
  margin: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: .45rem;
}
.topbar { padding: .55rem .75rem; display: grid; grid-template-columns: 185px 1fr auto; align-items: center; gap: .55rem; position: relative; border-radius: 0 0 20px 20px; }
.top-metrics { grid-template-columns: repeat(9, minmax(92px, 1fr)); gap: .45rem; }
.topbar h1 { margin: .15rem 0; font-size: 1.55rem; line-height: 1.05; }
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px,1fr));
  gap: .55rem;
}
.metrics-grid div {
  padding: .52rem .62rem;
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 78%, white 12%);
  border: 1px solid var(--line);
}
.metrics-grid span { display: block; color: var(--muted); font-size: .78rem; }
.metrics-grid strong { display: block; margin-top: .18rem; font-size: 1rem; }
.goal-card { grid-column: span 3; min-width: 0; }
.goal-track {
  display: none;
}
.goal-track i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #d5a16d, var(--accent));
  border-radius: inherit;
}
.speed-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .35rem; }
.speed-controls button { padding: .55rem .78rem; }
.speed-controls button.active { outline: 3px solid rgba(138,75,38,.18); background: #6e3518; }
.speed-status { min-width: 96px; font-size: .82rem; }
.settings-wrap { position: fixed; top: .55rem; right: .75rem; z-index: 100; }
.speed-controls { padding-right: 5.1rem; }
.settings-toggle { white-space: nowrap; }
.settings-menu {
  position: absolute;
  z-index: 10;
  top: calc(100% + .55rem);
  right: 0;
  width: min(320px, 80vw);
  display: grid;
  gap: .75rem;
  padding: .8rem;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.settings-group { display: grid; gap: .4rem; }
.settings-group select {
  width: 100%;
  padding: .65rem .75rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
}
body[data-theme="dark"] .settings-group select,
body[data-theme="dark"] .wizard-form input,
body[data-theme="dark"] .wizard-form select,
body[data-theme="dark"] .control-panel input,
body[data-theme="dark"] .control-panel select {
  background: #2a211d;
  color: var(--ink);
}
.alerts { display: grid; gap: .5rem; margin: 0; }
.alert { border-radius: 16px; padding: .85rem 1rem; border: 1px solid; }
.alert.warn { color: #7d4b00; background: #fff1d6; border-color: #efcf92; }
.alert.bad { color: #7f1d1d; background: #fde3e3; border-color: #efb2b2; }
.dashboard-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, .8fr) minmax(520px, 1.55fr) minmax(360px, .95fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "ops middle controls"
    "insight middle controls";
  gap: .45rem;
}
.dashboard-grid > article { padding: .65rem; min-height: 0; overflow: hidden; border-radius: 18px; }
.dashboard-grid > article:nth-child(1) { grid-area: ops; }
.insight-panel { grid-area: insight; }
.middle-tabs { grid-area: middle; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: .55rem; }
.control-panel { grid-area: controls; display: grid; gap: .52rem; align-content: start; overflow: auto !important; }
.tab-buttons { display: flex; gap: .35rem; flex-wrap: wrap; }
.tab-button {
  padding: .5rem .72rem;
  background: var(--accent-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}
.tab-button.active { background: var(--accent); color: white; }
.tab-content { min-height: 0; overflow: hidden; }
.tab-panel { display: none; height: 100%; min-height: 0; overflow: hidden; }
.tab-panel.active { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: .55rem; }
.tab-panel[data-tab-panel="staff"].active { grid-template-rows: auto minmax(0, auto) auto; }
.tab-panel[data-tab-panel="finance"].active { grid-template-rows: auto auto auto; align-content: start; overflow: auto; }
.tab-panel[data-tab-panel="finance"] .metrics-grid {
  align-content: start;
  grid-auto-rows: max-content;
}
.tab-panel[data-tab-panel="finance"] .metrics-grid div {
  min-height: 0;
  align-self: start;
}
.ad-slot {
  margin-top: .8rem;
  min-height: 90px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 82%, white 6%);
  font-size: .9rem;
}
body[data-theme="dark"] .ad-slot {
  background: #2a211d;
}
.tab-panel[data-tab-panel="menu"].active { grid-template-rows: auto auto minmax(0, 1fr); }
.tab-panel[data-tab-panel="reports"].active { grid-template-rows: auto auto auto auto minmax(0, 1fr); }
.tab-panel[data-tab-panel="advisor"].active { grid-template-rows: auto auto minmax(0, 1fr); }
.panel-title h2 { margin: 0 0 .55rem; font-size: 1rem; }
.submetrics { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .85rem; color: var(--muted); }
.staff-rows, .menu-items { display: grid; gap: .65rem; }
.menu-items { min-height: 0; overflow: auto; padding-right: .25rem; }
.bridge-list, .advisor-list { display: grid; gap: .6rem; }
.staff-row, .menu-item, .report-row, .log-row {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 82%, white 10%);
  border-radius: 16px;
  padding: .75rem;
}
.bridge-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .75rem;
  align-items: center;
}
.bridge-row span:last-child { font-weight: 700; }
.bridge-row.cost span:last-child { color: var(--bad); }
.bridge-row.profit span:last-child { color: var(--good); }
.report-highlights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .6rem;
  margin-bottom: .75rem;
}
.report-highlights div, .advisor-item, .yearly-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 82%, white 10%);
  padding: .72rem;
}
.trend-bars {
  display: flex;
  align-items: flex-end;
  gap: .45rem;
  min-height: 110px;
  margin-bottom: .8rem;
}
.trend-bar {
  flex: 1;
  min-width: 18px;
  border-radius: 999px 999px 8px 8px;
  background: linear-gradient(180deg, #d5a16d, #8a4b26);
  position: relative;
}
.trend-bar.negative { background: linear-gradient(180deg, #de8b8b, #b83b3b); }
.trend-bar span {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 5px);
  transform: translateX(-50%);
  font-size: .7rem;
  color: var(--muted);
}
.advisor-item strong { display: block; margin-bottom: .25rem; }
.advisor-item.warn { border-color: #efcf92; background: #fff1d6; }
.advisor-item.bad { border-color: #efb2b2; background: #fde3e3; }
.advisor-item.good { border-color: #aad6bf; background: #e9f7f0; }
.yearly-summary { display: grid; gap: .65rem; }
.mini-section { min-height: 0; }
.mini-section h3 { margin: .1rem 0 .5rem; font-size: .95rem; }
.compact-scroll { max-height: 150px; }
.compact-actions button, .compact-actions .file-button { padding: .55rem .72rem; }
.staff-row, .menu-item {
  display: flex;
  justify-content: space-between;
  gap: .8rem;
  align-items: center;
}
.inline-actions, .hire-controls, .save-actions { display: flex; gap: .55rem; flex-wrap: wrap; }
.hire-controls button { padding: .55rem .8rem; }
.scroll-list { display: grid; gap: .65rem; min-height: 0; overflow: auto; }
.report-row small, .log-row small { display: block; color: var(--muted); margin-top: .2rem; }
.file-button {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  padding: .72rem 1rem;
  cursor: pointer;
}
.file-button input { display: none; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px,1fr));
  gap: .8rem;
  margin: 1rem 0 1.2rem;
}
.summary-grid div {
  background: white;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: .85rem;
}
.modal-actions { display: flex; gap: .7rem; flex-wrap: wrap; }
.good { color: var(--good); }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); }
@media (max-width: 980px) {
  #game { height: auto; display: block; }
  .topbar { grid-template-columns: 1fr; }
  .settings-wrap { top: .7rem; right: .7rem; }
  .speed-controls { padding-right: 0; }
  .speed-controls { justify-content: flex-start; }
  .dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "ops"
      "insight"
      "middle"
      "controls"
  }
  .middle-tabs { min-height: 620px; }
}
