/* ===== Pastel-soft educational palette ===== */
:root {
  --bg: #F7F6FB;
  --bg-grad: linear-gradient(135deg, #F7F6FB 0%, #EFEEFB 50%, #F4F0F9 100%);
  --surface: #FFFFFF;
  --surface-2: #FBFAFE;
  --ink: #1F1B3A;
  --ink-soft: #4B4675;
  --ink-mute: #8783A8;
  --line: #E7E3F2;
  --line-soft: #F1EEF7;

  /* Indigo primary */
  --primary: #6366F1;
  --primary-soft: #A5B4FC;
  --primary-tint: #EEF0FF;
  --primary-deep: #4338CA;

  /* Shape face tints (pastel) */
  --tint-indigo: #C7CCFF;
  --tint-indigo-deep: #818CF8;
  --tint-mint: #B7E8D2;
  --tint-mint-deep: #4ADE80;
  --tint-rose: #FBC7D9;
  --tint-rose-deep: #FB7185;
  --tint-amber: #FCD9A8;
  --tint-amber-deep: #F59E0B;

  /* Status */
  --ok: #10B981;
  --ok-tint: #DCFCE7;
  --warn: #F59E0B;
  --warn-tint: #FEF3C7;
  --err: #F43F5E;
  --err-tint: #FFE4E6;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  --sh-1: 0 1px 2px rgba(31, 27, 58, 0.04), 0 1px 3px rgba(31, 27, 58, 0.04);
  --sh-2: 0 4px 12px rgba(31, 27, 58, 0.06), 0 2px 4px rgba(31, 27, 58, 0.04);
  --sh-3: 0 12px 30px rgba(99, 102, 241, 0.12), 0 4px 10px rgba(31, 27, 58, 0.06);
  --sh-glow: 0 0 0 4px rgba(99, 102, 241, 0.16);

  --t-fast: 140ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-med: 280ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--ink);
  background: var(--bg-grad);
  min-height: 100vh;
  font-feature-settings: 'cv11', 'ss01';
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ===== Layout ===== */
.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 32px 60px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #818CF8, #6366F1);
  display: grid;
  place-items: center;
  box-shadow: var(--sh-2);
  position: relative;
}
.brand-mark svg { width: 26px; height: 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text .t1 { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-text .t2 { font-weight: 500; font-size: 12px; color: var(--ink-mute); margin-top: 2px; }

.topbar-stats {
  display: flex; gap: 10px; align-items: center;
}
.stat-pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--sh-1);
}
.stat-pill .lbl { color: var(--ink-mute); font-weight: 500; }
.stat-pill .val { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-pill.streak .val { color: var(--warn); }
.stat-pill .ico { width: 14px; height: 14px; opacity: 0.7; }

.topbar-actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  transition: all var(--t-fast);
  box-shadow: var(--sh-1);
}
.btn:hover { background: var(--primary-tint); border-color: var(--primary-soft); }
.btn.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: var(--sh-3);
}
.btn.btn-primary:hover { background: var(--primary-deep); }
.btn.btn-ghost { box-shadow: none; background: transparent; border-color: transparent; }
.btn.btn-ghost:hover { background: var(--primary-tint); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .ico { width: 16px; height: 16px; }

/* ===== Shape picker ===== */
.shape-picker {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  box-shadow: var(--sh-2);
  border: 1px solid var(--line);
  margin-bottom: 18px;
}
.shape-card {
  position: relative;
  border-radius: var(--r-md);
  padding: 14px 14px 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  text-align: left;
  transition: all var(--t-fast);
  display: flex;
  align-items: center;
  gap: 12px;
}
.shape-card:hover {
  border-color: var(--primary-soft);
  transform: translateY(-1px);
  box-shadow: var(--sh-2);
}
.shape-card.selected {
  border-color: var(--primary);
  background: var(--primary-tint);
  box-shadow: var(--sh-glow);
}
.shape-card .ico-3d {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--surface), #F0EEF7);
  display: grid; place-items: center;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.shape-card.selected .ico-3d {
  background: linear-gradient(135deg, white, var(--primary-tint));
  border-color: var(--primary-soft);
}
.shape-card .ico-3d svg { width: 42px; height: 42px; }
.shape-card .info { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.shape-card .nm { font-weight: 700; font-size: 14px; }
.shape-card .sub { font-size: 11.5px; color: var(--ink-mute); margin-top: 2px; }

/* ===== Main grid ===== */
.main-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  box-shadow: var(--sh-2);
  padding: 20px;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-head .step-dot {
  width: 22px; height: 22px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
}
.panel-head .hint {
  font-size: 12px;
  color: var(--ink-mute);
}

/* ===== Grid editor ===== */
.editor-wrap {
  position: relative;
  flex: 1;
  background:
    linear-gradient(180deg, #FBFAFE, #F4F2FB);
  border-radius: var(--r-md);
  border: 1px dashed var(--line);
  padding: 22px;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 420px;
}
.editor-grid {
  position: relative;
  /* dotted background */
  background-image: radial-gradient(rgba(99,102,241,0.18) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: 0 0;
  border-radius: 12px;
}
.slot {
  position: absolute;
  cursor: pointer;
  transition: filter var(--t-fast), transform var(--t-fast);
}
.slot:hover { filter: brightness(1.04); }
.slot.locked { cursor: default; }
.slot.hint { animation: hint-pulse 1.4s ease-in-out infinite; }
@keyframes hint-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12) drop-shadow(0 0 8px var(--primary)); }
}
.slot-fill {
  fill: rgba(99, 102, 241, 0.06);
  stroke: rgba(99, 102, 241, 0.34);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  transition: fill var(--t-fast), stroke var(--t-fast);
}
.slot:hover .slot-fill {
  fill: rgba(99, 102, 241, 0.14);
  stroke: rgba(99, 102, 241, 0.7);
}
.slot.active .slot-fill {
  stroke-dasharray: none;
  stroke-width: 2;
  fill: var(--tint-indigo);
  stroke: var(--tint-indigo-deep);
}
.slot.active.tone-mint .slot-fill { fill: var(--tint-mint); stroke: var(--tint-mint-deep); }
.slot.active.tone-rose .slot-fill { fill: var(--tint-rose); stroke: var(--tint-rose-deep); }
.slot.active.tone-amber .slot-fill { fill: var(--tint-amber); stroke: var(--tint-amber-deep); }
.slot.base .slot-fill { fill: var(--tint-indigo-deep); stroke: var(--primary-deep); }
.slot.base.tone-mint .slot-fill { fill: var(--tint-mint-deep); stroke: #047857; }
.slot.base.tone-rose .slot-fill { fill: var(--tint-rose-deep); stroke: #BE123C; }
.slot.base.tone-amber .slot-fill { fill: var(--tint-amber-deep); stroke: #92400E; }
.slot-label {
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  fill: var(--ink);
}
.slot.base .slot-label { fill: white; }
.slot.faded .slot-fill { opacity: 0.35; }

.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px;
  gap: 10px;
}
.editor-toolbar .grp { display: flex; gap: 8px; }

.counter {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-size: 13px;
  background: var(--primary-tint);
  color: var(--primary-deep);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
}
.counter .val { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.counter.full { background: var(--ok-tint); color: #065F46; }

/* ===== Feedback ===== */
.feedback {
  padding: 14px 16px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  line-height: 1.45;
  border: 1px solid transparent;
  animation: fb-pop 280ms ease-out;
}
@keyframes fb-pop {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.feedback.ok { background: var(--ok-tint); color: #065F46; border-color: #6EE7B7; }
.feedback.err { background: var(--err-tint); color: #9F1239; border-color: #FCA5A5; }
.feedback.info { background: var(--primary-tint); color: var(--primary-deep); border-color: var(--primary-soft); }
.feedback .ico { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.feedback strong { font-weight: 700; }

/* ===== 3D Preview ===== */
.preview-wrap {
  flex: 1;
  background:
    radial-gradient(120% 100% at 50% 20%, #FFFFFF 0%, #F2F0FA 70%, #EDEAF6 100%);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  min-height: 460px;
  perspective: 1400px;
  perspective-origin: 50% 35%;
}
.preview-scene {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}
.scene-rot {
  transform-style: preserve-3d;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0; height: 0;
}
.face-node {
  position: absolute;
  transform-style: preserve-3d;
  transform-origin: var(--ox, 0) var(--oy, 0);
  pointer-events: none;
}
.face-shape {
  position: absolute;
  width: 100%; height: 100%;
  backface-visibility: visible;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.92);
  user-select: none;
  /* A crisp seam that traces each face outline — INCLUDING clip-path
     triangles, which a normal border can't follow. Every face thus reads as a
     separate panel, so a triangle cap never looks merged with / overlapping the
     rectangle it folds against. */
  filter:
    drop-shadow(0.5px 0 0 rgba(255,255,255,0.85))
    drop-shadow(-0.5px 0 0 rgba(255,255,255,0.85))
    drop-shadow(0 0.5px 0 rgba(255,255,255,0.85))
    drop-shadow(0 -0.5px 0 rgba(255,255,255,0.85));
}
.face-shape.square {
  background: linear-gradient(135deg, var(--tint-indigo-deep), #6366F1);
}
.face-shape.triangle-up {
  background: transparent;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.face-shape.triangle-down {
  background: transparent;
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}
.face-shape.tone-mint   { background: linear-gradient(135deg, var(--tint-mint-deep), #34D399); }
.face-shape.tone-rose   { background: linear-gradient(135deg, var(--tint-rose-deep), #F87171); }
.face-shape.tone-amber  { background: linear-gradient(135deg, var(--tint-amber-deep), #FBBF24); }
/* Triangle (cap / lateral) faces get a clearly BRIGHTER shade than the
   rectangle side faces, so the two never blend into one green blob. */
.face-shape.triangle.tone-mint   { background: linear-gradient(135deg, #6EE7B7, #2DD4A7); }
.face-shape.triangle.tone-rose   { background: linear-gradient(135deg, #FDA4AF, #FB7185); }
.face-shape.triangle.tone-amber  { background: linear-gradient(135deg, #FCD34D, #FBBF24); }
.face-shape.is-base {
  background: linear-gradient(135deg, var(--primary-deep), #312E81);
}
.face-shape.is-base.tone-mint  { background: linear-gradient(135deg, #047857, #064E3B); }
.face-shape.is-base.tone-rose  { background: linear-gradient(135deg, #BE123C, #881337); }
.face-shape.is-base.tone-amber { background: linear-gradient(135deg, #B45309, #78350F); }

.preview-empty {
  text-align: center;
  color: var(--ink-mute);
  font-size: 14px;
  position: relative;
  z-index: 2;
  padding: 20px;
  max-width: 280px;
}
.preview-empty svg { width: 64px; height: 64px; margin-bottom: 12px; opacity: 0.6; }

/* Scene rotation controls (overlay on preview-wrap) */
.scene-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
  pointer-events: auto;
}
.scene-controls .sc-row {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.86);
  border-radius: 12px;
  box-shadow: var(--sh-2);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.scene-controls .sc-row button {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  display: grid; place-items: center;
  transition: all var(--t-fast);
}
.scene-controls .sc-row button:hover {
  background: var(--primary-tint);
  color: var(--primary-deep);
}
.scene-controls .sc-row button svg { width: 16px; height: 16px; }
.scene-controls .sc-reset {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.86);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  box-shadow: var(--sh-1);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  align-self: flex-end;
  transition: all var(--t-fast);
}
.scene-controls .sc-reset:hover {
  background: var(--primary-tint);
  color: var(--primary-deep);
  border-color: var(--primary-soft);
}
.scene-controls .sc-reset svg { width: 12px; height: 12px; }

/* Preview tip — small notice telling user they can fold partial nets */
.preview-tip {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(254, 243, 199, 0.92);
  border: 1px solid #FCD34D;
  color: #92400E;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.4;
  z-index: 4;
  backdrop-filter: blur(8px);
  max-width: 360px;
}
.preview-tip svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; }

/* Slider */
.fold-control {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.fold-label {
  display: flex; flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.fold-label .pct { font-size: 14px; color: var(--primary-deep); font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 1px; }
.fold-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary) var(--pos, 0%), var(--line) var(--pos, 0%), var(--line) 100%);
  border-radius: 999px;
  outline: none;
}
.fold-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: white;
  border: 2.5px solid var(--primary);
  box-shadow: var(--sh-2);
  cursor: pointer;
}
.fold-slider::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: white;
  border: 2.5px solid var(--primary);
  box-shadow: var(--sh-2);
  cursor: pointer;
}
.fold-slider:disabled::-webkit-slider-thumb { background: var(--line); border-color: var(--ink-mute); }
.fold-quick {
  display: flex; gap: 6px;
}
.fold-quick button {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: all var(--t-fast);
}
.fold-quick button:hover { background: var(--primary-tint); color: var(--primary-deep); border-color: var(--primary-soft); }
.fold-quick button.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Narration */
.narration {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.narration-step {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 800;
}
.narration-body strong { color: var(--ink); }

/* ===== Tutorial modal ===== */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(31, 27, 58, 0.45);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fade-in 200ms ease-out both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  max-width: 540px;
  width: 100%;
  padding: 32px;
  box-shadow: 0 30px 60px rgba(31, 27, 58, 0.25);
  animation: modal-in 320ms cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.modal p { margin: 0 0 18px; color: var(--ink-soft); line-height: 1.55; font-size: 14px; }
.modal .step-list {
  display: flex; flex-direction: column; gap: 12px;
  margin: 16px 0 24px;
}
.modal .step {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
}
.modal .step-num {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: grid; place-items: center;
  font-size: 13px;
  font-weight: 800;
}
.modal .step-body { font-size: 13.5px; line-height: 1.5; }
.modal .step-body strong { color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-mark {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, #818CF8, #6366F1);
  display: grid; place-items: center;
  margin-bottom: 16px;
  box-shadow: var(--sh-3);
}
.modal-mark svg { width: 36px; height: 36px; }

/* Celebration */
.celebrate-burst {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 80;
}
.confetti {
  position: absolute;
  width: 8px; height: 12px;
  top: -10px;
  animation: confetti-fall 1.6s ease-out forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* Responsive */
@media (max-width: 980px) {
  .main-grid { grid-template-columns: 1fr; }
  .shape-picker { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .app { padding: 16px; }
  .topbar { flex-wrap: wrap; }
  .shape-card { padding: 10px; }
  .shape-card .info .sub { display: none; }
  .panel { padding: 14px; }
}
