/* ── Reset & base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: #0f0e17;
  color: #fffffe;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────── */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  background: #1a1a2e;
  border-bottom: 2px solid #264653;
  flex-shrink: 0;
  z-index: 10;
}

.header-brand {
  font-size: 1.5rem;
  font-weight: 900;
  color: #e9c46a;
  letter-spacing: 1px;
}

#progress-counter {
  font-size: 1.1rem;
  font-weight: 700;
  color: #a8dadc;
}

/* ── Buttons ──────────────────────────────────── */
button {
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  transition: transform 0.1s, background 0.2s;
}
button:active { transform: scale(0.95); }

.btn-secondary {
  background: #264653;
  color: #fffffe;
  padding: 10px 18px;
  font-size: 0.95rem;
  min-height: 44px;
}
.btn-secondary:hover { background: #2a6880; }

.btn-nav {
  background: #1275c8;
  color: #fffffe;
  padding: 14px 28px;
  font-size: 1.1rem;
  min-height: 60px;
  min-width: 120px;
  border: 2px solid transparent;
  transition: background 0.2s, box-shadow 0.2s, transform 0.15s, border-color 0.2s;
}
.btn-nav:hover:not(:disabled) {
  background: #1a9fff;
  box-shadow: 0 6px 24px rgba(26, 159, 255, 0.55);
  transform: translateY(-2px) scale(1.05);
  border-color: rgba(26, 159, 255, 0.4);
}
.btn-nav:active:not(:disabled) {
  transform: scale(0.95);
  box-shadow: none;
  border-color: transparent;
}
.btn-nav:disabled {
  background: #1a1a2e;
  color: #36365a;
  cursor: not-allowed;
  border: 2px solid #252545;
  box-shadow: none;
  transform: none;
}

.pill {
  background: #264653;
  color: #fffffe;
  width: 44px;
  height: 44px;
  font-size: 1.1rem;
  font-weight: 900;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  border: 2px solid transparent;
  user-select: none;
}
.pill:hover { background: #3b6978; transform: scale(1.05); }
.pill.active  { border-color: #e9c46a; background: #3b6978; }
.pill.done    { background: #2d6a4f; color: #e9c46a; }

/* ── Main layout ──────────────────────────────── */
#app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Canvas area ──────────────────────────────── */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  gap: 12px;
  min-width: 0;
}

#canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 4/3;
  border-radius: 16px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.40;
  z-index: 0;
}

/* ── Filter canvas — transparent overlay layer ─── */
#filter-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  opacity: 1;          /* transparent pixels let video through — no forced opacity */
  z-index: 1;
  pointer-events: none;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  opacity: 1;
}

/* ── Hand prompt ──────────────────────────────── */
.hand-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.7);
  color: #fffffe;
  font-size: 1.6rem;
  font-weight: 900;
  padding: 18px 32px;
  border-radius: 16px;
  animation: pulse 1.4s ease-in-out infinite;
  pointer-events: none;
  z-index: 5;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  50%       { opacity: 0.6; transform: translate(-50%, -50%) scale(1.05); }
}

/* ── Camera off overlay ───────────────────────── */
#camera-off-overlay,
#camera-requesting-overlay {
  position: absolute;
  inset: 0;
  background: #111118;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 8;
  color: #7a8a9a;
  font-size: 1rem;
  font-weight: 700;
  pointer-events: none;
}

.cam-off-icon {
  width: 72px;
  height: 72px;
  background: #1e2535;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cam-off-icon svg {
  width: 38px;
  height: 38px;
  stroke: #4a5a6a;
}

.cam-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #264653;
  border-top-color: #a8dadc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Loading progress bar in overlay ────────── */
.loading-progress-wrap {
  width: 200px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

#cam-req-progress-bar {
  height: 100%;
  width: 0%;
  background: #e9c46a;
  transition: width 0.4s ease;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Camera / Clear buttons in nav row ────────── */
.btn-cam {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #2d6a4f;
  color: #fffffe;
  padding: 14px 20px;
  font-size: 1rem;
  min-height: 60px;
}

.btn-cam svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  pointer-events: none;
}

.btn-cam.cam-on  { background: #2d6a4f; }
.btn-cam.cam-on:hover { background: #40916c; box-shadow: none; transform: none; border-color: transparent; }

.btn-cam.cam-off-state { background: #c1121f; }
.btn-cam.cam-off-state:hover { background: #e5383b; box-shadow: none; transform: none; border-color: transparent; }

.btn-cam:disabled {
  background: #2a2a3e !important;
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.btn-cam-permission { background: #1d3557 !important; }
.btn-cam-permission:hover { background: #457b9d !important; }

.btn-clear {
  background: #4a3728;
  color: #f4a261;
}
.btn-clear:hover { background: #6b4c38; box-shadow: none; transform: none; border-color: transparent; }

/* ── Progress bar ─────────────────────────────── */
#progress-bar-wrap {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  height: 22px;
  background: rgba(0,0,0,0.5);
  border-radius: 11px;
  overflow: hidden;
  display: flex;
  align-items: center;
  z-index: 5;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2d6a4f, #52b788);
  border-radius: 11px;
  transition: width 0.3s ease;
}

#progress-pct {
  position: absolute;
  right: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fffffe;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* ── Nav buttons ──────────────────────────────── */
#nav-buttons {
  display: flex;
  gap: 12px;
  align-items: stretch;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Filter dropdown wrapper ──────────────────── */
.filter-dropdown-wrap {
  position: relative;
  display: inline-flex;
}

/* ── Filter toggle button ─────────────────────── */
.btn-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1d3557;
  color: #fffffe;
  padding: 14px 20px;
  font-size: 1rem;
  min-height: 60px;
  border-radius: 12px;
  transition: background 0.2s, transform 0.1s;
}
.btn-filter:hover { background: #2a4f7a; }
.btn-filter[aria-expanded="true"] {
  background: #2a4f7a;
  border-radius: 12px 12px 0 0;
}

.filter-chevron {
  font-size: 0.8rem;
  opacity: 0.7;
  transition: transform 0.2s;
}
.btn-filter[aria-expanded="true"] .filter-chevron {
  transform: rotate(180deg);
}

/* ── Filter dropdown menu ─────────────────────── */
.filter-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #1d3557;
  border: 1px solid #2a4f7a;
  border-top: none;
  border-radius: 0 0 12px 12px;
  overflow-y: auto;
  max-height: 172px;
  list-style: none;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: dropdown-open 0.15s ease forwards;
  scrollbar-width: thin;
  scrollbar-color: #2a4f7a #1d3557;
}
.filter-menu::-webkit-scrollbar {
  width: 6px;
}
.filter-menu::-webkit-scrollbar-track {
  background: #1d3557;
  border-radius: 0 0 12px 0;
}
.filter-menu::-webkit-scrollbar-thumb {
  background: #2a4f7a;
  border-radius: 3px;
}
.filter-menu::-webkit-scrollbar-thumb:hover {
  background: #e9c46a;
}

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

.filter-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  color: #fffffe;
  transition: background 0.15s;
}
.filter-option:hover { background: #2a9d8f33; }
.filter-option.active {
  color: #e9c46a;
  background: rgba(233, 196, 106, 0.1);
}

/* ── Celebration ──────────────────────────────── */
#celebration {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#well-done-label {
  position: relative;
  font-size: 3rem;
  font-weight: 900;
  color: #e9c46a;
  text-shadow: 0 4px 20px rgba(0,0,0,0.8), 0 0 40px #e9c46a;
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  z-index: 21;
}

@keyframes pop-in {
  0%   { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

.hidden { display: none !important; }

/* ── Sidebar ──────────────────────────────────── */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #1a1a2e;
  border-left: 2px solid #264653;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
  overflow-y: auto;
}

#alphabet-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

#letter-info {
  background: #264653;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#info-label {
  font-size: 0.85rem;
  color: #a8dadc;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#info-letter {
  font-size: 4rem;
  font-weight: 900;
  color: #e9c46a;
  line-height: 1;
  text-align: center;
}

#info-stroke {
  font-size: 1rem;
  font-weight: 700;
  color: #fffffe;
  text-align: center;
}

#info-hint {
  font-size: 0.9rem;
  color: #a8dadc;
  text-align: center;
  line-height: 1.4;
  font-style: italic;
}

/* ── Waypoint pop animation ───────────────────── */
@keyframes waypoint-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.waypoint-popping {
  animation: waypoint-pop 0.3s ease forwards;
}

/* ── All-done screen ──────────────────────────── */
#all-done-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 100;
}

#all-done-overlay h1 {
  font-size: 3.5rem;
  font-weight: 900;
  color: #e9c46a;
  text-shadow: 0 0 40px #e9c46a;
}

#all-done-overlay p {
  font-size: 1.5rem;
  color: #fffffe;
}

/* ── Case tabs ────────────────────────────────── */
#case-tabs {
  display: flex;
  gap: 6px;
  background: #111827;
  border-radius: 12px;
  padding: 4px;
  flex-shrink: 0;
}

.case-tab {
  flex: 1;
  background: transparent;
  color: #7a8a9a;
  border: none;
  border-radius: 9px;
  padding: 9px 0;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}
.case-tab:hover:not(.active) {
  background: #1e2535;
  color: #a8dadc;
}
.case-tab.active {
  background: #1275c8;
  color: #fffffe;
  box-shadow: 0 2px 12px rgba(18, 117, 200, 0.45);
}

/* ── Header case badge ────────────────────────── */
.case-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 3px 9px;
  border-radius: 8px;
  margin-left: 8px;
  vertical-align: middle;
  transition: background 0.2s, color 0.2s;
}
.upper-badge { background: #1275c8; color: #fffffe; }
.lower-badge { background: #2a9d8f; color: #fffffe; }

/* ── Scrollbar styling ────────────────────────── */
#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: #264653; border-radius: 3px; }

/* ── Shape Analysis card ─────────────────────── */
.shape-analysis {
  background: #1e2d3d;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid #2a9d8f33;
  animation: slide-in 0.4s ease forwards;
}

@keyframes slide-in {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

.shape-label {
  font-size: 0.75rem;
  color: #2a9d8f;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 900;
}

.shape-feedback {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fffffe;
  line-height: 1.4;
}

.shape-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shape-detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: #a8dadc;
}

.shape-icon {
  font-size: 1.1rem;
}

.shape-score-bar-wrap {
  position: relative;
  height: 18px;
  background: rgba(0,0,0,0.4);
  border-radius: 9px;
  overflow: hidden;
}

.shape-score-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2a9d8f, #52b788);
  border-radius: 9px;
  transition: width 0.6s ease;
}

#shape-score-pct {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 700;
  color: #fffffe;
}

/* ── How to Play bento panel ──────────────────── */
#how-to-play {
  width: 230px;
  flex-shrink: 0;
  background: #12112a;
  border-left: 1.5px solid rgba(38, 70, 83, 0.6);
  border-right: 1.5px solid rgba(38, 70, 83, 0.6);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #264653 transparent;
}

#how-to-play::-webkit-scrollbar { width: 5px; }
#how-to-play::-webkit-scrollbar-track { background: transparent; }
#how-to-play::-webkit-scrollbar-thumb { background: #264653; border-radius: 3px; }

.htp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.htp-icon { font-size: 1.25rem; line-height: 1; }
.htp-title {
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #e9c46a;
}

/* Step cards */
.htp-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  padding: 10px 12px;
  transition: background 0.2s;
}
.htp-card:hover { background: rgba(255,255,255,0.07); }

/* Highlighted card — camera permission step */
.htp-card--highlight {
  background: rgba(18,117,200,0.15);
  border-color: rgba(18,117,200,0.4);
  animation: htp-glow 2.8s ease-in-out infinite;
}
.htp-card--highlight:hover { background: rgba(18,117,200,0.22); }

@keyframes htp-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(18,117,200,0); }
  50%       { box-shadow: 0 0 14px 3px rgba(18,117,200,0.28); }
}

.htp-step-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #1275c8;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.htp-card--highlight .htp-step-num { background: #e9c46a; color: #0f0e17; }

.htp-step-body { display: flex; flex-direction: column; gap: 3px; }
.htp-step-body strong {
  font-size: 0.82rem;
  font-weight: 900;
  color: #fffffe;
  line-height: 1.3;
}
.htp-step-body span {
  font-size: 0.75rem;
  color: #8fa8b8;
  line-height: 1.45;
}

.htp-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 2px 0;
  border-radius: 1px;
}

.htp-tips-label {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #2a9d8f;
  margin-bottom: -2px;
}

.htp-tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
}
.htp-tips-list li {
  font-size: 0.76rem;
  color: #8fa8b8;
  line-height: 1.5;
  background: rgba(42,157,143,0.07);
  border: 1px solid rgba(42,157,143,0.15);
  border-radius: 9px;
  padding: 8px 10px;
  transition: background 0.2s;
}
.htp-tips-list li:hover { background: rgba(42,157,143,0.14); color: #c5dce0; }
.htp-tips-list li strong { color: #a8dadc; font-weight: 900; }

/* Hide the panel on narrow screens */
@media (max-width: 900px) {
  #how-to-play { display: none; }
}
