:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #eef3f8;
  --text: #142033;
  --muted: #5d6b7c;
  --line: #d9e1ea;
  --accent: #166f8d;
  --accent-strong: #0f536a;
  --action-bg: #050608;
  --action-text: #ffffff;
  --action-disabled-bg: #cfd5dc;
  --action-disabled-text: #5d6673;
  --focus: #c77a22;
  --danger: #b23b3b;
  --shadow: 0 18px 40px rgba(28, 42, 62, 0.12);
  --tab-height: 84px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050608;
  --surface: #111418;
  --surface-strong: #1a2027;
  --text: #f4f7fb;
  --muted: #aab4c2;
  --line: #2a333d;
  --accent: #8fd9ff;
  --accent-strong: #bfeaff;
  --action-bg: #ffffff;
  --action-text: #050608;
  --action-disabled-bg: #454b53;
  --action-disabled-text: #aeb6c2;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #050608;
    --surface: #111418;
    --surface-strong: #1a2027;
    --text: #f4f7fb;
    --muted: #aab4c2;
    --line: #2a333d;
    --accent: #8fd9ff;
    --accent-strong: #bfeaff;
    --action-bg: #ffffff;
    --action-text: #050608;
    --action-disabled-bg: #454b53;
    --action-disabled-text: #aeb6c2;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(var(--tab-height) + env(safe-area-inset-bottom));
}

.app-content {
  min-height: calc(100vh - var(--tab-height));
}

.app-section {
  display: none;
  min-height: calc(100vh - var(--tab-height));
}

.app-section.active {
  display: block;
}

.adhoc-layout {
  display: grid;
  grid-template-columns: 300px minmax(400px, 1fr) minmax(360px, 430px);
  min-height: 100vh;
}

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

.brand-logo {
  border-radius: 16px;
  box-shadow: 0 10px 22px rgba(8, 10, 12, 0.18);
  flex: 0 0 auto;
  height: 62px;
  object-fit: cover;
  width: 62px;
}

.catalog-panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  overflow-y: auto;
  padding: 22px 18px;
}

.language-block,
.catalog-browser,
.exercise-browser {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.language-block label {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
}

.catalog-title-row {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.source-link {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.source-link.hidden {
  display: none;
}

.catalog-tree {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.catalog-tree details {
  border-left: 2px solid transparent;
}

.catalog-tree details[open] {
  border-left-color: var(--accent);
}

.catalog-tree summary,
.topic-button,
.exercise-button {
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}

.catalog-tree summary {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
  list-style: none;
  padding: 8px 8px 8px 10px;
}

.catalog-tree summary::-webkit-details-marker {
  display: none;
}

.catalog-tree summary::before {
  color: var(--muted);
  content: "›";
  display: inline-block;
  font-weight: 900;
  margin-right: 7px;
  transform: rotate(0deg);
  transition: transform 120ms ease;
}

.catalog-tree details[open] > summary::before {
  transform: rotate(90deg);
}

.catalog-children {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 12px;
  padding: 2px 0 4px;
}

.topic-button,
.exercise-button {
  background: transparent;
  color: var(--text);
  display: block;
  font-weight: 750;
  padding: 9px 10px;
  text-align: left;
}

.topic-button:hover,
.catalog-tree summary:hover,
.exercise-button:hover {
  background: var(--surface-strong);
}

.topic-button.active,
.exercise-button.active {
  background: #dcece9;
  color: var(--accent-strong);
}

.selected-topic {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  min-height: 20px;
}

.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exercise-button {
  border: 1px solid var(--line);
  line-height: 1.35;
}

.exercise-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 850;
}

.exercise-preview {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 4px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
}

.topbar {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.eyebrow.mini {
  color: #8b5a10;
  font-size: 0.72rem;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 2.2vw, 2.1rem);
  line-height: 1.04;
}

h2 {
  font-size: 1rem;
}

.model-chip {
  align-items: center;
  background: #050608;
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 700;
  min-height: 36px;
  padding: 0 14px;
  white-space: nowrap;
}

.model-chip.missing {
  background: var(--danger);
}

.learner-stats {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 10px;
}

.stat-tile span {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  margin-bottom: 3px;
}

.stat-tile strong {
  color: var(--text);
  display: block;
  font-size: 1.18rem;
  line-height: 1.1;
}

.capture-panel {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.preview-frame {
  align-items: center;
  background:
    linear-gradient(90deg, rgba(20, 32, 51, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(20, 32, 51, 0.035) 1px, transparent 1px),
    var(--surface);
  background-size: 28px 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex: 0 0 auto;
  justify-content: center;
  height: min(54vh, 470px);
  min-height: 300px;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.preview-frame.portrait-preview {
  align-self: center;
  aspect-ratio: 9 / 16;
  height: auto;
  max-width: 330px;
  width: min(100%, 330px);
}

.preview-frame.landscape-preview {
  height: min(48vh, 430px);
}

.camera-preview {
  display: none;
  height: 100%;
  inset: 0;
  object-fit: contain;
  position: absolute;
  width: 100%;
  z-index: 2;
}

.camera-preview.active {
  display: block;
}

.camera-preview.portrait-rotated {
  transform: rotate(90deg) scale(0.72);
}

#previewCanvas {
  display: block;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  width: 100%;
  z-index: 1;
}

.empty-preview {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 7px;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: absolute;
  text-align: center;
  z-index: 3;
}

.empty-preview strong {
  color: var(--text);
  font-size: 1.1rem;
}

.empty-preview.hidden {
  display: none;
}

.camera-row,
.action-row {
  display: grid;
  gap: 10px;
}

.camera-row {
  grid-template-columns: minmax(0, 1fr) minmax(150px, 190px) minmax(150px, 190px);
}

.action-row {
  grid-template-columns: minmax(0, 1fr) minmax(150px, 190px) 48px;
}

.file-button,
.primary-button,
.secondary-button,
.icon-button {
  align-items: center;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 48px;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease;
}

.file-button {
  background: var(--surface-strong);
  color: var(--text);
  overflow: hidden;
  position: relative;
}

.file-button input {
  inset: 0;
  opacity: 0;
  position: absolute;
}

.secondary-button {
  background: var(--surface-strong);
  color: var(--text);
}

.primary-button {
  background: var(--action-bg);
  color: var(--action-text);
}

.primary-button:enabled:hover,
.secondary-button:enabled:hover,
.file-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  background: var(--action-disabled-bg);
  color: var(--action-disabled-text);
  cursor: not-allowed;
}

.icon-button {
  background: #ffe8e8;
  color: var(--danger);
  font-size: 1.6rem;
  line-height: 1;
}

.side-panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  overflow-y: auto;
  padding: 22px;
}

.panel-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-block label,
.segmented-label {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
}

textarea,
input[type="text"],
input[type="search"],
select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  min-height: 42px;
  padding: 10px 12px;
  width: 100%;
}

textarea {
  resize: vertical;
}

textarea:focus,
input[type="text"]:focus,
input[type="search"]:focus,
select:focus,
button:focus-visible,
.file-button:focus-within {
  outline: 3px solid rgba(214, 139, 25, 0.34);
  outline-offset: 2px;
}

.segmented {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.segmented label {
  align-items: center;
  cursor: pointer;
  display: flex;
  font-size: 0.82rem;
  justify-content: center;
  min-height: 40px;
  padding: 0 8px;
  text-align: center;
}

.segmented input {
  inline-size: 0;
  opacity: 0;
  position: absolute;
}

.segmented label:has(input:checked) {
  background: var(--text);
  color: #fff;
}

.checkbox-line {
  align-items: center;
  display: flex;
  gap: 10px;
}

.checkbox-line input {
  accent-color: var(--accent);
  height: 18px;
  width: 18px;
}

.progress-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress-header,
.meter-row,
.quiz-head {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.text-button {
  background: transparent;
  border-radius: 8px;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 850;
  min-height: 34px;
  padding: 0 8px;
}

.text-button:hover {
  background: #eef7f3;
}

.level-meter {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.meter-row {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.level-bar {
  background: #e6edf5;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  width: 100%;
}

.level-bar span {
  background: linear-gradient(90deg, #166f8d, #c77a22);
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 0%;
}

.challenge-card,
.quiz-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.challenge-card {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.challenge-card h3,
.quiz-card h3,
.badge-shelf h3 {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.2;
  margin: 0;
}

.challenge-card p,
.quiz-card p {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
  margin: 5px 0 0;
}

.compact-button {
  font-size: 0.82rem;
  min-height: 40px;
  padding: 0 12px;
  white-space: nowrap;
}

.compact-button.done {
  background: #dcece9;
  color: var(--accent-strong);
}

.quiz-head span {
  background: #fff4df;
  border: 1px solid #f0d3a5;
  border-radius: 999px;
  color: #7b4c0d;
  font-size: 0.72rem;
  font-weight: 850;
  padding: 3px 8px;
  white-space: nowrap;
}

.quiz-options {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.quiz-option {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  min-height: 40px;
  padding: 8px 10px;
  text-align: left;
}

.quiz-option:hover,
.quiz-option:focus-visible {
  background: var(--surface-strong);
}

.quiz-option.correct {
  background: #dcece9;
  border-color: #a8d1c9;
  color: var(--accent-strong);
}

.quiz-option.incorrect {
  background: #ffe8e8;
  border-color: #f0bbbb;
  color: var(--danger);
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-feedback {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.4;
  margin-top: 9px;
  min-height: 18px;
}

.badge-shelf {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 2px;
}

.badge {
  background: #eef7f3;
  border: 1px solid #c9e3d7;
  border-radius: 999px;
  color: #386050;
  font-size: 0.74rem;
  font-weight: 850;
  line-height: 1.2;
  padding: 5px 8px;
}

.badge.locked {
  background: #f3f5f8;
  border-color: #dfe6ee;
  color: #7b8794;
}

.feature-section {
  padding: 24px;
}

.feature-header {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 auto 18px;
  max-width: 1120px;
}

.feature-header h1 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.challenge-grid,
.community-grid,
.menu-grid {
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 1120px;
}

.challenge-grid {
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.7fr);
}

.challenge-home,
.badge-vault,
.community-card,
.menu-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.badge-vault h2,
.community-card h2,
.menu-card h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
}

.badge-vault .badge-list {
  gap: 10px;
}

.badge-vault .badge {
  border-radius: 8px;
  font-size: 0.86rem;
  padding: 10px 12px;
}

.community-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.community-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.community-card.wide {
  grid-column: 1 / -1;
}

.community-card p,
.menu-card p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.classmates {
  display: flex;
  gap: 8px;
}

.classmates span {
  align-items: center;
  background: #050608;
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 0.8rem;
  font-weight: 850;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.community-actions {
  grid-template-columns: 1fr 1fr;
}

.collab-list {
  display: grid;
  gap: 8px;
}

.collab-list button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  min-height: 44px;
  padding: 10px 12px;
  text-align: left;
}

.collab-list button:hover {
  background: var(--surface-strong);
}

.menu-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.menu-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-card label {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
}

.menu-toggle {
  margin-top: 4px;
}

.menu-logo-row {
  align-items: center;
  display: flex;
  gap: 12px;
}

.menu-logo-row img {
  border-radius: 12px;
  height: 54px;
  width: 54px;
}

.bottom-tabs {
  align-items: stretch;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-top: 1px solid var(--line);
  bottom: 0;
  box-shadow: 0 -10px 28px rgba(28, 42, 62, 0.12);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  height: calc(var(--tab-height) + env(safe-area-inset-bottom));
  left: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  position: fixed;
  right: 0;
  z-index: 20;
}

.bottom-tab {
  align-items: center;
  background: transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-size: 0.74rem;
  font-weight: 850;
  gap: 4px;
  justify-content: center;
  min-width: 0;
  padding: 5px 4px;
}

.bottom-tab.active {
  background: var(--surface-strong);
  color: var(--text);
}

.tab-icon {
  display: block;
  fill: currentColor;
  height: 27px;
  width: 27px;
}

.answer-panel,
.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.answer-panel {
  background: #fbfbf4;
}

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

.answer-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.voice-button {
  align-items: center;
  background: var(--surface-strong);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 900;
  height: 32px;
  justify-content: center;
  width: 36px;
}

.voice-button:hover {
  background: #dcece9;
  color: var(--accent-strong);
}

.voice-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.voice-spinner {
  animation: spin 900ms linear infinite;
  border: 3px solid rgba(38, 54, 75, 0.24);
  border-radius: 999px;
  border-top-color: var(--accent-strong);
  height: 16px;
  width: 16px;
}

.voice-disclosure {
  background: #eef7f3;
  border: 1px solid #c9e3d7;
  border-radius: 999px;
  color: #386050;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 7px;
  white-space: nowrap;
}

#statusText {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.answer-text {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.55;
  margin-top: 12px;
  white-space: pre-wrap;
}

.answer-text.error {
  color: var(--danger);
}

.history-panel {
  background: #f9fbfd;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.history-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.history-answer {
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.4;
}

.spinner {
  animation: spin 900ms linear infinite;
  border: 3px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  border-radius: 999px;
  height: 18px;
  width: 18px;
}

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

@media (max-width: 920px) {
  .adhoc-layout {
    grid-template-columns: 1fr;
  }

  .catalog-panel {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    max-height: 56vh;
  }

  .workspace {
    padding: 18px;
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 18px;
  }

  .preview-frame {
    min-height: 390px;
  }

  .learner-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #previewCanvas {
    max-height: 62vh;
  }

  .challenge-grid,
  .community-grid,
  .menu-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .camera-row {
    grid-template-columns: 1fr;
  }

  .icon-button {
    min-height: 44px;
  }

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

  .challenge-card {
    grid-template-columns: 1fr;
  }

  .compact-button {
    width: 100%;
  }

  .preview-frame {
    min-height: 310px;
  }

  .feature-section {
    padding: 18px 14px;
  }

  .feature-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-logo {
    border-radius: 12px;
    height: 50px;
    width: 50px;
  }

  .bottom-tabs {
    padding-left: 6px;
    padding-right: 6px;
  }

  .bottom-tab {
    font-size: 0.68rem;
  }

  .tab-icon {
    height: 25px;
    width: 25px;
  }
}
