/* Base Styles - Variables, resets, and global styles */
:root {
  /* slightly brighter dark theme palette */
  --bg-1: #181a20;
  --bg-2: #181a20;
  --card: #1c1f24;
  --card-overlay: rgba(28, 31, 36, 0.7);
  --stroke: #32343a;
  --text: #f0f2f5;
  --muted: #a4aab0;
  --accent: #c0c5cc;
  --accent-2: #d0d4da;
  --success: #b0b5bc;
  --danger: #b0b5bc;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.30);
  --input-bg: #171b22;
  --code-bg: #13181f;
  --bubble-bg: rgba(24, 26, 33, 0.7);
  --bubble-user-bg: rgba(96, 165, 250, 0.14);
  --button-text: #181a20;
  --dock-bg: rgba(28, 31, 36, 0.8);
  --dock-border: #32343a;
  --dock-item-bg: rgba(28, 31, 36, 0.9);
  --dock-item-hover: rgba(188, 193, 200, 0.12);
  --dock-label-bg: rgba(28, 31, 36, 0.95);
  --mobile-bottom-offset: 0px;
}

:root[data-theme="light"] {
  --bg-1: #f5f6f8;
  --bg-2: #f5f6f8;
  --card: #ffffff;
  --card-overlay: rgba(255, 255, 255, 0.9);
  --stroke: #d5d9df;
  --text: #1f2933;
  --muted: #5f6b7a;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --success: #15803d;
  --danger: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
  --input-bg: #f8fafc;
  --code-bg: #eef2f7;
  --bubble-bg: rgba(255, 255, 255, 0.9);
  --bubble-user-bg: rgba(37, 99, 235, 0.12);
  --button-text: #f8fafc;
  --dock-bg: rgba(255, 255, 255, 0.9);
  --dock-border: #d5d9df;
  --dock-item-bg: rgba(255, 255, 255, 0.95);
  --dock-item-hover: rgba(37, 99, 235, 0.12);
  --dock-label-bg: rgba(255, 255, 255, 0.98);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Domine", "Segoe UI", system-ui, -apple-system, serif;
  color: var(--text);
  min-height: 100vh;
  height: 100vh;
  width: 100%;
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
    height: 100dvh;
  }
}

button,
input,
textarea,
select {
  touch-action: manipulation;
}

.theme-toggle {
  position: static;
  height: 36px;
  padding: 0 12px;
  border-radius: 0;
  border: 1px solid var(--stroke);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* color slider next to theme toggle */
#colorSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  margin: 0 8px;
  vertical-align: middle;
}

#colorSlider::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(90deg, hsl(0,50%,60%) 0%, hsl(60,50%,60%) 16%, hsl(120,50%,60%) 33%, hsl(180,50%,60%) 50%, hsl(240,50%,60%) 66%, hsl(300,50%,60%) 83%, hsl(360,50%,60%) 100%);
  border-radius: 3px;
}

#colorSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 1px solid var(--stroke);
  border-radius: 50%;
  margin-top: -4px;
}

#colorSlider:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(100, 150, 255, 0.4);
}

.theme-toggle:hover {
  filter: brightness(1.04);
}

/* settings modal separator */
.modal-row hr {
  border: none;
  border-top: 1px solid var(--stroke);
  margin: 0.5em 0;
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.answer-content.popIn {
  animation: popIn 300ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* settings modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85); /* more opaque overlay */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(2px);
  transition: opacity 0.25s ease;
}
.modal.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-content {
  /* slightly lighter than surrounding card for visibility */
  background: color-mix(in srgb, var(--card) 85%, #ffffff 15%);
  padding: 30px 24px;
  max-width: 400px;
  width: 90%;
  border-radius: 8px;
  /* ensure modal fits viewport and scrolls internally if needed */
  max-height: 80vh;
  overflow-y: auto;
  /* override per-modal in quiz.css for shuffle if needed */
  position: relative;
  box-shadow: 0 12px 24px rgba(0,0,0,0.35);
  border: 1px solid var(--stroke);
  animation: pop 220ms ease;
}

/* give palette a subtle card-like background so scroll bar blends */
.theme-palette {
  background: var(--card);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}
.modal-content h2 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.25rem;
  text-align: center;
}
.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.2s;
}
.close-btn:hover {
  color: var(--text);
}
.modal-row {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}
.modal-row label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.modal-row input[type="range"] {
  width: 100%;
}
.modal-row input[type="color"] {
  width: 100%;
  height: 2.2rem;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
}
.modal-row input[type="checkbox"] {
  transform: scale(1.1);
  margin-right: 0.5rem;
}

/* theme palette cards */
.theme-palette {
  display: flex;
  flex-wrap: nowrap;            /* keep a single row */
  gap: 0.5rem;
  margin-top: 0.5rem;
  overflow-x: auto;            /* scroll on overflow */
  max-height: 120px;           /* fallback if wrap occurs */
  overflow-y: auto;
  padding-bottom: 0.5rem;      /* space for scrollbar */

  /* scrolling performance hints */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  will-change: scroll-position, transform;
}

.theme-card {
  flex: 0 0 80px;
  height: 50px;
  border: 1px solid var(--muted);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  /* hide any inner text; rely on title tooltip */
  color: transparent;
  font-size: 0;
  /* promote to own layer for smoother scrolling */
  transform: translateZ(0);
  will-change: transform;
}

.theme-card:hover,
.theme-card:focus {
  transform: translateY(-2px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.24);
  border-color: var(--text);
  outline: none;
}

/* add-card style for "new palette" button */
.theme-card.add-card {
  font-size: 1.5rem;
  color: var(--text);
  background: var(--bg-1);
  border: 2px dashed var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* scrollbar styling for theme row */
.theme-palette {
  scrollbar-width: thin;
  scrollbar-color: var(--text-secondary) var(--bg-1);
}
.theme-palette::-webkit-scrollbar {
  height: 8px;
}
.theme-palette::-webkit-scrollbar-track {
  background: var(--bg-1);
}
.theme-palette::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  opacity: 0.6;
  border-radius: 4px;
}
.theme-palette::-webkit-scrollbar-thumb:hover {
  opacity: 0.8;
}

/* modal scrollbar consistency */
.modal-content {
  scrollbar-width: thin;
  scrollbar-color: var(--text-secondary) var(--bg-1);
}

.theme-card.add-card:hover,
.theme-card.add-card:focus {
  border-style: solid;
}
