:root {
  --bg: #f6f0e6;
  --panel: #fffdf8;
  --panel-soft: #f1e7d7;
  --text: #2d241d;
  --muted: #716155;
  --line: #d8c5ad;
  --accent: #8e2d25;
  --accent-warm: #bd8129;
  --shadow: 0 14px 34px rgba(75, 43, 20, .08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 14% 0%, rgba(189, 129, 41, .1), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: Arial, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

button, input, select { font: inherit; }

.page-shell {
  width: min(calc(100% - 32px), 1500px);
  margin: 0 auto;
}

.breadcrumbs { padding: 14px 2px 0; }
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  gap: 7px;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
}
.breadcrumbs li + li::before { content: "/"; margin-right: 7px; opacity: .55; }
.breadcrumbs a { color: inherit; text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent); text-decoration: underline; }

.page-intro {
  padding: 24px 2px 18px;
}
.page-intro .eyebrow,
.section-number {
  margin: 0 0 4px;
  color: var(--accent-warm);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.page-intro h1 {
  max-width: 960px;
  margin: 0;
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.16;
}
.page-intro p:last-child { max-width: 880px; margin: 9px 0 0; color: var(--muted); }

.input-panel {
  margin-bottom: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.input-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}
.input-panel h2 { margin: 0; color: var(--accent); font-size: 18px; }
.input-panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.input-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(150px, .8fr) minmax(150px, .8fr);
  align-items: end;
  margin-top: 13px;
  gap: 12px;
}
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { color: #604735; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.field input,
.field select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #bba487;
  border-radius: 9px;
  outline: none;
  background: #fffdfa;
  color: var(--text);
}
.field input:focus,
.field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(142, 45, 37, .12); }
.field small { color: var(--muted); font-size: 11px; }
.field.is-muted { opacity: .48; }
.input-arrow { padding-bottom: 10px; color: var(--accent-warm); font-size: 24px; font-weight: 800; }
.direction-switch {
  display: flex;
  flex-wrap: wrap;
  margin-top: 13px;
  gap: 7px;
}
.direction-switch[hidden] { display: none; }
.direction-button {
  min-height: 34px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffaf2;
  color: var(--text);
  cursor: pointer;
}
.direction-button.is-active { border-color: var(--accent); background: var(--accent); color: #fff; }

.learning-layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 220px;
  align-items: start;
  gap: 18px;
}
.side-card,
.lesson-content {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.side-card { position: sticky; top: 84px; overflow: hidden; }
.side-card > h2 {
  margin: 0;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  font-size: 15px;
}
.lesson-list,
.toc-list { display: grid; padding: 10px; gap: 7px; }
.lesson-button {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}
.lesson-button span { display: block; margin-bottom: 2px; color: var(--accent); font-size: 12px; font-weight: 800; }
.lesson-button:hover,
.lesson-button.is-active { background: #f2dfb4; color: #6e241e; }
.toc-list a {
  padding: 9px 10px;
  border-left: 3px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}
.toc-list a:hover,
.toc-list a.is-active { border-color: var(--accent); background: #f4e2ba; color: var(--accent); font-weight: 700; }

.lesson-content { min-width: 0; padding: 0 26px; }
.content-section { scroll-margin-top: 86px; padding: 28px 0; }
.content-section + .content-section { border-top: 1px solid var(--line); }
.content-section h2 {
  margin: 0 0 14px;
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(23px, 3vw, 30px);
}
.knowledge-box {
  padding: 17px 19px;
  border-left: 4px solid var(--accent-warm);
  border-radius: 0 12px 12px 0;
  background: var(--panel-soft);
}
.knowledge-box p { margin: 0; }
.knowledge-box p + p { margin-top: 10px; }
.knowledge-box strong { color: var(--accent); }

.practice-card {
  overflow: hidden;
  border: 1px dashed #cdb697;
  border-radius: 16px;
  background: linear-gradient(135deg, #fffdf8, #f5ecdf);
}
.svg-stage {
  display: grid;
  min-height: 460px;
  place-items: center;
  padding: 18px;
}
.svg-stage svg { display: block; width: min(100%, 620px); max-height: 620px; }
.svg-loading { color: var(--muted); }
.svg-stage .is-bam-visible { opacity: 1 !important; visibility: visible !important; }
.svg-stage .is-bam-highlight {
  filter: drop-shadow(0 0 4px rgba(169, 64, 31, .75));
}
.svg-stage .is-bam-press { animation: press-pop .48s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
.svg-stage .is-bam-blink { animation: lesson-blink .55s ease-in-out infinite alternate; }
@keyframes press-pop { to { transform: scale(1.12); filter: drop-shadow(0 0 7px rgba(142, 45, 37, .8)); } }
@keyframes lesson-blink { from { opacity: .35; } to { opacity: 1; filter: drop-shadow(0 0 7px rgba(189, 129, 41, .9)); } }
@media (prefers-reduced-motion: reduce) {
  .svg-stage .is-bam-press,
  .svg-stage .is-bam-blink { animation-duration: 1.2s; }
}
.practice-status {
  min-height: 55px;
  margin: 0;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .54);
  color: #594538;
  text-align: center;
}
.practice-status strong { color: var(--accent); }
.practice-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-top: 1px solid var(--line);
  gap: 9px;
}
.primary-button,
.secondary-button,
.speed-control button {
  min-height: 42px;
  border-radius: 10px;
  cursor: pointer;
}
.primary-button { min-width: 112px; padding: 0 18px; border: 1px solid var(--accent); background: var(--accent); color: #fff; font-weight: 800; }
.secondary-button { min-width: 100px; padding: 0 16px; border: 1px solid var(--line); background: #fffaf2; color: var(--text); font-weight: 700; }
button:disabled { cursor: not-allowed; opacity: .48; }
.speed-control {
  display: grid;
  grid-template-columns: 38px 62px 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffaf2;
}
.speed-control button { min-height: 40px; border: 0; border-radius: 0; background: transparent; color: var(--accent); font-size: 20px; font-weight: 800; }
.speed-control button:hover { background: var(--panel-soft); }
.speed-control output { display: grid; place-items: center; font-weight: 800; }

.mobile-tools { display: none; }

@media (max-width: 1040px) {
  .learning-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .toc-column { display: none; }
}

@media (max-width: 760px) {
  .page-shell { width: min(calc(100% - 18px), 1500px); }
  .tuvi9-shell-header-inner { width: calc(100% - 18px); grid-template-columns: auto 1fr; }
  .tuvi9-shell-header-spacer { display: none; }
  .tuvi9-shell-nav { justify-content: flex-end; }
  .tuvi9-shell-nav a { min-height: 34px; padding: 0 8px; font-size: 12px; }
  .tuvi9-shell-nav a:first-child { display: none; }
  .page-intro { padding-top: 18px; }
  .input-panel { padding: 15px; }
  .input-panel-head { display: block; }
  .input-panel-head p { margin-top: 3px; }
  .input-grid { grid-template-columns: 1fr 1fr; }
  .input-arrow { display: none; }
  #year-field { grid-column: 1 / -1; }
  .direction-switch { display: grid; grid-template-columns: 1fr 1fr; }
  .direction-button { border-radius: 9px; font-size: 12px; }
  .mobile-tools { display: flex; margin: 0 0 10px; gap: 8px; }
  .mobile-tools button {
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--accent);
    font-weight: 800;
  }
  .learning-layout { display: block; }
  .side-card { position: static; display: none; margin-bottom: 10px; }
  .side-card.is-open { display: block; }
  .lesson-content { padding: 0 16px; }
  .content-section { padding: 22px 0; }
  .svg-stage { min-height: 400px; padding: 10px; }
}

@media (max-width: 430px) {
  .tuvi9-shell-brand img { width: 58px; height: 38px; }
  .tuvi9-shell-nav a:last-child { display: none; }
  .input-grid { gap: 9px; }
  .field input, .field select { padding: 0 8px; }
  .svg-stage { min-height: 340px; }
  .practice-controls { gap: 7px; }
  .primary-button, .secondary-button { min-width: 91px; padding-inline: 12px; }
}
