/* ============================================================
   PIXEL BATTLE - Compact Modern Game Stylesheet
   Canvas-first layout: 85-90% canvas viewport, compact HUD
   ============================================================ */

:root {
  --scale: 1;
  --bg-dark: #0a0c0f;
  --bg-surface: #13161f;
  --bg-card: #1b1f2b;
  --bg-hover: #262c3d;
  --border-color: #272d3d;
  --border-light: #373f55;
  --text-main: #f1f3f9;
  --text-muted: #8b92a5;
  --accent-color: #be0039;
  --accent-hover: #e0124f;
  --online-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --radius-sm: 4px;
  --radius-md: 6px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   Header: 44px compact
   ============================================================ */
.app-header {
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  flex: 0 0 44px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
}

.brand-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

.header-online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: #34d399;
  background: #0f241a;
  border: 1px solid #165339;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
}

.online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--online-color);
  display: inline-block;
}

.header-coords {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  min-width: 90px;
  text-align: center;
}

/* ============================================================
   Canvas Section & Viewport (85-90% of screen height)
   ============================================================ */
.canvas-section {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background-color: #08090c;
  background-image: radial-gradient(#1e2230 1px, transparent 1px);
  background-size: 20px 20px;
  touch-action: none;
}

.canvas-viewport {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
}

.canvas-viewport.is-dragging {
  cursor: grabbing;
}

.canvas-transform-wrapper {
  position: absolute;
  transform-origin: center center;
  will-change: transform;
}

#boardCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7), 0 0 0 1px #333a4c;
  border: none;
  background-color: #ffffff;
}

/* Hover preview reticle (strictly 1x1 logic pixel with crisp inset contour) */
.pixel-hover-reticle {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  pointer-events: none;
  box-sizing: border-box;
  display: none;
  outline: none;
  border: none;
  box-shadow: inset 0 0 0 0.1px #000000;
  box-shadow: inset 0 0 0 calc(1px / var(--scale, 10)) #000000;
  z-index: 9;
  opacity: 0.6;
}

/* Confirmed target reticle (strictly 1x1 logic pixel with crisp inset black contour) */
.pixel-reticle {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  pointer-events: none;
  box-sizing: border-box;
  display: none;
  outline: none;
  border: none;
  box-shadow: inset 0 0 0 0.1px #000000;
  box-shadow: inset 0 0 0 calc(1px / var(--scale, 10)) #000000;
  z-index: 10;
}

/* HUD controls on Canvas */
.viewport-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  z-index: 15;
}

.zoom-controls {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.btn-icon {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}

.btn-icon:last-child {
  border-right: none;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: #ffffff;
}

.hud-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(23, 25, 34, 0.85);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* ============================================================
   Bottom Footer Controls: Compact, max ~125px
   ============================================================ */
.app-footer {
  flex: 0 0 auto;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 14px 12px 14px;
  z-index: 20;
  min-height: 105px;
  max-height: 130px;
}

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  line-height: 1.2;
}

.selected-swatch-wrapper, .selected-pixel-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.selection-label {
  color: var(--text-muted);
  font-size: 11px;
}

.selected-swatch-preview {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background-color: var(--accent-color);
  border: 1px solid rgba(255, 255, 255, 0.3);
  display: inline-block;
}

.color-hex {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.selected-pixel-info strong {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #60a5fa;
}

/* Palette: Strictly single horizontal row with horizontal scroll */
.palette-container {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: 6px !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  white-space: nowrap !important;
  padding: 1px 0 !important;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
  width: 100% !important;
  height: 32px !important;
  min-height: 32px !important;
  max-height: 32px !important;
  -webkit-overflow-scrolling: touch;
}

.palette-grid {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  align-items: center !important;
  flex-shrink: 0 !important;
  height: 28px !important;
}

.swatch {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  max-width: 26px !important;
  min-height: 26px !important;
  max-height: 26px !important;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0 !important;
  display: inline-block !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  transition: transform 0.1s ease, border-color 0.1s ease;
  position: relative;
}

.swatch:hover {
  transform: scale(1.15);
}

.swatch.is-selected {
  transform: scale(1.15);
  border-color: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
  z-index: 2;
}

.custom-color-btn {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  max-width: 26px !important;
  min-height: 26px !important;
  max-height: 26px !important;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px dashed var(--border-light);
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-muted);
  position: relative;
  overflow: hidden;
  flex-shrink: 0 !important;
  margin: 0 !important;
}

.custom-color-btn input[type="color"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Action Panel & Cooldown */
.action-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.cooldown-wrapper {
  display: flex;
  flex-direction: column;
}

.cooldown-timer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cooldown-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.3px;
}

.cooldown-pill.ready {
  background: #0f241a;
  color: #34d399;
  border: 1px solid #165339;
}

.cooldown-pill.waiting {
  background: #2b1f0d;
  color: #f59e0b;
  border: 1px solid #78480d;
}

.status-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.target-status {
  color: var(--text-muted);
  font-size: 11px;
}

.target-coords {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #60a5fa;
  margin-left: 4px;
}

.cooldown-timer {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--text-main);
  line-height: 1.1;
}

.cooldown-timer.active {
  color: var(--warning-color);
}

.cooldown-subtext {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.btn-place {
  flex: 1;
  max-width: 260px;
  height: 38px;
  border-radius: var(--radius-md);
  border: none;
  background-color: var(--accent-color);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.08s;
  box-shadow: 0 2px 10px rgba(190, 0, 57, 0.4);
}

.btn-place:hover:not(:disabled) {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-place:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-place:disabled {
  background-color: var(--bg-card);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.7;
}

/* ============================================================
   Toast Notifications
   ============================================================ */
.toast-container {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: auto;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-success {
  border-color: rgba(16, 185, 129, 0.4);
  background: #0f241a;
  color: #34d399;
}

.toast.toast-error {
  border-color: rgba(239, 68, 68, 0.4);
  background: #2b1115;
  color: #f87171;
}

.toast.toast-warning {
  border-color: rgba(245, 158, 11, 0.4);
  background: #261f10;
  color: #fbbf24;
}

/* ============================================================
   Mobile layout adjustments
   ============================================================ */
@media (max-width: 600px) {
  .app-header {
    height: 40px;
    padding: 0 10px;
  }
  .app-footer {
    padding: 6px 10px 10px 10px;
    gap: 6px;
  }
  .btn-place {
    max-width: 100%;
    height: 38px;
  }
}
