:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #edf8f1;
  --ink: #232a34;
  --muted: #667085;
  --line: #dde3eb;
  --primary: #4fb96f;
  --primary-dark: #25874a;
  --coral: #ff6b5f;
  --gold: #f4c44f;
  --teal: #35a7a0;
  --violet: #7d6ce3;
  --blue: #4489d6;
  --shadow: 0 18px 45px rgba(28, 40, 55, 0.12);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 11% 6%, rgba(79, 185, 111, 0.13), transparent 22rem),
    radial-gradient(circle at 92% 12%, rgba(53, 167, 160, 0.08), transparent 24rem),
    linear-gradient(180deg, #ffffff 0, var(--bg) 34rem);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 18px calc(22px + var(--safe-bottom));
}

.topbar,
.lesson-header,
.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  align-items: center;
  margin-bottom: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border: 2px solid #1f2937;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--coral) 0 50%, #fff 50%),
    linear-gradient(90deg, transparent, transparent);
  box-shadow: inset 0 0 0 4px #fff, 0 8px 16px rgba(28, 40, 55, 0.12);
}

.brand strong {
  display: block;
  font-size: 1.24rem;
  line-height: 1.1;
}

.brand span:not(.brand-mark) {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 2px;
}

.stats-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.stat-pill {
  min-width: 86px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 8px 18px rgba(28, 40, 55, 0.06);
}

.stat-pill span,
.session-label,
.eyebrow,
.module-kicker {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-pill strong {
  display: block;
  font-size: 1.08rem;
  margin-top: 2px;
}

.sync-banner {
  display: flex;
  align-items: center;
  min-height: 34px;
  margin-bottom: 12px;
  padding: 8px 10px;
  color: #35503f;
  background: rgba(237, 248, 241, 0.9);
  border: 1px solid rgba(79, 185, 111, 0.32);
  border-radius: var(--radius);
  font-weight: 750;
}

.sync-banner.local {
  color: #624919;
  background: #fff7df;
  border-color: rgba(244, 196, 79, 0.5);
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.tab-button,
.primary-button,
.secondary-button,
.icon-button,
.palette-button,
.path-node,
.module-card,
.choice-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  touch-action: manipulation;
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 850;
}

.tab-button.active {
  color: #0d3b21;
  background: var(--surface-soft);
  border-color: rgba(79, 185, 111, 0.45);
}

.tab-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--coral);
}

.tab-button:nth-child(2) .tab-dot {
  background: var(--teal);
}

.tab-button:nth-child(3) .tab-dot {
  background: var(--gold);
}

.tab-button:nth-child(4) .tab-dot {
  background: var(--violet);
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 2.55rem);
  line-height: 1.05;
  margin-top: 2px;
}

h2 {
  font-size: 1.04rem;
}

h3 {
  font-size: 0.98rem;
}

.section-heading {
  margin-bottom: 14px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
  gap: 12px;
}

.module-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  align-items: start;
  min-height: 170px;
  padding: 16px;
  text-align: left;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.module-card.active {
  background: var(--surface-soft);
  border-color: rgba(79, 185, 111, 0.48);
}

.module-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: var(--radius);
  color: #233143;
  border: 2px solid #253143;
  background: #fff;
  font-weight: 950;
}

.module-card p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.42;
}

.module-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.module-meta span,
.lesson-meta span,
.naming-meta span {
  padding: 7px 9px;
  color: #2b3a48;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 850;
}

.lesson-header {
  margin-bottom: 14px;
}

.lesson-meta,
.naming-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.lesson-stage {
  display: grid;
  grid-template-columns: minmax(260px, 0.82fr) minmax(320px, 1.18fr);
  gap: 14px;
  align-items: stretch;
}

.pattern-panel,
.toolbelt,
.session-card,
.path-unit,
.achievement-card,
.safety-note,
.naming-panel,
.level-dialog::backdrop {
  border-radius: var(--radius);
}

.pattern-panel,
.toolbelt,
.session-card,
.path-unit,
.achievement-card,
.naming-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.pattern-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 320px;
  padding: 14px;
  overflow: hidden;
}

.work-panel {
  background:
    linear-gradient(180deg, rgba(79, 185, 111, 0.07), transparent 55%),
    var(--surface);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.timer {
  min-width: 72px;
  padding: 7px 10px;
  color: #0d3b21;
  background: var(--surface-soft);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 950;
}

.icon-button {
  width: 44px;
  color: var(--ink);
  background: #f0f4f8;
  border: 1px solid var(--line);
  font-weight: 950;
}

.cube-board {
  --grid-size: 2;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  gap: clamp(5px, 1.4vw, 10px);
  width: min(100%, 520px);
  margin: auto;
  padding: clamp(8px, 2vw, 14px);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(35, 42, 52, 0.05), rgba(35, 42, 52, 0.01)),
    #f9fbfd;
  border: 1px solid #d7dee8;
}

.target-board {
  max-width: 360px;
}

.cube-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  padding: 0;
  border: 2px solid #253143;
  border-radius: 6px;
  background: #f0f4f8;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55), 0 5px 10px rgba(28, 40, 55, 0.12);
  -webkit-appearance: none;
  appearance: none;
}

.work-board .cube-cell {
  cursor: pointer;
}

.cube-cell.pending {
  border-style: dashed;
  border-color: #aeb8c6;
  background: #eef2f6;
}

.cube-cell.wrong {
  animation: wrong-pulse 0.7s ease;
  border-color: var(--coral);
}

.cube-cell.hinted {
  animation: hint-pulse 0.9s ease;
  border-color: var(--gold);
}

.face-white {
  background: #ffffff;
}

.face-red {
  background: var(--coral);
}

.face-diag-a {
  background: linear-gradient(135deg, var(--coral) 0 50%, #ffffff 50%);
}

.face-diag-b {
  background: linear-gradient(225deg, var(--coral) 0 50%, #ffffff 50%);
}

.face-diag-c {
  background: linear-gradient(315deg, var(--coral) 0 50%, #ffffff 50%);
}

.face-diag-d {
  background: linear-gradient(45deg, var(--coral) 0 50%, #ffffff 50%);
}

.memory-cover {
  position: absolute;
  inset: 48px 14px 14px;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 8px;
  color: #fff;
  background: rgba(35, 42, 52, 0.86);
  border-radius: var(--radius);
  text-align: center;
}

.memory-cover.hidden {
  display: none;
}

.toolbelt {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
  padding: 12px;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.palette-button {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 106px;
  padding: 7px 9px;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid var(--line);
  font-weight: 850;
}

.palette-button.active {
  background: #fff7df;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(244, 196, 79, 0.22);
}

.palette-swatch {
  width: 34px;
  height: 34px;
  border: 2px solid #253143;
  border-radius: 5px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.48);
}

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

.primary-button,
.secondary-button {
  padding: 10px 14px;
  font-weight: 950;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 7px 0 var(--primary-dark);
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 4px 0 var(--primary-dark);
}

.secondary-button {
  color: #253143;
  background: #eef3f7;
  border: 1px solid var(--line);
}

.compact {
  min-height: 38px;
  padding: 8px 10px;
}

.feedback {
  min-height: 42px;
  margin-top: 12px;
  padding: 11px 12px;
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  background: #ffffff;
  color: #2f3a47;
  font-weight: 850;
}

.feedback.warning {
  border-left-color: var(--coral);
}

.feedback.success {
  border-left-color: var(--primary);
}

.session-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-top: 12px;
  overflow: hidden;
}

.session-card > div {
  padding: 12px;
  background: #fbfcfd;
}

.session-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.naming-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.05fr);
  gap: 14px;
  align-items: stretch;
}

.naming-panel {
  padding: 14px;
}

.naming-image {
  display: grid;
  place-items: center;
  min-height: 332px;
  border: 1px solid #d7dee8;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(68, 137, 214, 0.08), transparent),
    #fbfcfd;
}

.naming-image svg {
  width: min(100%, 330px);
  height: auto;
}

.naming-image .stimulus-img {
  display: block;
  width: min(100%, 330px);
  max-height: 300px;
  object-fit: contain;
}

.answer-form {
  display: grid;
  gap: 10px;
}

.answer-input {
  width: 100%;
  min-height: 52px;
  padding: 12px 13px;
  color: var(--ink);
  background: #ffffff;
  border: 2px solid #cad4e0;
  border-radius: var(--radius);
  font-size: 1.08rem;
}

.hint-stack {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.hint-line {
  padding: 10px;
  color: #364656;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  line-height: 1.4;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.choice-button {
  padding: 9px 11px;
  color: #253143;
  background: #eef3f7;
  border: 1px solid var(--line);
  font-weight: 850;
}

.path-map {
  display: grid;
  gap: 14px;
}

.path-unit {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 16px;
  padding: 14px;
}

.path-unit p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.path-levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 10px;
  align-items: start;
}

.path-node {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 72px;
  padding: 8px;
  color: #233143;
  background: #f8fafc;
  border: 2px solid #d7dee8;
  font-weight: 950;
}

.path-node span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 3px;
  font-weight: 850;
}

.path-node.unlocked {
  background: #ecf9f0;
  border-color: rgba(79, 185, 111, 0.62);
}

.path-node.completed {
  color: #0f3d23;
  background: #dff6e7;
  border-color: var(--primary);
}

.path-node.locked {
  color: #8a94a4;
  background: #eef1f5;
  cursor: not-allowed;
}

.achievement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.achievement-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.achievement-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: var(--radius);
  color: #233143;
  background: #eef3f7;
  border: 1px solid var(--line);
  font-weight: 950;
}

.achievement-card.unlocked .achievement-icon {
  background: #fff2c8;
  border-color: var(--gold);
}

.achievement-card p {
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}

.safety-note {
  margin-top: 18px;
  padding: 11px 12px;
  color: #53606f;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.86rem;
}

.level-dialog {
  width: min(420px, calc(100% - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
  background: transparent;
}

.level-dialog::backdrop {
  background: rgba(35, 42, 52, 0.48);
}

.dialog-inner {
  padding: 24px;
  background: #ffffff;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
}

.dialog-badge {
  display: inline-block;
  width: 68px;
  height: 68px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 3px solid #253143;
  background:
    linear-gradient(135deg, var(--coral) 0 50%, #ffffff 50%),
    var(--gold);
  box-shadow: inset 0 0 0 5px #fff;
}

.dialog-inner p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.dialog-stats {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 18px;
}

.dialog-stats span {
  padding: 8px 10px;
  background: #eef3f7;
  border-radius: var(--radius);
  font-weight: 950;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(125, 108, 227, 0.45);
  outline-offset: 2px;
}

@keyframes wrong-pulse {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  60% {
    transform: translateX(5px);
  }
}

@keyframes hint-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(244, 196, 79, 0.58);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(244, 196, 79, 0);
  }
}

@media (max-width: 900px) {
  .topbar,
  .lesson-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .stats-strip,
  .lesson-meta,
  .naming-meta {
    justify-content: flex-start;
  }

  .lesson-stage,
  .path-unit,
  .naming-grid {
    grid-template-columns: 1fr;
  }

  .pattern-panel {
    min-height: 278px;
  }

  .toolbelt {
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 12px;
  }

  .view-tabs {
    position: sticky;
    top: calc(6px + var(--safe-top));
    z-index: 5;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
  }

  .tab-button {
    min-height: 50px;
    padding-inline: 4px;
    font-size: 0.82rem;
  }

  .tab-dot {
    display: none;
  }

  .module-card {
    grid-template-columns: 48px 1fr;
    min-height: 150px;
    padding: 13px;
  }

  .module-icon {
    width: 48px;
    height: 48px;
  }

  .palette-button {
    grid-template-columns: 32px;
    justify-items: center;
    min-width: 58px;
    min-height: 58px;
  }

  .palette-button span:not(.palette-swatch) {
    display: none;
  }

  .palette-swatch {
    width: 32px;
    height: 32px;
  }

  .session-card {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .session-card > div {
    padding: 10px;
  }

  .session-card strong {
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
