/* ==========================================================================
   WEB GPU KACHEL STUDIO & 3D ROOM SUITE - CORE STYLESHEET
   ========================================================================== */

:root {
  --bg-dark: #0a0d14;
  --bg-card: rgba(19, 24, 35, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-hover: rgba(26, 33, 48, 0.85);
  --bg-input: rgba(15, 20, 30, 0.8);
  
  --color-primary: #00f2fe;
  --color-primary-glow: rgba(0, 242, 254, 0.25);
  --color-accent: #4facfe;
  --color-emerald: #10b981;
  --color-gold: #f59e0b;
  --color-pink: #ec4899;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code: 'Fira Code', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --shadow-glow: 0 0 20px rgba(0, 242, 254, 0.2);
  --transition-fast: 0.15s ease;
  --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body.theme-dark {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(0, 242, 254, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(245, 158, 11, 0.03) 0%, transparent 40%);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: #1e293b;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #334155;
}

/* Layout Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header Navbar */
.studio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bg-card-border);
  z-index: 100;
  height: 60px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 8px rgba(0, 242, 254, 0.4));
}

.brand-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.brand-accent {
  color: var(--color-primary);
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-version {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-code);
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(15, 20, 30, 0.6);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.nav-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-btn.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.2), rgba(79, 172, 254, 0.2));
  border: 1px solid rgba(0, 242, 254, 0.3);
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.15);
}

.nav-game-btn.active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.2));
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--color-gold);
}

/* GPU Indicator Status */
.header-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.gpu-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-emerald);
}

.indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-emerald);
  box-shadow: 0 0 8px var(--color-emerald);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.gpu-indicator.fallback {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--color-gold);
}
.gpu-indicator.fallback .indicator-dot {
  background: var(--color-gold);
  box-shadow: 0 0 8px var(--color-gold);
}

/* Buttons System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: var(--transition-smooth);
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #090d16;
  font-weight: 700;
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: var(--shadow-glow);
}

.btn-accent {
  background: linear-gradient(135deg, #00f2fe, #4facfe);
  color: #000;
  font-weight: 700;
}
.btn-accent:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(0, 242, 254, 0.3);
}

.btn-emerald {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}
.btn-emerald:hover {
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-primary);
}
.btn-outline:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn-xs { padding: 0.2rem 0.5rem; font-size: 0.72rem; }
.btn-full { width: 100%; }

/* Workspace Section Layout */
.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.tab-content {
  display: none;
  height: 100%;
  width: 100%;
}
.tab-content.active {
  display: flex;
}

/* Sidebar Panels */
.sidebar-panel {
  width: 340px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  gap: 1.25rem;
  overflow-y: auto;
  z-index: 10;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h3 {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.badge {
  font-size: 0.68rem;
  padding: 0.2rem 0.5rem;
  background: rgba(0, 242, 254, 0.1);
  color: var(--color-primary);
  border: 1px solid rgba(0, 242, 254, 0.25);
  border-radius: var(--radius-sm);
  font-family: var(--font-code);
}
.badge-accent {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-gold);
  border-color: rgba(245, 158, 11, 0.25);
}
.badge-gold {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-gold);
  border-color: rgba(245, 158, 11, 0.3);
}

/* Control Groups */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.control-label .hint {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Preset Buttons Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.5rem 0.65rem;
  background: rgba(15, 20, 30, 0.6);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: left;
}

.preset-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.preset-btn.active {
  background: rgba(0, 242, 254, 0.12);
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 700;
}

/* Prompt Box */
.prompt-box {
  display: flex;
  gap: 0.4rem;
}

.prompt-box input[type="text"],
.control-group input[type="text"] {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  outline: none;
  transition: var(--transition-fast);
}

.prompt-box input[type="text"]:focus,
.control-group input[type="text"]:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 8px rgba(0, 242, 254, 0.2);
}

/* Sliders Group */
.sliders-group {
  gap: 0.85rem;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.slider-row label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.slider-val {
  font-family: var(--font-code);
  font-size: 0.75rem;
  color: var(--color-primary);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  box-shadow: 0 0 6px var(--color-primary);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Color Palette Row */
.color-palette-row {
  display: flex;
  gap: 0.6rem;
}

.color-palette-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  width: 100%;
  height: 34px;
  cursor: pointer;
  background: transparent;
}
.color-palette-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
.color-palette-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: var(--radius-md);
}

/* Viewport Panel (Canvas View) */
.viewport-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #06080d;
  position: relative;
  overflow: hidden;
}

.viewport-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  background: rgba(10, 13, 20, 0.6);
  border-bottom: 1px solid var(--bg-card-border);
  z-index: 5;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.active-preset-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
}

.resolution-badge {
  font-family: var(--font-code);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Canvas Wrapper */
.canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 1.5rem;
  user-select: none;
}

.canvas-wrapper canvas {
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  cursor: crosshair;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.canvas-wrapper canvas:hover {
  box-shadow: 0 16px 50px rgba(0, 242, 254, 0.15);
}

/* Click Overlay Hint */
.canvas-overlay-hint {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(19, 24, 35, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--bg-card-border);
  border-radius: 30px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  pointer-events: none;
  animation: float-hint 3s infinite ease-in-out;
}

@keyframes float-hint {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -4px); }
}

/* Segmented Buttons */
.btn-group-segmented {
  display: flex;
  background: rgba(15, 20, 30, 0.6);
  padding: 0.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.segmented-btn {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
}

.segmented-btn.active {
  background: rgba(0, 242, 254, 0.15);
  color: var(--color-primary);
  font-weight: 700;
}

/* Scene Presets Buttons */
.scene-presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.scene-btn {
  padding: 0.5rem;
  background: rgba(15, 20, 30, 0.6);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-fast);
}

.scene-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.scene-btn.active {
  border-color: var(--color-gold);
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-gold);
  font-weight: 700;
}

/* 3D Room Specifics */
.room-3d-wrapper {
  padding: 0;
}

.room-hint {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 0.8rem;
  background: rgba(10, 13, 20, 0.75);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.current-tile-mini {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--bg-card-border);
}

.mini-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.mini-tile-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(15, 20, 30, 0.6);
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.mini-tile-preview canvas {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.mini-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mini-info span {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.8rem;
}

/* History View */
.history-view-container {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-header h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
}

.history-header p {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.history-actions {
  display: flex;
  gap: 0.5rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: var(--transition-smooth);
}

.history-card:hover {
  transform: translateY(-3px);
  border-color: rgba(0, 242, 254, 0.3);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.history-card-canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  background: #000;
  object-fit: cover;
}

.history-card-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.history-card-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.9rem;
}

.history-card-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-card-btns {
  display: flex;
  gap: 0.4rem;
}

/* Game Mode */
.game-view-container {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-title-group h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 800;
}

.game-score-badge {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-lg);
  font-family: var(--font-code);
  font-size: 0.9rem;
  color: var(--color-gold);
}

.game-mode-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.game-mode-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-smooth);
}

.game-mode-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.game-mode-card.active {
  border-color: var(--color-gold);
  background: rgba(245, 158, 11, 0.08);
}

.game-mode-card .mode-icon {
  font-size: 1.8rem;
}

.game-mode-card h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--text-primary);
}

.game-mode-card p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.game-stage {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

/* POPOVER MODAL */
.popover-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
}

.popover-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.popover-backdrop {
  position: absolute;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}

.popover-card {
  position: relative;
  width: 520px;
  max-width: 90vw;
  background: #111622;
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), var(--shadow-glow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--bg-card-border);
}

.popover-header h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--color-primary);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.btn-close:hover { color: var(--text-primary); }

.popover-body {
  padding: 1.25rem;
  display: flex;
  gap: 1.25rem;
}

.popover-preview-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 180px;
}

.popover-preview-col canvas {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
  object-fit: cover;
}

.popover-controls-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.quick-palettes-grid {
  display: flex;
  gap: 0.4rem;
}

.palette-chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s;
}

.palette-chip:hover {
  transform: scale(1.15);
  border-color: #fff;
}

.popover-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .sidebar-panel { width: 280px; }
  .brand-title { font-size: 1rem; }
  .nav-btn { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
  .game-mode-selector { grid-template-columns: 1fr; }
}
