/* ============================================================
   BASE — Mobile first
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:        #0b0c18;
  --bg2:       #12131f;
  --surface:   #1a1b2e;
  --border:    #ffffff10;
  --text:      #e0e0e0;
  --muted:     #666;
  --radius:    12px;
  --font-head: 'Fredoka One', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================================
   SPLASH
   ============================================================ */
#splash {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, #1a1040 0%, #0b0c18 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#splash.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-inner {
  text-align: center;
  padding: 20px;
  animation: splash-in 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes splash-in {
  from { opacity: 0; transform: translateY(30px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.splash-icon {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 14px;
  filter: drop-shadow(0 0 24px #b721ff88);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}

.splash-title {
  font-family: var(--font-head);
  font-size: 2.4rem;
  background: linear-gradient(90deg, #f7971e, #ffd200, #21d4fd, #b721ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  background-size: 200%;
  animation: shimmer 3s linear infinite;
  margin-bottom: 10px;
}

@keyframes shimmer {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.splash-sub {
  color: #888;
  font-size: 0.95rem;
  margin-bottom: 32px;
}

#splash-btn {
  background: linear-gradient(135deg, #b721ff, #21d4fd);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 14px 44px;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: var(--font-body);
  cursor: pointer;
  box-shadow: 0 4px 24px #b721ff44;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

#splash-btn:active { transform: scale(0.96); }

/* ============================================================
   APP WRAPPER
   ============================================================ */
.app-hidden  { opacity: 0; pointer-events: none; }
.app-visible {
  opacity: 1;
  pointer-events: auto;
  animation: app-in 0.5s ease both;
}

@keyframes app-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   HEADER
   ============================================================ */
header {
  padding: 12px 14px 6px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(to bottom, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  filter: drop-shadow(0 0 10px #b721ff66);
}

.header-text { flex: 1; min-width: 0; }

.header-text h1 {
  font-family: var(--font-head);
  font-size: 1.15rem;
  background: linear-gradient(90deg, #f7971e, #ffd200, #21d4fd, #b721ff);
  background-size: 200%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 4s linear infinite;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-text p {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 1px;
  display: none;
}

.header-text p strong { color: #888; font-weight: 700; }

#quiz-btn, #mute-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 8px 12px;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  line-height: 1;
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

#quiz-btn:active, #mute-btn:active { transform: scale(0.93); }
#mute-btn.muted { opacity: 0.4; }

/* ============================================================
   LEGEND
   ============================================================ */
.legend {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 10px 10px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: #666;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot--active { background: #fff; box-shadow: 0 0 6px #fff8; }
.legend-dot--cross  { background: #aaa; opacity: 0.7; }

.legend-dash {
  width: 20px;
  height: 0;
  border-top: 2px dashed #f7971e;
  opacity: 0.8;
  flex-shrink: 0;
}

/* ============================================================
   TABLES — Mobile: scroll-snap (base)
   ============================================================ */
#tables-container {
  display: flex;
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  gap: 12px;
  padding: 8px 6vw 12px;
  scrollbar-width: none;
}

#tables-container::-webkit-scrollbar { display: none; }

.table-wrapper {
  flex: 0 0 88vw;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.table-wrapper.visible {
  opacity: 1;
  transform: translateY(0);
}

.table-title {
  width: 100%;
  text-align: center;
  font-family: var(--font-head);
  font-size: 1.05rem;
  padding: 8px 0 4px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  transition: box-shadow 0.3s;
}

.table-title.glowing {
  box-shadow: 0 0 18px var(--tc-color);
}

/* Stars row below each table title */
.table-stars {
  font-size: 1rem;
  margin-bottom: 6px;
  min-height: 1.3rem;
  line-height: 1;
  letter-spacing: 2px;
}

table {
  border-collapse: separate;
  border-spacing: 0 3px;
  width: 100%;
}

tr.mul-row {
  cursor: pointer;
  transition: transform 0.15s;
}

tr.mul-row td {
  padding: 10px 8px;
  transition: background 0.2s, color 0.2s;
  background: #ffffff08;
  font-size: 0.9rem;
}

tr.mul-row td:first-child {
  border-radius: 8px 0 0 8px;
  color: #6666aa;
  white-space: nowrap;
  font-weight: 600;
}

tr.mul-row td:last-child {
  border-radius: 0 8px 8px 0;
  font-family: var(--font-head);
  font-size: 1.1rem;
  text-align: right;
  padding-right: 12px;
  color: #bbb;
}

tr.mul-row.is-source              { transform: scale(1.04); }
tr.mul-row.is-source td           { background: var(--tc-bg); }
tr.mul-row.is-source td:first-child { color: #fff; }
tr.mul-row.is-source td:last-child  { color: #fff; font-size: 1.2rem; }

tr.mul-row.is-cross td            { background: var(--tc-bg); }
tr.mul-row.is-cross td:first-child { color: #ddd; }
tr.mul-row.is-cross td:last-child  { color: #fff; }

/* ============================================================
   SCROLL NAVIGATION (mobile)
   ============================================================ */
#scroll-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px 4px;
}

#nav-prev, #nav-next {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.5rem;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
  flex-shrink: 0;
}

#nav-prev:active, #nav-next:active { transform: scale(0.9); }
#nav-prev:disabled, #nav-next:disabled { opacity: 0.2; pointer-events: none; }

#scroll-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.scroll-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #333;
  cursor: pointer;
  transition: background 0.3s, transform 0.3s;
  -webkit-tap-highlight-color: transparent;
}

.scroll-dot.active {
  background: #b721ff;
  transform: scale(1.5);
}

/* ============================================================
   CANVAS OVERLAY
   ============================================================ */
#canvas-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

/* ============================================================
   FOOTER
   ============================================================ */
footer {
  text-align: center;
  padding: 14px 16px 32px;
  color: var(--muted);
  font-size: 0.82rem;
}

footer strong { color: #aaa; }

.kofi-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 18px;
  min-height: 44px;
  background: transparent;
  border: 1px solid rgba(108, 99, 255, 0.3);
  border-radius: 50px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.kofi-btn:hover,
.kofi-btn:focus-visible {
  border-color: rgba(108, 99, 255, 0.7);
  color: #c9c6ff;
  background: rgba(108, 99, 255, 0.08);
  outline: none;
}

.kofi-btn:active { opacity: 0.7; }

.heart {
  display: inline-block;
  animation: heartbeat 1.4s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%       { transform: scale(1.3); }
  28%       { transform: scale(1); }
  42%       { transform: scale(1.2); }
}

/* ============================================================
   QUIZ OVERLAY
   ============================================================ */
#quiz-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 3000;
  transition: opacity 0.3s, visibility 0.3s;
  padding: 0;
}

#quiz-modal.quiz-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.quiz-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 540px;
  padding: 20px 18px 36px;
  max-height: 92vh;
  overflow-y: auto;
  animation: sheet-in 0.35s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

@keyframes sheet-in {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.quiz-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-title {
  font-family: var(--font-head);
  font-size: 1.3rem;
  flex: 1;
  background: linear-gradient(90deg, #21d4fd, #b721ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.quiz-score {
  font-weight: 800;
  font-size: 1rem;
  color: #aaa;
  white-space: nowrap;
}

#quiz-close {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

#quiz-progress-bar {
  height: 5px;
  background: #ffffff10;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 18px;
}

#quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #21d4fd, #b721ff);
  border-radius: 10px;
  transition: width 0.4s ease;
  width: 0%;
}

.quiz-table-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.quiz-question {
  font-family: var(--font-head);
  font-size: 2.6rem;
  text-align: center;
  margin-bottom: 22px;
  color: #fff;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-option {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 18px 10px;
  font-family: var(--font-head);
  font-size: 1.5rem;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}

.quiz-option:active { transform: scale(0.95); }

.quiz-option.correct {
  background: #26de8133;
  border-color: #26de81;
  color: #26de81;
}

.quiz-option.wrong {
  background: #ff596133;
  border-color: #ff5961;
  color: #ff5961;
}

.quiz-option:disabled {
  cursor: default;
  pointer-events: none;
}

#quiz-feedback {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 0;
  min-height: 2rem;
  transition: opacity 0.2s;
}

.quiz-fb-hidden { opacity: 0; }

#quiz-stars-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.quiz-star-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  color: var(--muted);
}

.quiz-star-item span:first-child {
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: #aaa;
}

.quiz-star-item .stars {
  font-size: 0.75rem;
  letter-spacing: 1px;
}

/* ============================================================
   RESPONSIVE — Tablet (≥ 600px)
   ============================================================ */
@media (min-width: 600px) {
  .header-text p { display: block; }

  #scroll-nav { display: none; }

  #tables-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    overflow-x: visible;
    scroll-snap-type: none;
    padding: 8px 16px 20px;
    gap: 10px;
  }

  .table-wrapper {
    flex: unset;
    scroll-snap-align: unset;
  }

  .table-title { font-size: 0.9rem; }

  tr.mul-row td         { padding: 8px 7px; font-size: 0.85rem; }
  tr.mul-row td:last-child { font-size: 1rem; padding-right: 10px; }
}

/* ============================================================
   RESPONSIVE — Desktop (≥ 1024px)
   ============================================================ */
@media (min-width: 1024px) {
  header { padding: 14px 20px 8px; }

  .header-text h1 { font-size: 1.3rem; }
  .header-text p  { font-size: 0.78rem; }

  #tables-container {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: none;
    padding: 10px 20px 20px;
    gap: 10px;
    justify-content: center;
  }

  .table-wrapper { flex: 0 0 auto; width: 155px; scroll-snap-align: unset; }
  tr.mul-row td  { padding: 7px 8px; font-size: 0.86rem; }
  tr.mul-row td:last-child { font-size: 1rem; padding-right: 12px; }
}

/* ============================================================
   VOICE BUTTON
   ============================================================ */
#voice-btn {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 1500;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #fd3a69, #b721ff);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 20px #fd3a6955;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}

#voice-btn:active { transform: scale(0.92); }

#voice-btn.listening {
  animation: voice-pulse 1.1s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%   { box-shadow: 0 0 0 0   #fd3a6999; }
  60%  { box-shadow: 0 0 0 18px #fd3a6900; }
  100% { box-shadow: 0 0 0 0   #fd3a6900; }
}

/* tooltip-like status badge */
#voice-status {
  position: fixed;
  bottom: 88px;
  right: 16px;
  z-index: 1500;
  background: #1a1b2e;
  border: 1px solid #ffffff18;
  color: #ccc;
  font-size: 0.75rem;
  font-family: var(--font-body);
  padding: 5px 12px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}

#voice-status.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
   INSTALL PWA BUTTON
   ============================================================ */
#install-banner {
  position: fixed;
  bottom: 24px;
  left: 20px;
  z-index: 1600;
  transform: translateY(80px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1), opacity 0.3s;
}

#install-banner.install-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

#install-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid #6c63ff66;
  border-radius: 50px;
  padding: 11px 18px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35), 0 0 0 1px #6c63ff22;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

#install-btn:hover {
  background: #23243a;
  box-shadow: 0 4px 24px rgba(108, 99, 255, 0.3), 0 0 0 1px #6c63ff44;
}

#install-btn:active {
  transform: scale(0.94);
}

/* ============================================================
   ONBOARDING
   ============================================================ */
#onboarding {
  position: fixed;
  inset: 0;
  z-index: 4000;
}

#onboarding.onboarding-hidden {
  display: none;
}

#onb-spotlight {
  position: fixed;
  background: transparent;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72);
  pointer-events: none;
  transition:
    top    0.4s cubic-bezier(0.4, 0, 0.2, 1),
    left   0.4s cubic-bezier(0.4, 0, 0.2, 1),
    width  0.4s cubic-bezier(0.4, 0, 0.2, 1),
    height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    border-radius 0.35s,
    opacity 0.3s;
}

#onb-bubble {
  position: fixed;
  background: #fff;
  color: #1a1b2e;
  border-radius: 16px;
  padding: 16px 18px 14px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.28);
  font-family: var(--font-body);
}

#onb-bubble.onb-step-enter {
  animation: onb-fade 0.3s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

#onb-bubble.onb-final.onb-step-enter {
  animation: onb-fade-final 0.35s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

@keyframes onb-fade {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

@keyframes onb-fade-final {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 14px)) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Arrow */
#onb-bubble::after {
  content: '';
  position: absolute;
  border: 11px solid transparent;
  pointer-events: none;
}

#onb-bubble[data-arrow="up"]::after {
  top: -21px;
  left: var(--arrow-offset, 22px);
  border-bottom-color: #fff;
}

#onb-bubble[data-arrow="down"]::after {
  bottom: -21px;
  left: var(--arrow-offset, 22px);
  border-top-color: #fff;
}

/* Step dots */
.onb-dots {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 10px;
}

.onb-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ddd;
  transition: background 0.25s, transform 0.25s;
}

.onb-dot.active {
  background: #b721ff;
  transform: scale(1.4);
}

#onb-text {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.5;
  color: #1a1b2e;
  margin-bottom: 14px;
}

.onb-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#onb-skip {
  background: none;
  border: none;
  color: #aaa;
  font-size: 0.82rem;
  font-family: var(--font-body);
  cursor: pointer;
  padding: 6px 2px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

#onb-skip:hover { color: #666; }

#onb-next {
  background: linear-gradient(135deg, #b721ff, #21d4fd);
  color: #fff;
  border: none;
  border-radius: 30px;
  padding: 9px 22px;
  font-size: 0.88rem;
  font-weight: 800;
  font-family: var(--font-body);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 3px 14px #b721ff44;
  transition: transform 0.12s, box-shadow 0.12s;
  -webkit-tap-highlight-color: transparent;
}

#onb-next:active { transform: scale(0.94); box-shadow: none; }

/* Final step */
#onb-bubble.onb-final {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(300px, calc(100vw - 40px));
  text-align: center;
}

#onb-bubble.onb-final::after {
  display: none;
}

#onb-bubble.onb-final .onb-actions {
  justify-content: center;
}

#onb-bubble.onb-final #onb-text {
  font-size: 1.1rem;
}
