:root {
  --bg: #101319;
  --panel: rgba(18, 22, 29, 0.9);
  --panel-solid: #151a22;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f4f7fb;
  --muted: #9ca8ba;
  --blue: #2f7df6;
  --red: #e44343;
  --green: #25c27a;
  --gold: #e6b84f;
  --command-rail-height: 64px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202733;
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #202733;
  color: var(--text);
  font: inherit;
  font-weight: 800;
}

button:active {
  transform: translateY(1px);
}

button:enabled { cursor: pointer; }
button:focus-visible { outline: 2px solid #b9f6dc; outline-offset: 2px; }
[hidden] { display: none !important; }
.battle-result {
  position: fixed;
  z-index: 4;
  top: max(80px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(430px, calc(100% - 100px));
  padding: 18px 22px;
  border: 1px solid #7caa9c;
  border-top: 3px solid #57f59a;
  border-radius: 6px;
  background: #141d20f2;
  box-shadow: 0 12px 32px #0005;
  pointer-events: none;
}
.battle-result h2 { margin: 6px 0 10px; font-size: 22px; }
.battle-result p { margin: 0; font-size: 13px; line-height: 1.6; color: #c7d8d3; }
.upgrade-rank { display: block; width: 110px; height: 8px; margin: 8px 0; accent-color: #57f59a; }

button[disabled] {
  opacity: 0.46;
}

.game-intro {
  position: fixed;
  z-index: 10;
  inset: 0;
  overflow: hidden;
  background: #05070b;
  isolation: isolate;
  transition: opacity 420ms ease, visibility 420ms ease;
}

.game-intro.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.intro-canvas,
.intro-scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.intro-canvas {
  z-index: -2;
  object-fit: cover;
  object-position: center;
}

.intro-scrim {
  z-index: -1;
  background: linear-gradient(180deg, transparent 65%, rgba(3, 5, 8, 0.55) 100%);
}

.intro-content {
  position: absolute;
  inset: auto max(20px, env(safe-area-inset-right)) max(34px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  display: grid;
  justify-items: start;
  gap: 18px;
}

.intro-title {
  margin: 0;
  max-width: 100%;
  font-size: 48px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
  color: #f4f7fb;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

@media (min-width: 760px) {
  .intro-title { font-size: 72px; }
}

.intro-start {
  min-width: 164px;
  min-height: 52px;
  border-color: rgba(226, 236, 249, 0.65);
  background: #e9eef6;
  color: #101720;
  font-size: 16px;
}

.intro-start[disabled] {
  opacity: 0.65;
}

#battlefield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.top-hud,
.base-bars,
.bottom-panel,
.side-actions,
.message,
.drawer {
  position: fixed;
  z-index: 2;
}

.top-hud {
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
}

.top-hud > div,
.timer {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  text-transform: uppercase;
}

strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.base-bars {
  top: auto;
  bottom: calc(var(--command-rail-height) + 8px + env(safe-area-inset-bottom));
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  pointer-events: none;
}

.base-bars div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 22, 29, 0.72);
}

.base-bars span {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

meter {
  width: 100%;
  height: 5px;
}

.side-actions {
  top: 108px;
  right: 10px;
  display: grid;
  gap: 8px;
}

.side-actions button {
  width: 46px;
  padding: 0;
  font-size: 23px;
}

.message {
  left: 12px;
  right: 68px;
  bottom: calc(var(--command-rail-height) + 54px + env(safe-area-inset-bottom));
  min-height: 28px;
  color: #e8edf7;
  font-size: 13px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.bottom-panel {
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: min(46vh, 330px);
  overflow: hidden;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(16px);
  transition: transform 180ms ease;
}

.bottom-panel.is-collapsed {
  transform: none;
}

.bottom-panel.is-collapsed .deployment-details {
  display: none;
}

.bottom-panel.is-collapsed .primary-row {
  margin-top: 0;
}

.panel-toggle {
  width: 100%;
  min-height: 44px;
  margin: 0;
  background: #111821;
  color: var(--text);
}

.panel-toggle.has-selection {
  border-color: var(--blue);
  color: #dce9ff;
}

.deployment-details {
  order: 1;
}

.enemy-preview {
  display: grid;
  gap: 7px;
  min-height: 58px;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 11, 16, 0.44);
}

.preview-title {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.preview-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-units {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 1px;
}

.preview-unit {
  flex: 0 0 auto;
  padding: 5px 7px;
  border: 1px solid rgba(228, 67, 67, 0.42);
  border-radius: 7px;
  background: rgba(228, 67, 67, 0.14);
  color: #ffd0d0;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.unit-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.unit-card {
  display: grid;
  min-height: 76px;
  padding: 8px;
  text-align: left;
}

.unit-card.is-selected {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.unit-card small {
  color: var(--muted);
  font-weight: 700;
}

.unit-card b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-row {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 76px;
  gap: 8px;
  margin-top: 8px;
  order: 2;
}

.primary-row .timer {
  padding: 6px;
  text-align: center;
}

.primary-row .timer .label {
  font-size: 9px;
}

.primary-row .timer strong {
  font-size: 12px;
}

.start-button {
  background: #57f59a;
  border: 1px solid #a5ffcc;
  box-shadow: 0 0 14px #57f59a40;
  color: #07140d;
  line-height: 1.05;
}

.start-button:disabled {
  background: #343d43;
  border-color: #52606a;
  color: #aab5be;
  box-shadow: none;
  opacity: 1;
}

.start-button:enabled:hover { background: #85ffb6; }
.start-button:focus-visible { outline: 3px solid white; outline-offset: 3px; }

.start-button span,
.start-button small {
  display: block;
}

.start-button small {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 800;
  opacity: 0.74;
}

.bottom-panel.is-combat .panel-toggle {
  display: none;
}

.bottom-panel.is-combat .primary-row {
  grid-template-columns: minmax(0, 1fr) 76px;
}

.drawer {
  right: 10px;
  bottom: 142px;
  width: min(390px, calc(100vw - 20px));
  max-height: min(62vh, 520px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

.drawer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.drawer h2,
.drawer h3 {
  margin: 0;
  font-size: 17px;
}

.drawer h3 {
  margin-top: 16px;
  color: var(--muted);
}

.profile-progress {
  margin-bottom: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10161f;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.close-drawer {
  width: 44px;
  padding: 0;
  font-size: 22px;
}

.drawer-list {
  display: grid;
  gap: 8px;
}

.drawer-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1c232d;
}

.drawer-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.editor-actions select {
  grid-column: 1 / -1;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #0e1218;
  color: var(--text);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (min-width: 760px) {
  .intro-content {
    left: max(42px, env(safe-area-inset-left));
    bottom: max(42px, env(safe-area-inset-bottom));
  }

  .top-hud {
    left: 18px;
    right: auto;
    width: 420px;
  }

  .base-bars {
    top: auto;
    right: auto;
    bottom: 290px;
    left: 18px;
    width: 430px;
  }

  .base-bars div {
    padding: 7px 9px;
  }

  .base-bars span {
    font-size: 10px;
  }

  meter {
    height: 7px;
  }

  .side-actions {
    top: 82px;
  }

  .bottom-panel {
    left: 18px;
    right: auto;
    bottom: 18px;
    width: 430px;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .message {
    left: 22px;
    right: auto;
    bottom: 360px;
    width: 430px;
  }

  .drawer {
    bottom: 18px;
  }
}

@media (min-width: 760px) and (max-width: 1023px) {
  .top-hud {
    width: 380px;
  }

  .base-bars,
  .bottom-panel,
  .message {
    width: 390px;
  }
}
