:root {
  color-scheme: light dark;
  --bg: #f8f5ef;
  --surface: #fffaf2;
  --surface-2: #eaf3ee;
  --text: #17211f;
  --muted: #61736f;
  --line: rgba(23, 33, 31, .13);
  --primary: #2f6f6b;
  --primary-2: #174d4a;
  --accent: #e56f4f;
  --gold: #d99b35;
  --danger: #b84343;
  --shadow: 0 22px 60px rgba(30, 48, 44, .13);
  --radius: 8px;
  --bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  --bg: #111615;
  --surface: #1b2220;
  --surface-2: #24332f;
  --text: #f2efe6;
  --muted: #b4c1bc;
  --line: rgba(242, 239, 230, .14);
  --primary: #7fc4bb;
  --primary-2: #a9ddd6;
  --accent: #f09071;
  --gold: #efc66b;
  --danger: #ff8f8f;
  --shadow: 0 22px 60px rgba(0, 0, 0, .32);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #111615;
    --surface: #1b2220;
    --surface-2: #24332f;
    --text: #f2efe6;
    --muted: #b4c1bc;
    --line: rgba(242, 239, 230, .14);
    --primary: #7fc4bb;
    --primary-2: #a9ddd6;
    --accent: #f09071;
    --gold: #efc66b;
    --danger: #ff8f8f;
    --shadow: 0 22px 60px rgba(0, 0, 0, .32);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: .72;
}

.app {
  min-height: 100vh;
}

.boot-screen,
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 24px;
  background:
    radial-gradient(circle at 34% 32%, var(--accent) 0 13px, transparent 14px),
    radial-gradient(circle at 68% 28%, var(--gold) 0 10px, transparent 11px),
    linear-gradient(145deg, var(--surface-2), var(--primary));
  box-shadow: var(--shadow);
}

.shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px calc(118px + var(--bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
}

.brand p,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.timer-pill {
  min-width: 128px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-align: center;
  color: var(--primary-2);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.hero {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, .88fr);
  align-items: stretch;
}

.panel,
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.hero-copy {
  display: grid;
  align-content: start;
  gap: 16px;
  min-height: 390px;
  background:
    radial-gradient(circle at 88% 12%, color-mix(in srgb, var(--gold) 30%, transparent), transparent 28%),
    linear-gradient(145deg, color-mix(in srgb, var(--surface-2) 72%, var(--surface)), var(--surface));
}

.hero-title {
  margin: 0;
  max-width: 820px;
  font-size: 76px;
  line-height: .9;
  letter-spacing: 0;
}

.hero-title span {
  color: var(--primary);
}

.setup-grid {
  display: grid;
  gap: 14px;
}

.field label,
.field-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 13px;
}

.wheel-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.wheel,
.money-box,
.battery-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.wheel button,
.money-box button {
  width: 100%;
  padding: 8px;
  color: var(--primary-2);
  background: transparent;
}

.wheel-value {
  padding: 10px 4px;
  text-align: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.wheel-value strong {
  display: block;
  font-size: 24px;
}

.wheel-value span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.money-controls {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
}

.money-value {
  text-align: center;
  font-size: 24px;
  font-weight: 750;
}

.battery-shell {
  height: 28px;
  margin: 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

.battery-fill {
  height: 100%;
  width: 50%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--primary));
  transition: width .28s ease;
}

input[type="range"] {
  width: calc(100% - 26px);
  margin: 0 13px 13px;
  accent-color: var(--primary);
}

.text-input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 11px 14px;
  font-weight: 750;
}

.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
}

.is-busy .primary-btn,
.is-busy .secondary-btn,
.is-busy .ghost-btn {
  cursor: progress;
}

:root[data-theme="dark"] .primary-btn {
  color: #10201d;
}

.secondary-btn {
  color: var(--primary-2);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.ghost-btn {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

.stack {
  display: grid;
  gap: 12px;
}

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

.card {
  padding: 14px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.card p {
  margin: 0 0 10px;
  color: var(--muted);
}

.metric-row {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.metric {
  display: grid;
  grid-template-columns: 92px 1fr 22px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: max(10px, var(--bottom));
  z-index: 30;
  width: min(680px, calc(100% - 18px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.tabbar button {
  min-height: 46px;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
}

.tabbar button.active {
  color: var(--text);
  background: var(--surface-2);
}

.auth-card {
  width: min(430px, 100%);
  padding: 20px;
}

.auth-card h1 {
  margin: 0 0 8px;
}

.auth-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.notice {
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--primary-2);
  background: var(--surface-2);
}

.error {
  color: var(--danger);
}

.history-row {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 820px) {
  .shell {
    padding: 12px 10px calc(112px + var(--bottom));
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    min-height: 260px;
  }

  .hero-title {
    font-size: 44px;
    line-height: .95;
  }

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

  .topbar {
    align-items: flex-start;
  }

  .timer-pill {
    min-width: 104px;
    font-size: 13px;
  }

  .tabbar button {
    font-size: 11px;
  }
}
