* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #0f0f1a;
  font-family: 'Segoe UI', 'Noto Sans JP', sans-serif;
  color: #e0e0e0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  overflow-x: auto;
}

#app {
  display: flex;
  flex-direction: column;
  width: 1280px;
  min-height: 100vh;
}

/* ===== HUD ===== */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0a0a14;
  padding: 8px 16px;
  border-bottom: 2px solid #252540;
  height: 52px;
  gap: 16px;
}

.hud-logo {
  font-size: 18px;
  font-weight: 900;
  color: #7c4dff;
  letter-spacing: 1px;
  white-space: nowrap;
}

.hud-stats {
  display: flex;
  gap: 20px;
  flex: 1;
  justify-content: center;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 16px;
  font-weight: 700;
  background: #1a1a2e;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid #252545;
  min-width: 80px;
  justify-content: center;
}

.hud-icon { font-size: 18px; }

.hud-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== Buttons ===== */
.btn-primary {
  background: #7c4dff;
  color: #fff;
  border: none;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn-primary:hover { background: #9c6fff; }
.btn-primary:active { transform: scale(0.96); }
.btn-primary:disabled { background: #444; cursor: not-allowed; }

.btn-secondary {
  background: #252540;
  color: #ccc;
  border: 1px solid #383860;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #353560; }
.btn-secondary.active { background: #1a3a60; color: #7bb3ff; border-color: #4080c0; }

.btn-close {
  background: none;
  border: none;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-close:hover { background: #333; color: #fff; }

.btn-sell {
  width: 100%;
  background: #b71c1c;
  color: #fff;
  border: none;
  padding: 7px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}
.btn-sell:hover { background: #e53935; }

/* ===== Game Layout ===== */
#game-wrap {
  display: flex;
  flex: 1;
}

#canvas {
  display: block;
  cursor: crosshair;
  flex-shrink: 0;
}

/* ===== Sidebar ===== */
#sidebar {
  width: 280px;
  background: #0a0a14;
  border-left: 2px solid #252540;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#tab-bar {
  display: flex;
  border-bottom: 2px solid #252540;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: #888;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tab-btn:hover { color: #ccc; background: #151525; }
.tab-btn.active { color: #7c4dff; border-bottom: 2px solid #7c4dff; margin-bottom: -2px; }

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 10px; }
.tab-content.active { display: block; }

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #666;
  margin-bottom: 8px;
  margin-top: 4px;
}

/* ===== Tower List ===== */
#tower-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tower-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #151525;
  border: 2px solid #252540;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
  color: #e0e0e0;
}
.tower-btn:hover { background: #1e1e35; border-color: #404060; }
.tower-btn.selected { border-color: #7c4dff; background: #1a1a35; }
.tower-btn.affordable { opacity: 1; }
.tower-btn.expensive { opacity: 0.5; }

.tower-btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.tower-btn-info { flex: 1; }
.tower-btn-name { font-size: 13px; font-weight: 700; }
.tower-btn-cost { font-size: 12px; color: #ffd740; font-weight: 600; }
.tower-btn-desc { font-size: 11px; color: #888; margin-top: 2px; }

/* ===== Tower Detail ===== */
.tower-detail {
  margin-top: 10px;
  background: #151525;
  border: 1px solid #252540;
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
}
.tower-detail.hidden { display: none; }

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid #1e1e35;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: #888; }
.stat-val { color: #fff; font-weight: 600; }

/* ===== Enemy List ===== */
#enemy-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.enemy-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #151525;
  border-radius: 6px;
  font-size: 12px;
}
.enemy-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.enemy-name { font-weight: 600; flex: 1; }
.enemy-hp { color: #888; font-size: 11px; }

.info-text p {
  font-size: 12px;
  color: #aaa;
  line-height: 1.6;
  margin-bottom: 8px;
  background: #151525;
  padding: 8px;
  border-radius: 6px;
}

/* ===== Placed Tower Panel ===== */
.placed-panel {
  padding: 10px;
  border-top: 2px solid #252540;
  background: #0d0d1e;
}
.placed-panel.hidden { display: none; }

.placed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

#placed-name {
  font-size: 14px;
  font-weight: 700;
}

#placed-stats {
  background: #151525;
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

#placed-upgrades {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upgrade-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: #1a2a1a;
  border: 1px solid #2a4a2a;
  border-radius: 8px;
  color: #90ee90;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
.upgrade-btn:hover { background: #243024; }
.upgrade-btn:disabled { background: #1a1a1a; border-color: #333; color: #555; cursor: not-allowed; }
.upgrade-btn.maxed { background: #1a1a35; border-color: #303060; color: #7c4dff; cursor: default; }

/* ===== Overlay ===== */
#overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#overlay.hidden { display: none; }

#overlay-box {
  background: #1a1a2e;
  border: 2px solid #7c4dff;
  border-radius: 16px;
  padding: 48px;
  text-align: center;
  min-width: 320px;
}

#overlay-title {
  font-size: 36px;
  font-weight: 900;
  margin-bottom: 16px;
}

#overlay-msg {
  font-size: 16px;
  color: #aaa;
  margin-bottom: 32px;
  line-height: 1.6;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a14; }
::-webkit-scrollbar-thumb { background: #303050; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #404070; }

/* ===== Sidebar collapse toggle (desktop: hidden) ===== */
#btn-sidebar-collapse {
  display: none;
  flex: 0 0 auto;
  padding: 10px 14px;
  font-size: 18px;
  line-height: 1;
  color: #666;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
#btn-sidebar-collapse:hover { color: #ccc; }

/* ===== Mobile Responsive ===== */
@media (max-width: 1100px) {
  body { overflow-x: hidden; }

  #app { width: 100%; min-width: 0; height: 100%; min-height: 0; }

  /* HUD: two-row compact layout */
  #hud {
    flex-wrap: wrap;
    height: auto;
    padding: 5px 10px;
    gap: 5px;
  }
  .hud-logo { display: none; }
  .hud-stats {
    flex: 1 1 auto;
    gap: 4px;
    justify-content: space-around;
    order: 1;
  }
  .hud-item  {
    flex: 1;
    min-width: 54px;
    max-width: 90px;
    padding: 4px 6px;
    font-size: 13px;
    gap: 3px;
    justify-content: center;
  }
  .hud-icon  { font-size: 14px; }
  .hud-controls {
    order: 2;
    width: 100%;
    gap: 5px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .hud-controls::-webkit-scrollbar { display: none; }
  .btn-primary   { padding: 9px 14px; font-size: 13px; white-space: nowrap; }
  .btn-secondary { padding: 9px 11px; font-size: 12px; white-space: nowrap; }

  /* Show collapse button on mobile */
  #btn-sidebar-collapse { display: flex; align-items: center; }

  /* Stack canvas above sidebar */
  #game-wrap {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  #canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 1000 / 720;
    touch-action: none;
    flex-shrink: 0;
  }

  /* Sidebar: fills remaining space below canvas */
  #sidebar {
    width: 100%;
    flex: 1;
    min-height: 120px;
    border-left: none;
    border-top: 2px solid #252540;
    overflow-y: auto;
    overflow-x: hidden;
    transition: min-height 0.25s ease, max-height 0.25s ease;
  }

  /* Collapsed sidebar: show only tab-bar */
  #sidebar.sidebar-collapsed { min-height: 0; max-height: 44px; overflow: hidden; }
  #sidebar.sidebar-collapsed .tab-content,
  #sidebar.sidebar-collapsed .placed-panel { display: none !important; }

  /* Bigger tap targets */
  .tab-btn    { padding: 12px 10px; font-size: 14px; min-height: 44px; }
  .tower-btn  { padding: 10px 12px; min-height: 54px; gap: 10px; }
  .tower-btn-icon { width: 36px; height: 36px; font-size: 20px; }
  .tower-btn-name { font-size: 14px; }
  .tower-btn-cost { font-size: 13px; }
  .upgrade-btn { min-height: 46px; padding: 10px 12px; font-size: 13px; }
  .btn-sell    { padding: 11px; font-size: 14px; min-height: 46px; }
  .stat-row    { padding: 5px 0; font-size: 13px; }
}
