:root {
  --bg: #f4f0e8;
  --bg-deep: #e7dcc8;
  --panel: #fffdf6;
  --panel-border: #d7c7a4;
  --text: #1f1f22;
  --muted: #655e53;
  --accent: #0d7c66;
  --accent-2: #f29f05;
  --danger: #a83535;
  --ok: #2f8a4a;
  --shadow: 0 8px 20px rgba(20, 20, 30, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 0%, #fff7d5 0%, var(--bg) 45%),
    linear-gradient(130deg, #f0e6d8 0%, var(--bg-deep) 100%);
}

body.theme-dark {
  --bg: #10131a;
  --bg-deep: #1a212c;
  --panel: #171d27;
  --panel-border: #2d394b;
  --text: #eef2f7;
  --muted: #a9b6c8;
  --accent: #1aa185;
  --accent-2: #f0a934;
  --danger: #e86a6a;
  --ok: #5ec585;
  --shadow: 0 10px 24px rgba(1, 3, 8, 0.45);
  background: radial-gradient(circle at 15% 0%, #23324f 0%, var(--bg) 45%),
    linear-gradient(130deg, #131a24 0%, var(--bg-deep) 100%);
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 10%, rgba(255, 238, 190, 0.52), rgba(25, 18, 12, 0.7));
  backdrop-filter: blur(6px);
}

.start-screen.hidden {
  display: none;
}

.start-card {
  width: min(780px, 100%);
  border: 2px solid #d7c7a4;
  border-radius: 14px;
  background: linear-gradient(180deg, #fffef8 0%, #f7f0e0 100%);
  box-shadow: 0 12px 28px rgba(12, 11, 7, 0.3);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.start-logo {
  width: min(560px, 100%);
  margin: 0 auto;
  display: block;
}

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

.start-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: #4c4335;
}

.start-field input,
.start-field select,
#import-save-text {
  border: 1px solid #ceb998;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-size: 0.95rem;
}

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

.import-panel {
  border: 1px solid #ddccab;
  border-radius: 10px;
  padding: 10px;
  background: #fdf8ec;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.import-panel label {
  font-size: 0.85rem;
  color: #5c4a32;
}

.import-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#start-feedback {
  min-height: 18px;
}

#import-save-file {
  display: none;
}

.file-pill {
  border: 1px solid #d7c7a4;
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 0.85rem;
  background: #f7f1e2;
  cursor: pointer;
}

.app-shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.top-bar {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 16px;
  align-items: stretch;
}

.header-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-actions {
  display: flex;
  justify-content: flex-end;
}

.theme-toggle-btn {
  min-width: 46px;
  font-size: 1rem;
  line-height: 1;
}

.brand-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-logo {
  width: 130px;
  min-width: 130px;
  border-radius: 10px;
  border: 1px solid #c8b48f;
  background: #f5eee0;
}

.player-line {
  font-size: 0.9rem;
  color: #3f3a31;
}

.eyebrow {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.subtitle {
  color: var(--muted);
  margin-top: 6px;
}

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

.stat-card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.stat-card h2 {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-card p {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 1.15rem;
}

.main-layout {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.left-panel,
.shop-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-block {
  background: linear-gradient(180deg, #fff 0%, #fdf9ef 100%);
  border: 1px solid #e6dbc2;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.click-block {
  position: relative;
  overflow: hidden;
}

.resolve-btn {
  padding: 16px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, #0a5f52 100%);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(9, 66, 56, 0.25);
}

.resolve-btn:active {
  transform: translateY(1px);
}

.resolve-btn.pulse {
  animation: resolvePulse 260ms ease-out;
}

.secondary-btn,
.ghost-btn,
.danger-btn,
.buy-btn,
.tab-btn {
  border-radius: 9px;
  padding: 8px 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
}

.secondary-btn {
  background: var(--accent-2);
  color: #111;
}

.ghost-btn {
  background: #f7f1e2;
  color: #292722;
  border-color: #d7c7a4;
}

.danger-btn {
  background: #f8dddd;
  color: var(--danger);
  border-color: #d59292;
}

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

.hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.active-events {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.event-chip {
  background: #1f2625;
  color: #f9f9f9;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  border: 1px solid #303b38;
}

.event-chip.is-new {
  animation: chipPop 380ms ease-out;
}

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

.tab-btn {
  background: #f7f1e2;
  border-color: #d7c7a4;
  font-size: 0.88rem;
}

.tab-btn.active {
  background: #f29f05;
  color: #121212;
  border-color: #e19100;
}

.tab-btn:disabled,
.buy-btn:disabled,
.secondary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tab-lock {
  background: #f8edcf;
  border: 1px dashed #caa25b;
  color: #6e5427;
  border-radius: 8px;
  padding: 9px;
  font-size: 0.86rem;
}

.automation-line {
  margin: 2px 4px 2px;
}

.upgrade-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 2px;
}

.upgrade-card {
  border: 1px solid #d9ccb4;
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upgrade-card.affordable {
  border-color: #90b8ae;
  box-shadow: 0 0 0 1px rgba(20, 107, 87, 0.12);
}

.upgrade-card h3 {
  margin: 0;
  font-size: 0.95rem;
}

.upgrade-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
}

.upgrade-desc {
  font-size: 0.82rem;
  color: #373737;
  line-height: 1.35;
  min-height: 42px;
}

.upgrade-cost,
.upgrade-effect,
.upgrade-lock {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  color: #463f32;
}

.upgrade-lock {
  color: var(--danger);
}

.buy-btn {
  background: #146b57;
  color: #fff;
}

.bottom-panel {
  padding: 14px;
}

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

.event-log li {
  background: #fcf8ed;
  border: 1px solid #dfd2b8;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

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

.stat-card.flash {
  animation: statFlash 360ms ease-out;
}

.click-fx {
  position: absolute;
  inset: 12px;
  pointer-events: none;
}

.float-gain {
  position: absolute;
  left: 18px;
  bottom: 34px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88rem;
  color: #0f6e5b;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  animation: floatGain 820ms ease-out forwards;
}

.float-gain.crit {
  color: #b44300;
  font-weight: 700;
  animation-duration: 980ms;
}

.event-banner {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translate(-50%, -14px);
  z-index: 30;
  width: min(780px, calc(100% - 24px));
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
  box-shadow: var(--shadow);
}

.event-banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.event-banner.good {
  background: #daf5df;
  border: 1px solid #8cc497;
  color: #1f5d2c;
}

.event-banner.bad {
  background: #f6dddd;
  border: 1px solid #d19191;
  color: #7a2424;
}

.event-banner.neutral {
  background: #ede8dc;
  border: 1px solid #ccb995;
  color: #4d4637;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(19, 17, 10, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal.hidden,
.hidden {
  display: none;
}

.modal-card {
  width: min(560px, 100%);
  background: #fffef8;
  border: 2px solid #d7c7a4;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.modal-field input[type="range"],
.modal-field input[type="number"],
.modal-field select {
  width: 100%;
  border: 1px solid #ceb998;
  border-radius: 8px;
  padding: 8px 9px;
  background: #fff;
}

.modal-check {
  flex-direction: row;
  align-items: center;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

body.theme-dark .start-card,
body.theme-dark .panel-block,
body.theme-dark .upgrade-card,
body.theme-dark .event-log li,
body.theme-dark .tab-lock,
body.theme-dark .modal-card,
body.theme-dark .import-panel,
body.theme-dark .start-field input,
body.theme-dark .start-field select,
body.theme-dark #import-save-text,
body.theme-dark .modal-field input[type="range"],
body.theme-dark .modal-field input[type="number"],
body.theme-dark .modal-field select {
  background: #1b2431;
  border-color: #34465e;
  color: #eef2f7;
}

body.theme-dark .subtitle,
body.theme-dark .hint,
body.theme-dark .upgrade-meta,
body.theme-dark .upgrade-cost,
body.theme-dark .upgrade-effect,
body.theme-dark .player-line,
body.theme-dark .tab-lock {
  color: #b6c3d4;
}

body.theme-dark .tab-btn,
body.theme-dark .ghost-btn,
body.theme-dark .file-pill {
  background: #1f2b3b;
  border-color: #34465e;
  color: #e9eef5;
}

body.theme-dark .tab-btn.active {
  background: #f0a934;
  color: #111;
}

body.theme-dark .buy-btn {
  background: #1a8f73;
}

body.theme-dark .start-screen {
  background: radial-gradient(circle at 20% 10%, rgba(32, 52, 86, 0.45), rgba(8, 10, 15, 0.75));
}

@keyframes resolvePulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes statFlash {
  0% {
    box-shadow: var(--shadow);
  }
  40% {
    box-shadow: 0 0 0 2px rgba(13, 124, 102, 0.28), 0 8px 20px rgba(20, 20, 30, 0.09);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

@keyframes floatGain {
  0% {
    transform: translateY(0) scale(0.9);
    opacity: 0;
  }
  20% {
    opacity: 1;
    transform: translateY(-4px) scale(1);
  }
  100% {
    transform: translateY(-30px) scale(1);
    opacity: 0;
  }
}

@keyframes chipPop {
  0% {
    transform: scale(0.92);
    opacity: 0.2;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .resolve-btn.pulse,
  .stat-card.flash,
  .float-gain,
  .event-chip.is-new {
    animation: none !important;
  }

  .event-banner {
    transition: none;
  }
}

body.no-anim .resolve-btn.pulse,
body.no-anim .stat-card.flash,
body.no-anim .float-gain,
body.no-anim .event-chip.is-new {
  animation: none !important;
}

body.no-anim .event-banner {
  transition: none !important;
}

@media (max-width: 980px) {
  .top-bar,
  .main-layout {
    grid-template-columns: 1fr;
  }

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

  .brand-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .hud-logo {
    width: 100%;
    max-width: 230px;
  }

  .upgrade-list {
    grid-template-columns: 1fr;
    max-height: none;
  }

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

  .settings-actions {
    grid-template-columns: 1fr;
  }

  .start-grid,
  .start-actions {
    grid-template-columns: 1fr;
  }
}
