/* style.css */
:root {
  color-scheme: dark;
  --bg: #080d16;
  --panel: rgba(10, 17, 28, 0.84);
  --panel-strong: rgba(15, 25, 39, 0.95);
  --line: rgba(151, 190, 218, 0.18);
  --text: #edf8ff;
  --muted: #94aaba;
  --cyan: #71e5ff;
  --gold: #ffca62;
  --red: #ff6374;
  --green: #74efaa;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #dce8ef;
    --panel: rgba(244, 250, 253, 0.88);
    --panel-strong: rgba(250, 253, 255, 0.96);
    --line: rgba(22, 57, 79, 0.2);
    --text: #10202d;
    --muted: #526c7e;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #dce8ef;
  --panel: rgba(244, 250, 253, 0.88);
  --panel-strong: rgba(250, 253, 255, 0.96);
  --line: rgba(22, 57, 79, 0.2);
  --text: #10202d;
  --muted: #526c7e;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080d16;
  --panel: rgba(10, 17, 28, 0.84);
  --panel-strong: rgba(15, 25, 39, 0.95);
  --line: rgba(151, 190, 218, 0.18);
  --text: #edf8ff;
  --muted: #94aaba;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.topbar,
.left-panel,
.build-panel,
.help,
.pilot-banner,
.toast {
  position: fixed;
  z-index: 3;
}

.topbar {
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(100deg, var(--panel-strong), var(--panel));
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
}

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

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(113, 229, 255, 0.4);
  border-radius: 9px;
  background: rgba(63, 159, 190, 0.16);
  color: var(--cyan);
  font-size: 21px;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand strong {
  font-size: clamp(11px, 2.5vw, 15px);
  letter-spacing: 0.1em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.resource-row {
  display: flex;
  gap: 5px;
}

.stat {
  display: flex;
  min-width: 49px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.14);
  font-size: 12px;
}

.stat span {
  color: var(--cyan);
}

.stat.cash span {
  color: var(--gold);
}

.stat.base span {
  color: var(--green);
}

.stat.danger span,
.stat.danger b {
  color: var(--red);
}

.left-panel {
  top: 82px;
  left: 12px;
  width: min(274px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
}

.panel-heading,
.build-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.speed-badge {
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(113, 229, 255, 0.13);
  color: var(--text);
  letter-spacing: normal;
}

.left-panel p {
  min-height: 32px;
  margin: 8px 0 8px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
}

.progress-shell {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(141, 167, 182, 0.18);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), #8d8dff);
  transition: width 0.25s ease;
}

.enemy-readout {
  margin: 7px 0 11px;
  color: var(--muted);
  font-size: 11px;
}

.selected-card {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 58px;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid rgba(113, 229, 255, 0.17);
  border-radius: 10px;
  background: rgba(24, 46, 62, 0.32);
}

.selection-icon {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: rgba(113, 229, 255, 0.12);
  color: var(--cyan);
}

.selected-card b,
.selected-card small {
  display: block;
}

.selected-card b {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-card small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.action,
.tool,
.restart-btn,
.pilot-banner button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(37, 55, 70, 0.68);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.action:hover,
.tool:hover,
.restart-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(113, 229, 255, 0.55);
}

.action:active,
.tool:active,
.restart-btn:active {
  transform: translateY(1px);
}

.action {
  padding: 8px 5px;
  font-size: 11px;
  font-weight: 700;
}

.action:disabled {
  cursor: not-allowed;
  opacity: 0.43;
}

.action.primary {
  border-color: rgba(255, 202, 98, 0.42);
  background: linear-gradient(135deg, #a65a1d, #d98b2e);
  color: #fff9e9;
}

.action.pilot-active {
  border-color: rgba(255, 99, 116, 0.7);
  background: rgba(148, 47, 68, 0.72);
}

.build-panel {
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  max-width: 760px;
  margin: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.23);
}

.build-title {
  margin: 1px 2px 8px;
}

.build-title span:last-child {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
}

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

.tool {
  display: flex;
  min-width: 0;
  min-height: 75px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 3px;
  background: rgba(25, 39, 53, 0.72);
}

.tool.active {
  border-color: var(--cyan);
  background: linear-gradient(160deg, rgba(48, 111, 132, 0.78), rgba(24, 42, 56, 0.9));
  box-shadow: inset 0 0 0 1px rgba(113, 229, 255, 0.15);
}

.tool-icon {
  display: block;
  margin-bottom: 2px;
  font-size: 20px;
  line-height: 1;
}

.cannon-icon { color: var(--gold); }
.frost-icon { color: var(--cyan); }
.tesla-icon { color: #c19aff; }
.mine-icon { color: var(--red); }

.tool strong,
.tool small {
  display: block;
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool strong {
  font-size: 10px;
}

.tool small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 8px;
}

.help {
  right: 15px;
  bottom: 117px;
  max-width: 215px;
  color: rgba(222, 239, 247, 0.78);
  font-size: 10px;
  line-height: 1.4;
  text-align: right;
  pointer-events: none;
  text-shadow: 0 1px 3px #000;
}

.help span {
  display: block;
  margin-top: 2px;
}

.help b {
  color: var(--cyan);
}

.pilot-banner {
  top: 82px;
  right: 12px;
  left: auto;
  display: flex;
  width: min(330px, calc(100vw - 24px));
  align-items: center;
  gap: 9px;
  padding: 10px 10px 10px 13px;
  border: 1px solid rgba(255, 99, 116, 0.55);
  border-radius: 12px;
  background: rgba(79, 18, 31, 0.89);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.3);
}

.pilot-banner b {
  color: #ff9eaa;
  font-size: 10px;
  letter-spacing: 0.12em;
}

.pilot-banner span {
  flex: 1;
  font-size: 11px;
  line-height: 1.25;
}

.pilot-banner button {
  display: grid;
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  place-items: center;
  padding: 0;
  font-size: 20px;
}

.toast {
  bottom: 212px;
  left: 50%;
  max-width: min(350px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid rgba(113, 229, 255, 0.28);
  border-radius: 999px;
  background: rgba(8, 17, 27, 0.9);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  transform: translate(-50%, 18px);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.game-over {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 6, 11, 0.76);
  backdrop-filter: blur(8px);
}

.game-over-card {
  width: min(420px, 100%);
  padding: 25px;
  border: 1px solid rgba(255, 115, 125, 0.42);
  border-radius: 19px;
  background: linear-gradient(145deg, #1d1520, #101b27);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.overline {
  color: #ff9aa7;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.game-over h1 {
  margin: 8px 0 7px;
  font-size: 28px;
}

.game-over p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 22px 0;
}

.report-grid div {
  padding: 11px 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(3, 8, 15, 0.31);
}

.report-grid small,
.report-grid b {
  display: block;
}

.report-grid small {
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.07em;
}

.report-grid b {
  margin-top: 5px;
  color: var(--gold);
  font-size: 22px;
}

.restart-btn {
  width: 100%;
  border-color: rgba(113, 229, 255, 0.44);
  background: linear-gradient(135deg, #16667d, #2ca1bc);
  color: white;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.floating-reward {
  position: fixed;
  z-index: 5;
  color: var(--green);
  font-size: 14px;
  font-weight: 900;
  pointer-events: none;
  animation: floatReward 0.8s ease-out forwards;
  text-shadow: 0 2px 4px #000;
}

@keyframes floatReward {
  from { opacity: 1; transform: translate(-50%, 0) scale(0.9); }
  to { opacity: 0; transform: translate(-50%, -42px) scale(1.15); }
}

@media (max-width: 620px) {
  .left-panel {
    top: 77px;
    width: 214px;
    padding: 10px;
  }

  .left-panel p {
    font-size: 11px;
  }

  .selected-card {
    display: none;
  }

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

  .action {
    min-height: 39px;
    font-size: 10px;
  }

  .help {
    display: none;
  }

  .pilot-banner {
    top: 76px;
    left: 12px;
    right: 12px;
    width: auto;
  }

  .toast {
    bottom: 190px;
  }

  .tool {
    min-height: 70px;
  }
}

@media (max-width: 390px) {
  .brand small {
    display: none;
  }

  .topbar {
    min-height: 50px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .stat {
    min-width: 42px;
    padding: 7px 5px;
    font-size: 11px;
  }

  .left-panel {
    top: 68px;
    width: 194px;
  }

  .panel-heading {
    font-size: 9px;
  }

  .build-panel {
    padding: 8px;
  }

  .tool-row {
    gap: 4px;
  }

  .tool strong {
    font-size: 9px;
  }

  .tool small {
    font-size: 7px;
  }
}
