:root {
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #d1fae5;
  --secondary: #0284c7;
  --accent: #f59e0b;
  --bg-dark: #0f172a;
  --card-bg: #1e293b;
  --card-border: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --success: #10b981;
  --danger: #ef4444;
  --font-heading: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Lexend', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background-color: #1e293b;
  border-bottom: 2px solid var(--card-border);
  padding: 0.75rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-icon {
  font-size: 2rem;
  background: rgba(5, 150, 105, 0.2);
  border: 2px solid var(--primary);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.brand h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

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

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.tab-pills {
  display: flex;
  background: #0f172a;
  padding: 4px;
  border-radius: 999px;
  gap: 4px;
  border: 1px solid var(--card-border);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.4);
}

.tab-btn:hover:not(.active) {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.btn-header {
  background: #334155;
  color: #fff;
  border: none;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: 0.2s;
}

.btn-header:hover {
  background: #475569;
}

.game-container {
  flex: 1;
  padding: 1.25rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-pane.active {
  display: block;
}

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

.mode-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  background: var(--card-bg);
  padding: 1rem 1.25rem;
  border-radius: 14px;
  border: 1px solid var(--card-border);
}

.section-intro h2 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  color: #fff;
}

.section-intro p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 2px;
}

.styled-select {
  background: #0f172a;
  border: 1px solid var(--card-border);
  color: #fff;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
}

.action-btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s;
}

.action-btn.primary {
  background: var(--primary);
  color: white;
}

.action-btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.action-btn.secondary {
  background: #334155;
  color: white;
}

.action-btn.secondary:hover:not(:disabled) {
  background: #475569;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ================= TAB 1: TANGRAM ================= */
.tangram-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.tangram-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
}

.tangram-board-container {
  background: #090d16;
  border: 2px solid var(--card-border);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

#tangram-canvas {
  background: #0f172a;
  border-radius: 10px;
  border: 1px solid #1e293b;
  cursor: grab;
  max-width: 100%;
  height: auto;
}

#tangram-canvas:active {
  cursor: grabbing;
}

.board-hud {
  margin-top: 0.75rem;
  width: 100%;
  display: flex;
  justify-content: center;
}

.hud-pill {
  background: rgba(5, 150, 105, 0.15);
  border: 1px solid var(--primary);
  color: #6ee7b7;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
}

.tangram-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.side-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 1.1rem;
}

.side-card h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.75rem;
}

.tan-preview-box {
  background: #0f172a;
  border: 1px dashed var(--card-border);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.tan-preview-box.has-tan {
  border-style: solid;
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.tan-action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.rotate-btn {
  justify-content: center;
  background: #1e3a8a;
  color: white;
}

.rotate-btn:hover:not(:disabled) {
  background: #2563eb;
}

.micro-tip {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tan-composition-list {
  list-style: none;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* ================= TAB 2: TESSELLATION LAB ================= */
.tess-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.polygon-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.picker-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.shape-btn {
  background: #0f172a;
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.2s;
}

.shape-btn.active {
  background: var(--secondary);
  border-color: #38bdf8;
  color: white;
}

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

.tess-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
}

.tess-canvas-wrap {
  background: #090d16;
  border: 2px solid var(--card-border);
  border-radius: 14px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

#tess-canvas {
  background: #0d131f;
  border-radius: 8px;
  border: 1px solid #1e293b;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}

.tess-overlay-tip {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tess-math-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.math-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 1.1rem;
}

.math-card h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  color: #fff;
}

.math-badge {
  display: inline-block;
  margin: 0.4rem 0 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid var(--success);
}

.math-badge.fails {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border-color: var(--danger);
}

.angle-breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.angle-stat {
  background: #0f172a;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.stat-val {
  font-size: 1rem;
  font-weight: 700;
  color: #38bdf8;
}

.math-explanation {
  font-size: 0.8rem;
  color: #cbd5e1;
  line-height: 1.45;
}

.realworld-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 1.1rem;
}

.realworld-card h4 {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: #fbbf24;
  margin-bottom: 0.4rem;
}

#tess-realworld-desc {
  font-size: 0.8rem;
  color: #cbd5e1;
  line-height: 1.4;
  margin-bottom: 0.85rem;
}

.tess-color-palette {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s;
}

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

/* ================= TAB 3: SYMMETRY MIRROR ================= */
.symm-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.symm-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.symm-mode-btn {
  background: #0f172a;
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.2s;
}

.symm-mode-btn.active {
  background: var(--primary);
  border-color: #34d399;
  color: #fff;
}

.brush-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.brush-controls input[type="color"] {
  width: 32px;
  height: 28px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

.brush-controls input[type="range"] {
  width: 70px;
  cursor: pointer;
}

.symm-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
}

.symm-canvas-wrap {
  background: #090d16;
  border: 2px solid var(--card-border);
  border-radius: 14px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

#symm-canvas {
  background: #0b1120;
  border-radius: 8px;
  border: 1px solid #1e293b;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}

.canvas-axis-labels {
  margin-top: 0.5rem;
}

.axis-pill {
  font-size: 0.75rem;
  background: rgba(2, 132, 199, 0.2);
  border: 1px solid var(--secondary);
  color: #38bdf8;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
}

.symm-guide-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.guide-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 1.1rem;
}

.guide-box h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.75rem;
}

.shape-symmetry-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.symm-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f172a;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  font-size: 0.8rem;
}

.shape-name {
  color: #cbd5e1;
}

.symm-count {
  font-weight: 700;
  color: #10b981;
}

.celtic-note {
  background: rgba(5, 150, 105, 0.1);
  border-left: 3px solid var(--primary);
  padding: 0.65rem 0.75rem;
  border-radius: 0 8px 8px 0;
}

.celtic-note h4 {
  font-size: 0.85rem;
  color: #6ee7b7;
  margin-bottom: 0.25rem;
}

.celtic-note p {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.35;
}

/* ================= TAB 4: QUIZ ================= */
.quiz-container {
  max-width: 760px;
  margin: 0 auto;
}

.quiz-card {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 0.75rem;
}

.quiz-badge {
  background: rgba(5, 150, 105, 0.2);
  color: #34d399;
  border: 1px solid var(--primary);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.quiz-count {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.quiz-body h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  line-height: 1.4;
  margin-bottom: 1.25rem;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.quiz-opt-btn {
  background: #0f172a;
  border: 1px solid var(--card-border);
  color: #f8fafc;
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quiz-opt-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #1e293b;
}

.quiz-opt-btn.correct {
  background: rgba(16, 185, 129, 0.25);
  border-color: var(--success);
  color: #a7f3d0;
}

.quiz-opt-btn.wrong {
  background: rgba(239, 68, 68, 0.25);
  border-color: var(--danger);
  color: #fca5a5;
}

.quiz-opt-btn:disabled {
  cursor: default;
}

.quiz-feedback {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.quiz-feedback.correct {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--success);
  color: #6ee7b7;
}

.quiz-feedback.wrong {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
}

.quiz-feedback.hidden {
  display: none;
}

.quiz-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score-display {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.score-display strong {
  color: #fff;
  font-size: 1.1rem;
}

/* Responsive */
@media (max-width: 992px) {
  .tangram-layout,
  .tess-layout,
  .symm-layout {
    grid-template-columns: 1fr;
  }
  .options-grid {
    grid-template-columns: 1fr;
  }
}
