:root {
  --bg-dark: #0a0c14;
  --card-bg: rgba(22, 27, 44, 0.75);
  --accent: #00ffaa;
  --accent-glow: rgba(0, 255, 170, 0.35);
  --danger: #ff3366;
  --halloween: #ff7700;
  --xmas: #33ccff;
  --text: #e2e8f0;
  --text-muted: #8492a6;
  --border: rgba(255, 255, 255, 0.08);
  --glass: blur(12px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-dark);
  color: var(--text);
  padding-bottom: 74px;
  min-height: 100vh;
}

header {
  background: rgba(10, 12, 20, 0.9);
  backdrop-filter: var(--glass);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 3px;
  box-shadow: 0 0 12px var(--accent-glow);
}

.connection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffcc00;
  transition: all 0.3s;
}

.status-indicator.online {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.status-indicator.offline {
  background: var(--danger);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

/* Discovery Banner */
.discovery-banner {
  background: rgba(0, 255, 170, 0.08);
  border: 1px solid rgba(0, 255, 170, 0.25);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.banner-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.banner-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
}

.banner-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.banner-actions {
  display: flex;
  gap: 6px;
}

.progress-bar-wrap {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* Tabs */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  backdrop-filter: var(--glass);
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* Controls */
.control-group {
  margin-bottom: 16px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.slider-val {
  color: var(--accent);
  font-weight: 600;
}

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

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
}

input[type="text"], select {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

input[type="text"]:focus, select:focus {
  border-color: var(--accent);
}

/* Buttons */
.btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border: none;
  box-shadow: 0 0 15px var(--accent-glow);
}

.btn-danger {
  background: rgba(255, 51, 102, 0.15);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* Category Filter Chips */
.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 8px;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.chip.active {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-color: var(--accent);
}

.chip-halloween.active {
  background: var(--halloween);
  border-color: var(--halloween);
  color: #000;
}

.chip-xmas.active {
  background: var(--xmas);
  border-color: var(--xmas);
  color: #000;
}

/* Effects Grid */
.effects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.effect-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 0.85rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.effect-card:active, .effect-card.active {
  border-color: var(--accent);
  background: rgba(0, 255, 170, 0.15);
  color: var(--accent);
  font-weight: 600;
}

.effect-card.cat-halloween { border-color: rgba(255, 119, 0, 0.35); }
.effect-card.cat-halloween.active { background: rgba(255, 119, 0, 0.2); color: var(--halloween); border-color: var(--halloween); }

.effect-card.cat-xmas { border-color: rgba(51, 204, 255, 0.35); }
.effect-card.cat-xmas.active { background: rgba(51, 204, 255, 0.2); color: var(--xmas); border-color: var(--xmas); }

/* Canvas 16x16 */
.canvas-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#matrix-canvas {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 1px;
  background: #000;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  touch-action: none;
  width: min(90vw, 320px);
  height: min(90vw, 320px);
  margin-bottom: 14px;
}

.pixel {
  background: #181a20;
  border-radius: 1px;
}

.palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s;
}

.color-dot.active {
  border-color: #fff;
  transform: scale(1.15);
}

/* Gamepad */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(3, 72px);
  gap: 8px;
  justify-content: center;
  margin: 20px auto 10px;
}

.dpad-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.dpad-btn:active {
  background: var(--accent);
  color: #000;
}

/* Nav Bar */
.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(10, 12, 20, 0.96);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 10px 4px;
  z-index: 100;
  backdrop-filter: var(--glass);
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex: 1;
  transition: color 0.2s;
}

.nav-btn.active {
  color: var(--accent);
  font-weight: 600;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}



/* Speed Slider Labels */
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Preset Buttons Active State */
.btn-preset.active {
  background: rgba(0, 255, 170, 0.2);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Running Text Color Picker & Gradient */
.text-color-selection {
  margin-top: 14px;
}

.control-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.color-picker-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 10px;
}

.color-input-wrap input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  padding: 0;
}
.color-input-wrap input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input-wrap input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; }

#text-color-hex {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 600;
}

.text-preview-strip {
  flex: 1;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#text-preview-sample {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 1px;
  transition: all 0.2s;
}

.text-mode-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mode-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-chip:hover, .mode-chip.active {
  background: rgba(0, 255, 170, 0.15);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* Palette Tools (Drawing) */
.palette-tools {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: 100%;
}

.custom-color-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.custom-color-wrap input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  background: none;
  padding: 0;
}
.custom-color-wrap input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-wrap input[type="color"]::-webkit-color-swatch { border-radius: 50%; border: 1px solid #fff; }

/* Games Styling */
.game-control-header {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.game-status-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  text-align: center;
}

.btn-game.active {
  border-color: var(--accent);
  background: rgba(0, 255, 170, 0.2);
  color: var(--accent);
  font-weight: 700;
}

/* Danger Zone */
.card-danger-zone {
  border-color: rgba(255, 51, 102, 0.35);
  background: rgba(255, 51, 102, 0.05);
}

.chip-new.active {
  background: #a855f7;
  border-color: #a855f7;
  color: #fff;
}

.effect-card.cat-new { border-color: rgba(168, 85, 247, 0.4); }
.effect-card.cat-new.active { background: rgba(168, 85, 247, 0.2); color: #c084fc; border-color: #a855f7; }
