:root {
  --bg: #f6f3ec;
  --panel: #fffefa;
  --ink: #22211f;
  --muted: #68635c;
  --line: #ddd5c8;
  --accent: #1f7a6d;
  --accent-soft: #d9ebe7;
  --warn: #b85c38;
  --gold: #c9962d;
  --shadow: 0 16px 40px rgba(34, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 20px;
}

.eyebrow,
.small-label {
  margin: 0 0 6px;
  color: var(--warn);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 6vw, 58px);
  line-height: 1;
}

.summary {
  min-width: 112px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 800;
}

.summary small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.tabs {
  display: flex;
  gap: 8px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 18px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-width: 92px;
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 760;
}

.tab.active {
  border-color: var(--accent);
  color: var(--ink);
}

main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 56px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 26px 0 18px;
}

.section-title h2 {
  margin: 0;
  font-size: 28px;
}

.section-title p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
}

.source-panel {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8e8;
  color: var(--muted);
}

.source-panel strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.source-panel p {
  margin: 0;
}

.source-panel code {
  color: var(--warn);
  font-size: 0.95em;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.letter-card {
  display: grid;
  gap: 12px;
  min-height: 220px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.letter-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.tibetan-letter {
  font-family: "Noto Serif Tibetan", "Microsoft Himalaya", serif;
  font-size: 68px;
  line-height: 1;
}

.status-select {
  min-width: 88px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.latin {
  margin: 0;
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
}

.latin span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}


.meaning {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--gold);
  background: #fff8e8;
  color: var(--ink);
  font-size: 14px;
  font-weight: 720;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
}

.quiz-panel {
  display: grid;
  justify-items: center;
  gap: 20px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.quiz-letter {
  font-family: "Noto Serif Tibetan", "Microsoft Himalaya", serif;
  font-size: clamp(96px, 18vw, 180px);
  line-height: 1;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 10px;
  width: min(520px, 100%);
}

.option-button,
.text-button,
.audio-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 760;
}

.option-button:hover,
.text-button:hover,
.audio-button:hover {
  border-color: var(--accent);
}

.audio-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.option-button.correct {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option-button.wrong {
  border-color: var(--warn);
  background: #f7e1d7;
}

.quiz-feedback {
  min-height: 26px;
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.write-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}

.write-card,
.canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.write-card {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
}

.write-letter {
  font-family: "Noto Serif Tibetan", "Microsoft Himalaya", serif;
  font-size: 132px;
  line-height: 1;
}

.canvas-wrap {
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: min(420px, 58vh);
  background:
    linear-gradient(90deg, rgba(221, 213, 200, 0.52) 1px, transparent 1px),
    linear-gradient(rgba(221, 213, 200, 0.52) 1px, transparent 1px), #fffefa;
  background-size: 40px 40px;
  touch-action: none;
}

.canvas-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px;
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .write-layout {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 560px) {
  .app-header,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    overflow-x: auto;
  }

  .card-grid,
  .quiz-options {
    grid-template-columns: 1fr;
  }
}
