:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #5b6680;
  --panel: #ffffff;
  --panel-soft: #f4f7fb;
  --border: #d9e1ee;
  --green: #4da86b;
  --green-dark: #2f7648;
  --sky: #8ed2f5;
  --sun: #ffd166;
  --rose: #f47c7c;
  --blue: #5777c8;
  --shadow: 0 16px 44px rgba(50, 64, 92, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #dfeefa;
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(142, 210, 245, 0.78), rgba(255, 241, 210, 0.42) 46%),
    linear-gradient(135deg, #e7f4ff, #f8fbf0 55%, #f3f0ff);
}

button {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: min(100% - 28px, 1180px);
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.lab-link {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 800;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

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

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.stage-panel,
.side-panel,
.info-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.stage-panel {
  padding: 14px;
}

.stage-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.stage-heading h2 {
  margin-bottom: 0;
}

.status-badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(47, 118, 72, 0.22);
  border-radius: 999px;
  background: rgba(77, 168, 107, 0.12);
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 900;
  padding: 8px 12px;
  white-space: nowrap;
}

.stage-frame {
  overflow: hidden;
  border: 1px solid #a9bdd4;
  border-radius: 8px;
  background: var(--sky);
  aspect-ratio: 16 / 9;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.power-panel {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.charge-button,
.ghost-button,
.segmented-control button,
.item-actions button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.charge-button {
  background: var(--green);
  color: #ffffff;
  padding: 10px 18px;
  touch-action: none;
}

.charge-button:hover,
.charge-button:focus-visible {
  background: var(--green-dark);
}

.charge-button:active {
  transform: translateY(1px);
}

.charge-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.ghost-button {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  padding: 9px 14px;
}

.ghost-button:hover,
.ghost-button:focus-visible {
  border-color: var(--green);
}

.segmented-control {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 4px;
}

.segmented-control.wide {
  width: 100%;
  grid-template-columns: repeat(3, 1fr);
}

.segmented-control button {
  min-height: 36px;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}

.segmented-control button.is-active {
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(36, 47, 70, 0.12);
  color: var(--green-dark);
}

.power-readout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 40px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.control-stack {
  display: grid;
  gap: 10px;
}

.power-readout strong,
.angle-control strong {
  color: var(--ink);
  text-align: right;
}

.angle-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.angle-control input {
  width: 100%;
  accent-color: var(--green);
}

.angle-control input:disabled {
  opacity: 0.5;
}

.power-track,
.hp-track {
  overflow: hidden;
  border-radius: 999px;
  background: #d8e2ee;
}

.power-track {
  height: 14px;
}

.power-track span,
.hp-track span {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transition: transform 0.08s linear;
}

.power-track span {
  background: linear-gradient(90deg, var(--sun), #ff9858, var(--rose));
  transform: scaleX(0);
}

.item-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 14px;
  align-items: center;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(244, 247, 251, 0.82);
  padding: 12px;
}

.item-panel h2 {
  margin-bottom: 0;
  font-size: 16px;
}

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.item-actions button {
  min-height: 38px;
  border-color: var(--border);
  background: #ffffff;
  color: var(--ink);
  padding: 8px 12px;
}

.item-actions button:hover,
.item-actions button:focus-visible {
  border-color: var(--green);
}

.item-actions button.is-active {
  border-color: rgba(244, 124, 124, 0.7);
  background: rgba(244, 124, 124, 0.14);
  color: #9b3d3d;
}

.item-actions button.is-used,
.item-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

.item-text {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.side-panel {
  display: grid;
  gap: 12px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.info-block {
  padding: 16px;
}

.info-block h2 {
  margin-bottom: 14px;
  font-size: 17px;
}

.info-row,
.hp-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.info-row {
  min-height: 30px;
  color: var(--muted);
  font-size: 14px;
}

.info-row strong,
.hp-copy strong {
  color: var(--ink);
}

.message-text {
  min-height: 72px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.hp-row + .hp-row {
  margin-top: 16px;
}

.hp-copy {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
}

.hp-track {
  height: 12px;
}

#playerHpFill {
  background: linear-gradient(90deg, #44b36a, #87d37c);
}

#opponentHpFill {
  background: linear-gradient(90deg, #f47c7c, #ffb86b);
}

.result-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.42);
  z-index: 10;
}

.result-modal[hidden] {
  display: none;
}

.result-dialog {
  width: min(100%, 380px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 28px 90px rgba(17, 22, 34, 0.34);
  padding: 24px;
  text-align: center;
}

.result-dialog h2 {
  font-size: 28px;
}

.result-dialog p:not(.section-kicker) {
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 940px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .side-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  .top-actions,
  .stage-heading,
  .power-panel {
    align-items: stretch;
    flex-direction: column;
  }

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

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

  .item-actions {
    justify-content: stretch;
  }

  .item-actions button {
    flex: 1 1 120px;
  }

  .charge-button {
    min-height: 58px;
    font-size: 18px;
  }

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

  .message-text {
    min-height: 0;
  }
}

@media (max-width: 440px) {
  .stage-panel {
    padding: 10px;
  }

  .segmented-control {
    width: 100%;
    grid-template-columns: repeat(2, 1fr);
  }

  .top-actions .ghost-button {
    width: 100%;
  }
}
