/* ==========================================================================
   Celestial Weaver - Design System & Stylesheet
   ========================================================================== */

:root {
  --bg-primary: #080a15;
  --bg-secondary: rgba(18, 24, 48, 0.7);
  --bg-card: rgba(26, 34, 64, 0.65);
  --border-glass: rgba(255, 255, 255, 0.14);
  --border-glow: rgba(0, 242, 254, 0.5);

  --text-primary: #f0f4fc;
  --text-secondary: #a0aec0;
  --text-muted: #64748b;

  --color-cyan: #00f2fe;
  --color-magenta: #f50057;
  --color-yellow: #ffe000;
  --color-green: #38ef7d;
  --color-red: #ff4b4b;
  --color-blue: #00b4db;
  --color-purple: #9d50bb;

  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-neon: 0 0 16px rgba(0, 242, 254, 0.35);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.5);
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  line-height: 1.4;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #151a36 0%, #080a15 80%);
}

/* --------------------------------------------------------------------------
   Header Bar
   -------------------------------------------------------------------------- */
#header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-glass);
  z-index: 10;
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

#app-logo {
  filter: drop-shadow(0 0 6px rgba(0, 242, 254, 0.6));
}

#app-title {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff 0%, var(--color-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
}

#level-badge {
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-cyan);
}

#header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   Main Content Layout
   -------------------------------------------------------------------------- */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  overflow: hidden;
  gap: 8px;
}

#objective-banner {
  width: 100%;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* --------------------------------------------------------------------------
   Canvas Container
   -------------------------------------------------------------------------- */
#canvas-container {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 200px;
}

#game-canvas {
  background: rgba(10, 14, 28, 0.8);
  border-radius: var(--radius-md);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.6), inset 0 0 1px rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-glass);
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Inventory Section
   -------------------------------------------------------------------------- */
#inventory-section {
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#inventory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}

#inventory-title {
  font-weight: 700;
  color: var(--color-cyan);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

#inventory-hint {
  color: var(--text-muted);
  font-size: 0.72rem;
}

#inventory-palette {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  min-height: 60px;
  align-items: center;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 58px;
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid var(--border-glass);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
  padding: 4px;
  position: relative;
}

.palette-item:hover, .palette-item:focus {
  background: rgba(0, 242, 254, 0.1);
  border-color: var(--color-cyan);
}

.palette-item.selected {
  background: rgba(0, 242, 254, 0.2);
  border-color: var(--color-cyan);
  box-shadow: var(--shadow-neon);
}

.palette-item .count-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--color-cyan);
  color: #000;
  font-size: 0.7rem;
  font-weight: 800;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.palette-item canvas {
  pointer-events: none;
}

.palette-item-name {
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   Buttons & Controls
   -------------------------------------------------------------------------- */
#footer-controls {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
  padding-bottom: 6px;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  transition: var(--transition-fast);
  outline: none;
}

.btn-primary {
  flex: 2;
  background: linear-gradient(135deg, #00b4db 0%, #00f2fe 100%);
  color: #04091a;
  box-shadow: 0 4px 16px rgba(0, 242, 254, 0.3);
  font-weight: 700;
  letter-spacing: 0.3px;
}

.btn-primary:hover, .btn-primary:focus {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 242, 254, 0.5);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
  min-height: 44px;
  padding: 0 14px;
  font-size: 0.88rem;
}

.btn-secondary:hover, .btn-secondary:focus {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* --------------------------------------------------------------------------
   Toast Notification
   -------------------------------------------------------------------------- */
.hidden {
  display: none !important;
}

#toast-overlay {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
}

#toast-card {
  background: rgba(255, 75, 75, 0.95);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(255, 75, 75, 0.4);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 18, 0.88);
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-glass);
}

.modal-header h2 {
  font-size: 1.15rem;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

#level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 70px;
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid var(--border-glass);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  color: var(--text-primary);
  font-weight: 700;
}

.level-btn:hover {
  border-color: var(--color-cyan);
  background: rgba(0, 242, 254, 0.1);
}

.level-btn.completed {
  border-color: var(--color-green);
  background: rgba(56, 239, 125, 0.1);
}

.level-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.level-btn .stars-sub {
  font-size: 0.7rem;
  margin-top: 2px;
}

/* Modal Complete Card */
.modal-complete-card {
  text-align: center;
  border-color: var(--color-cyan);
  box-shadow: var(--shadow-neon);
}

.modal-complete-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#stars-rating {
  font-size: 2.2rem;
  letter-spacing: 4px;
}

#complete-description {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

#complete-stats {
  display: flex;
  gap: 20px;
  width: 100%;
  justify-content: center;
}

.stat-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-cyan);
}

.modal-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
}

/* --------------------------------------------------------------------------
   Responsive Adjustments (Mobile & Landscape)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  #header-bar {
    padding: 8px 10px;
  }
  #app-title {
    font-size: 0.95rem;
  }
  #level-badge {
    padding: 4px 10px;
    font-size: 0.75rem;
  }
  .btn-secondary {
    padding: 0 8px;
    font-size: 0.8rem;
  }
  #footer-controls {
    gap: 8px;
  }
  #level-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  .level-btn {
    height: 60px;
  }
}

@media (max-height: 550px) and (orientation: landscape) {
  #app {
    flex-direction: row;
    max-width: 100%;
  }
  #header-bar {
    flex-direction: column;
    justify-content: flex-start;
    gap: 16px;
    width: 180px;
    height: 100%;
    border-bottom: none;
    border-right: 1px solid var(--border-glass);
  }
  #header-actions {
    flex-direction: column;
    width: 100%;
  }
  #header-actions button {
    width: 100%;
  }
  #main-content {
    flex: 1;
    height: 100%;
  }
}
