:root {
  color-scheme: dark;
  --ink: #f8efe0;
  --muted: #d8c8ae;
  --panel: rgba(45, 34, 31, 0.82);
  --panel-strong: rgba(72, 45, 36, 0.92);
  --line: rgba(255, 235, 190, 0.24);
  --gold: #ffc857;
  --red: #e85545;
  --green: #65d18a;
  --blue: #70b8ff;
  --shadow: rgba(25, 13, 10, 0.4);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #211915;
  color: var(--ink);
}

button {
  border: 0;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

#app,
#game,
.screen {
  position: fixed;
  inset: 0;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  background: #83c5f4;
}

.screen {
  pointer-events: none;
}

.screen > *,
.modal {
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.topbar,
.battle-hud,
.battle-controls {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  top: max(14px, env(safe-area-inset-top));
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 52px);
  line-height: 0.92;
  text-shadow: 0 4px 0 rgba(80, 40, 25, 0.42);
}

h2 {
  font-size: clamp(18px, 2vw, 27px);
  line-height: 1.05;
}

.eyebrow {
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.wallet,
.health-pill,
.round-card,
.panel,
.battle-toast,
.result-card {
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px var(--shadow);
  backdrop-filter: blur(12px);
}

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

.wallet span,
.health-pill {
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 12px;
  background: rgba(39, 27, 24, 0.72);
}

.wallet b {
  color: var(--gold);
}

.icon-button,
.ghost,
.primary,
.tab,
.unit-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 10px 14px;
  background: rgba(52, 38, 34, 0.88);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.primary {
  width: 100%;
  background: linear-gradient(#ffcf62, #e18a2e);
  color: #3b2114;
  text-transform: uppercase;
}

.ghost {
  border: 1px solid var(--line);
}

.home-grid {
  position: absolute;
  inset: 112px max(18px, env(safe-area-inset-right)) 22px max(18px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(190px, 260px) minmax(320px, 1fr) minmax(230px, 330px);
  gap: 16px;
  align-items: stretch;
}

.panel {
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  min-height: 0;
  overflow: auto;
}

.compact {
  align-self: end;
}

.base-stage {
  align-self: stretch;
  min-width: 0;
}

.stage-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(640px, 70vw);
  border-radius: 8px;
  padding: 10px 14px;
  background: rgba(38, 27, 24, 0.68);
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.tab {
  padding: 8px;
  min-height: 38px;
  color: var(--muted);
}

.tab.active {
  background: var(--gold);
  color: #3b2114;
}

.stat-card,
.opponent-card,
.leader-row {
  border-radius: 8px;
  background: rgba(23, 17, 15, 0.38);
  border: 1px solid rgba(255, 235, 190, 0.14);
  padding: 12px;
  margin: 10px 0;
}

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

.stat-card button {
  margin-top: 8px;
  width: 100%;
}

.battle-hud {
  top: max(12px, env(safe-area-inset-top));
}

.health-block {
  display: grid;
  grid-template-columns: 72px minmax(120px, 260px) 48px;
  gap: 9px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.health-block.right {
  grid-template-columns: 112px minmax(120px, 260px) 48px;
}

.bar {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(20, 15, 14, 0.58);
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4bd47a, #c2f06c);
  transition: width 220ms ease;
}

.bar.danger i {
  background: linear-gradient(90deg, #ff754d, #ffd166);
}

.round-card {
  min-width: 150px;
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 8px 14px;
  text-align: center;
}

.round-card span,
.round-card small {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.round-card strong {
  display: block;
  color: var(--gold);
  font-size: 18px;
}

.battle-toast {
  position: absolute;
  left: 50%;
  top: 90px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: rgba(31, 23, 20, 0.78);
  color: var(--gold);
  min-width: 190px;
  padding: 10px 14px;
  text-align: center;
  font-weight: 900;
  opacity: 0;
  transition: opacity 180ms ease;
}

.battle-toast.show {
  opacity: 1;
}

.battle-controls {
  bottom: max(14px, env(safe-area-inset-bottom));
  align-items: flex-end;
}

.unit-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: min(620px, 62vw);
}

.unit-button {
  display: grid;
  grid-template-columns: 30px auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  min-width: 146px;
  text-align: left;
}

.unit-button.active {
  outline: 3px solid rgba(255, 200, 87, 0.72);
  background: rgba(78, 49, 38, 0.96);
}

.unit-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #24130d;
  background: var(--gold);
  font-weight: 1000;
}

.shot-readout {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.drive-controls {
  display: grid;
  grid-template-columns: repeat(2, 44px);
  gap: 8px;
}

.drive-controls .icon-button {
  min-width: 44px;
  padding: 8px 0;
  font-size: 28px;
  line-height: 1;
  background: linear-gradient(#6a4a3d, #34241f);
  border: 1px solid var(--line);
}

.drive-controls .icon-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.shot-readout span {
  border-radius: 8px;
  background: rgba(31, 23, 20, 0.74);
  padding: 10px 12px;
}

.shot-readout i {
  color: var(--gold);
  font-style: normal;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(18, 10, 8, 0.38);
}

.result-card {
  width: min(420px, calc(100vw - 30px));
  border-radius: 8px;
  padding: 22px;
  background: var(--panel-strong);
  text-align: center;
}

.result-card h2 {
  font-size: 44px;
  margin: 8px 0 14px;
}

.reward-line {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  color: var(--muted);
  font-weight: 800;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 900px), (max-height: 590px) {
  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 34px;
  }

  .home-grid {
    inset: 92px 12px 12px;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
  }

  .base-stage {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .panel.compact,
  .home-grid > .panel:not(.compact) {
    grid-row: 2;
    max-height: 34vh;
  }

  .canvas-hint {
    bottom: 34vh;
    width: calc(100vw - 28px);
    font-size: 12px;
  }

  .battle-hud {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
  }

  .health-block,
  .health-block.right {
    grid-template-columns: 1fr;
    gap: 4px;
    font-size: 12px;
  }

  .battle-controls {
    align-items: stretch;
    gap: 6px;
  }

  .unit-bar {
    max-width: 56vw;
  }

  .unit-button {
    min-width: 74px;
    grid-template-columns: 1fr;
    justify-items: center;
    font-size: 11px;
  }

  .drive-controls {
    grid-template-columns: repeat(2, 38px);
    gap: 6px;
  }

  .drive-controls .icon-button {
    min-width: 38px;
    min-height: 38px;
    font-size: 24px;
  }

  .shot-readout span {
    padding: 8px 9px;
    font-size: 12px;
  }
}
