@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Sarabun:ital,wght@0,400;0,500;0,600;0,700;1,400;1,600&display=swap');

:root {
  /* GradeUp: Homework Scanner Official Light iOS/iPadOS Palette */
  --bg-app: #f2f6fc;
  --bg-surface: #ffffff;
  --bg-panel: #ffffff;
  --bg-card: #f8fafc;
  --bg-hover: #eef4ff;
  --border-subtle: #e2e8f0;
  --border-focus: #2563eb;
  --text-main: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;

  /* GradeUp Signature Royal Blue (rgb(33, 73, 193)) */
  --primary: #2149c1;
  --primary-light: #2563eb;
  --primary-hover: #1a3a9c;
  --primary-soft: #eff6ff;
  --primary-glow: rgba(33, 73, 193, 0.22);

  --accent-cyan: #0ea5e9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 4px 20px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.03);
  --shadow-float: 0 12px 32px rgba(33, 73, 193, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
}

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

body {
  font-family: 'Sarabun', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==================== GRADEUP TOPBAR ==================== */
.topbar {
  height: 68px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.03);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(145deg, #2149c1 0%, #2563eb 55%, #38bdf8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 22px;
  box-shadow: 0 6px 16px rgba(33, 73, 193, 0.32);
  position: relative;
  overflow: hidden;
}

.brand-title {
  font-size: 17.5px;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eff6ff;
  color: #2149c1;
  border: 1px solid #bfdbfe;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* iOS Segmented Pill Mode Tabs */
.mode-tabs {
  display: flex;
  align-items: center;
  background: #edf2f9;
  padding: 4px;
  border-radius: 13px;
  border: 1px solid #e2e8f0;
  gap: 4px;
}

.mode-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.mode-tab:hover {
  color: var(--primary);
  background: rgba(255, 255, 255, 0.6);
}

.mode-tab.active {
  background: linear-gradient(135deg, #2149c1 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(33, 73, 193, 0.25);
}

.tab-count-badge {
  background: rgba(33, 73, 193, 0.12);
  color: var(--primary);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  font-weight: 800;
}

.mode-tab.active .tab-count-badge {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

/* Topbar Right Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ==================== BUTTONS & INPUTS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--text-main);
  transition: all 0.16s ease;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.btn:hover {
  background: var(--bg-hover);
  border-color: #cbd5e1;
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, #2149c1 0%, #2563eb 100%);
  border-color: #1d4ed8;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(33, 73, 193, 0.28);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1a3a9c 0%, #1d4ed8 100%);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(33, 73, 193, 0.35);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: #059669;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.22);
}

.btn-success:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
}

.btn-danger-outline {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}

.btn-danger-outline:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

.select-input {
  background: #f8fafc;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(33, 73, 193, 0.12);
}

/* ==================== WORKSPACE VIEWS ==================== */
.workspace-view {
  display: none;
  flex: 1;
  min-height: calc(100vh - 68px);
}

.workspace-view.active {
  display: flex;
}

/* ==================== STUDIO LAYOUT (SCANNER & ERASER) ==================== */
.studio-layout {
  display: grid;
  grid-template-columns: 335px 1fr 345px;
  width: 100%;
  height: calc(100vh - 68px);
  overflow: hidden;
}

.studio-sidebar {
  background: #f8fafc;
  border-right: 1px solid var(--border-subtle);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.studio-sidebar-right {
  background: #f8fafc;
  border-left: 1px solid var(--border-subtle);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-title {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 7px;
}

.panel-badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 99px;
  background: #eff6ff;
  color: #2149c1;
  border: 1px solid #dbeafe;
  font-weight: 700;
}

/* GradeUp Preset Cards */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-btn {
  padding: 10px 11px;
  border-radius: 11px;
  border: 1.5px solid #e2e8f0;
  background: #f8fafc;
  color: #1e293b;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.16s ease;
}

.preset-btn span.preset-sub {
  font-size: 11px;
  font-weight: 500;
  color: #64748b;
}

.preset-btn:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.preset-btn.active {
  border-color: var(--primary);
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  color: var(--primary);
  box-shadow: 0 3px 10px rgba(33, 73, 193, 0.12);
}

.preset-btn.active span.preset-sub {
  color: #1e40af;
}

/* Toggle Switches for Ink Channels */
.channel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 11px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  transition: background 0.15s ease;
}

.channel-row:hover {
  background: #f1f5f9;
}

.channel-info {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
}

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

.ink-dot.blue { background: #2563eb; box-shadow: 0 0 6px rgba(37, 99, 235, 0.45); }
.ink-dot.red { background: #ef4444; box-shadow: 0 0 6px rgba(239, 68, 68, 0.45); }
.ink-dot.yellow { background: #eab308; box-shadow: 0 0 6px rgba(234, 179, 8, 0.45); }
.ink-dot.pencil { background: #64748b; }
.ink-dot.shadow { background: #cbd5e1; border: 1px solid #94a3b8; }

/* iOS Style Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 99px;
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider-toggle {
  background-color: var(--primary);
}

.switch input:checked + .slider-toggle:before {
  transform: translateX(18px);
}

/* Range Sliders */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
}

.control-value {
  color: var(--primary);
  font-weight: 800;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2.5px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(33, 73, 193, 0.35);
}

/* ==================== CENTER CANVAS STAGE ==================== */
.canvas-stage-wrapper {
  position: relative;
  background-color: #eaf0f8;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  user-select: none;
}

/* Floating White-Glass iOS Tool Strip inside Stage */
.stage-toolbar {
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid #dbe3ef;
  padding: 6px 10px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 30;
  box-shadow: var(--shadow-float);
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: #334155;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.tool-btn.active {
  background: linear-gradient(135deg, #2149c1 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(33, 73, 193, 0.25);
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  background: #e2e8f0;
  margin: 0 4px;
}

/* Viewport container holding the Dual Canvas */
.canvas-viewport {
  flex: 1;
  width: 100%;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 28px;
}

/* GradeUp Onboarding / Empty State Hub */
.gradeup-empty-hub {
  max-width: 680px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: auto;
}

.gradeup-drop-card {
  background: #ffffff;
  border: 2px dashed #93c5fd;
  border-radius: 24px;
  padding: 36px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 16px 40px rgba(33, 73, 193, 0.08);
  transition: all 0.2s ease;
}

.gradeup-drop-card:hover {
  border-color: var(--primary);
  box-shadow: 0 20px 48px rgba(33, 73, 193, 0.13);
}

.gradeup-hero-icon {
  width: 78px;
  height: 78px;
  border-radius: 22px;
  background: linear-gradient(145deg, #2149c1 0%, #2563eb 60%, #38bdf8 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  box-shadow: 0 10px 24px rgba(33, 73, 193, 0.3);
}

.gradeup-feature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.gradeup-feature-item {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  box-shadow: var(--shadow-card);
}

.gradeup-feature-badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.worksheet-comparison-frame {
  position: relative;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  background: #ffffff;
  transform-origin: top center;
  transition: transform 0.12s ease;
  overflow: hidden;
}

.worksheet-comparison-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Before/After Split Clipping Layer */
.before-overlay-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Split Slider Divider Line & Handle (GradeUp Laser Scan Bar) */
.split-slider-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #2149c1;
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.85);
  cursor: ew-resize;
  z-index: 20;
  touch-action: none;
}

.split-slider-line::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -22px;
  width: 47px;
  background: transparent;
}

.split-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2149c1 0%, #2563eb 100%);
  border: 3px solid #ffffff;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 6px 20px rgba(33, 73, 193, 0.45);
  cursor: ew-resize;
  touch-action: none;
}

.split-badge-left,
.split-badge-right {
  position: absolute;
  top: 14px;
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  z-index: 18;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
}

.split-badge-left {
  left: 14px;
  background: rgba(239, 68, 68, 0.92);
  color: #ffffff;
}

.split-badge-right {
  right: 14px;
  background: rgba(33, 73, 193, 0.94);
  color: #ffffff;
}

/* Snip Selection Rectangle for Mistake Notebook */
.snip-selection-box {
  position: absolute;
  border: 2.5px dashed #2149c1;
  background: rgba(37, 99, 235, 0.12);
  pointer-events: none;
  display: none;
  z-index: 25;
}

/* Stage Bottom Status & Zoom Bar */
.stage-statusbar {
  width: 100%;
  height: 44px;
  background: #ffffff;
  border-top: 1px solid var(--border-subtle);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-muted);
  z-index: 25;
}

.telemetry-pills {
  display: flex;
  align-items: center;
  gap: 14px;
}

.telemetry-pill strong {
  color: var(--primary);
  font-weight: 700;
}

/* Stats Grid in Right Sidebar */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Question Quick-Snip List in Right Sidebar */
.detected-questions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detected-q-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detected-q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
  color: #0f172a;
}

.status-tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 99px;
  font-weight: 700;
}

.status-tag.correct {
  background: #dcfce7;
  color: #15803d;
}

.status-tag.wrong {
  background: #fee2e2;
  color: #b91c1c;
}

/* ==================== VIEW 2: AI SOLVER & AUTO-GRADER ==================== */
.solver-container {
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 24px;
  align-items: start;
}

.solver-preview-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: sticky;
  top: 86px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-card);
}

.solver-preview-img-wrap {
  background: #f8fafc;
  border-radius: 10px;
  overflow: hidden;
  max-height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-subtle);
}

.solver-preview-img-wrap img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

.solver-results-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.score-hero-banner {
  background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 100%);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.score-circle {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: #ffffff;
  border: 3.5px solid var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(33, 73, 193, 0.15);
}

.score-circle .big-score {
  font-size: 23px;
  font-weight: 800;
  color: var(--primary);
}

.score-circle .score-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.question-solution-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.question-solution-card.wrong-card {
  border-left: 4px solid var(--danger);
}

.question-solution-card.correct-card {
  border-left: 4px solid var(--success);
}

.solution-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.65;
  color: #1e293b;
}

/* ==================== VIEW 3: MISTAKE NOTEBOOK & EXAM BUILDER ==================== */
.notebook-container {
  max-width: 1340px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.notebook-header-bar {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: var(--shadow-card);
}

.mistake-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 18px;
}

.mistake-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-card);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.mistake-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-float);
}

.mistake-crop-preview {
  background: #f8fafc;
  padding: 14px;
  border-bottom: 1px solid var(--border-subtle);
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mistake-crop-preview img {
  max-width: 100%;
  max-height: 210px;
  object-fit: contain;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.mistake-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

.text-input {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: all 0.15s ease;
}

.text-input:focus {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33, 73, 193, 0.12);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #0f172a;
  border-left: 4px solid #38bdf8;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.2s ease-out;
}

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

/* ==================== PRINT STYLESHEET ==================== */
#printableArea {
  display: none;
}

@media print {
  body * {
    visibility: hidden;
  }
  .topbar,
  .workspace-view,
  .modal-backdrop,
  .toast-container {
    display: none !important;
  }
  #printableArea,
  #printableArea * {
    visibility: visible;
  }
  #printableArea {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #ffffff;
    color: #000000;
  }
}

/* ==================== RESPONSIVE: IPAD & IPHONE NATIVE LAYOUT ==================== */
@media (max-width: 1180px) {
  .studio-layout {
    grid-template-columns: 290px 1fr 290px;
  }
  .solver-container {
    grid-template-columns: 1fr;
  }
  .solver-preview-card {
    position: static;
  }
}

@media (max-width: 860px) {
  body {
    padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  }

  /* Compact iPhone Header */
  .topbar {
    height: auto;
    min-height: 56px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .brand {
    gap: 8px;
    flex: 1;
    min-width: 0;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .brand-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-badge,
  .brand-subtitle {
    display: none !important;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .btn {
    padding: 7px 10px;
    font-size: 12px;
    border-radius: 9px;
  }

  /* Native iOS Fixed Bottom Tab Bar */
  .mode-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 180;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 0;
    border: none;
    border-top: 1px solid #cbd5e1;
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  }

  .mode-tab {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 10px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tab-count-badge {
    font-size: 10px;
    padding: 0 5px;
  }

  /* Studio Layout: Single Column Stack on iPhone */
  .workspace-view {
    min-height: auto;
  }

  .studio-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
    width: 100%;
  }

  /* 1. Canvas Stage on top */
  .canvas-stage-wrapper {
    order: 1;
    width: 100%;
    min-height: auto;
    overflow: visible;
  }

  /* Horizontal touch-scrollable toolbar on iPhone */
  .stage-toolbar {
    width: calc(100% - 16px);
    margin: 8px 8px 4px 8px;
    padding: 6px 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    border-radius: 12px;
    gap: 6px;
  }

  .stage-toolbar::-webkit-scrollbar {
    display: none;
  }

  .tool-btn {
    flex-shrink: 0;
    padding: 7px 11px;
    font-size: 12.5px;
  }

  .canvas-viewport {
    padding: 10px 12px;
    overflow: visible;
    min-height: auto;
  }

  .gradeup-empty-hub {
    gap: 12px;
  }

  .gradeup-drop-card {
    padding: 22px 16px;
    border-radius: 18px;
    gap: 12px;
  }

  .gradeup-hero-icon {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    font-size: 28px;
  }

  .gradeup-drop-card h2 {
    font-size: 18px !important;
  }

  .gradeup-drop-card p {
    font-size: 13px !important;
  }

  .gradeup-feature-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .gradeup-feature-item {
    padding: 11px 13px;
    border-radius: 13px;
  }

  .stage-statusbar {
    height: auto;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11.5px;
  }

  .telemetry-pills {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* 2. Left Sidebar (1-Click AI Modes & Sliders) */
  .studio-sidebar {
    order: 2;
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--border-subtle);
    padding: 12px;
    gap: 12px;
    overflow: visible;
  }

  /* 3. Right Sidebar (Export PDF/Word/PNG/Print — 100% visible on iPhone!) */
  .studio-sidebar-right {
    order: 3;
    display: flex !important;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    padding: 12px;
    gap: 12px;
    overflow: visible;
  }

  .panel-card {
    padding: 13px;
    border-radius: 14px;
  }

  input[type="range"] {
    height: 8px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  /* Other Views on iPhone */
  .solver-container,
  .notebook-container {
    padding: 12px;
    gap: 14px;
  }

  .notebook-header-bar {
    padding: 14px 16px;
  }

  .notebook-header-bar h2 {
    font-size: 18px !important;
  }

  .mistake-cards-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal-dialog {
    padding: 18px;
    border-radius: 16px;
  }

  .toast-container {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
  }
}

