:root {
  --bg: #f4efe6;
  --bg-strong: #efe3cf;
  --panel: rgba(255, 251, 245, 0.82);
  --panel-border: rgba(87, 63, 37, 0.12);
  --ink: #221a14;
  --muted: #6b5d51;
  --accent: #b5522d;
  --accent-strong: #8f3d1f;
  --accent-soft: #f5d4bf;
  --success: #1f7a52;
  --danger: #ab2f2f;
  --shadow: 0 24px 60px rgba(70, 43, 19, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --line: #3d3025;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 30%),
    radial-gradient(circle at right 10% top 20%, rgba(181, 82, 45, 0.18), transparent 25%),
    linear-gradient(160deg, #f8f3ed 0%, #efe2cf 48%, #e4d2ba 100%);
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 26px;
}

.eyebrow,
.play-label,
.feedback-label {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  color: var(--muted);
}

h1,
h2,
h3 {
  margin: 0;
}

h1,
.hero-card strong {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

h1 {
  font-size: clamp(2.2rem, 4vw, 4.2rem);
  line-height: 0.95;
  max-width: 10ch;
}

.hero-copy {
  margin: 14px 0 0;
  max-width: 62ch;
  font-size: 1.03rem;
  color: var(--muted);
  line-height: 1.65;
}

.hero-card,
.panel {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.hero-card {
  min-width: 220px;
  padding: 20px;
  border-radius: var(--radius-lg);
  display: grid;
  gap: 8px;
}

.hero-card-label,
.hero-card-meta {
  color: var(--muted);
}

.hero-card strong {
  font-size: 3rem;
  line-height: 1;
}

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

.panel {
  border-radius: var(--radius-xl);
  padding: 22px;
}

.controls-panel {
  display: grid;
  gap: 20px;
  align-content: start;
}

.controls-panel section {
  display: grid;
  gap: 14px;
}

.control-group {
  display: grid;
  gap: 8px;
}

label,
.status-text,
#answers-help {
  color: var(--muted);
}

select,
.primary-button,
.secondary-button,
.ghost-button,
.answer-button {
  border-radius: 999px;
  border: 1px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

select {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(87, 63, 37, 0.16);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button {
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff8f3;
  box-shadow: 0 14px 26px rgba(143, 61, 31, 0.28);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(87, 63, 37, 0.14);
  color: var(--ink);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(87, 63, 37, 0.14);
  color: var(--ink);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.answer-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled),
.answer-button:hover:not(:disabled),
select:hover {
  transform: translateY(-1px);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(87, 63, 37, 0.1);
}

.stat-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.stat-card strong {
  font-size: 1.8rem;
}

.stat-card.accent {
  background: linear-gradient(135deg, rgba(181, 82, 45, 0.15), rgba(245, 212, 191, 0.75));
}

.play-panel {
  display: grid;
  gap: 18px;
  align-content: start;
}

.game-topbar,
.game-hud {
  display: none;
}

.game-topbar {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255, 248, 239, 0.9);
  border: 1px solid rgba(87, 63, 37, 0.1);
}

.game-topbar-copy {
  display: grid;
  gap: 2px;
  text-align: center;
}

.game-topbar-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  color: var(--muted);
}

.game-topbar-copy strong {
  font-size: 0.96rem;
}

.game-topbar-button,
.ghost-button {
  white-space: nowrap;
}

.game-hud {
  gap: 12px;
}

.game-hud-main,
.game-hud-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.game-hud-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.hud-stat {
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(87, 63, 37, 0.08);
}

.hud-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.hud-stat strong {
  display: block;
  font-size: 1.1rem;
  line-height: 1;
}

.chip-status {
  max-width: 100%;
}

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

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

.chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(87, 63, 37, 0.12);
  color: var(--muted);
  font-size: 0.92rem;
}

.staff-stage {
  padding: 18px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(251, 244, 235, 0.82)),
    repeating-linear-gradient(
      135deg,
      rgba(181, 82, 45, 0.04) 0,
      rgba(181, 82, 45, 0.04) 12px,
      transparent 12px,
      transparent 24px
    );
  border: 1px solid rgba(87, 63, 37, 0.1);
}

#staff-svg {
  width: 100%;
  display: block;
}

.timing-caption {
  margin-top: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

.last-note-card,
.feedback-card {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid rgba(87, 63, 37, 0.12);
}

.last-note-card {
  position: relative;
  overflow: hidden;
  background: rgba(255, 250, 244, 0.94);
  box-shadow: 0 16px 30px rgba(70, 43, 19, 0.1);
}

.last-note-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  border-radius: 22px 0 0 22px;
  background: rgba(107, 93, 81, 0.2);
}

.last-note-card.neutral::after {
  background: rgba(107, 93, 81, 0.28);
}

.last-note-card.success {
  background: linear-gradient(135deg, rgba(31, 122, 82, 0.18), rgba(245, 255, 249, 0.96));
  border-color: rgba(31, 122, 82, 0.38);
}

.last-note-card.success::after {
  background: var(--success);
}

.last-note-card.error {
  background: linear-gradient(135deg, rgba(171, 47, 47, 0.18), rgba(255, 247, 247, 0.96));
  border-color: rgba(171, 47, 47, 0.34);
}

.last-note-card.error::after {
  background: var(--danger);
}

.last-note-card h3 {
  margin: 0 0 8px;
  font-size: clamp(1.08rem, 2vw, 1.35rem);
}

.last-note-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.feedback-card.neutral {
  background: rgba(255, 252, 248, 0.88);
}

.feedback-card.success {
  background: rgba(31, 122, 82, 0.12);
  border-color: rgba(31, 122, 82, 0.3);
}

.feedback-card.error {
  background: rgba(171, 47, 47, 0.1);
  border-color: rgba(171, 47, 47, 0.24);
}

.feedback-card h3 {
  margin: 0 0 8px;
}

.feedback-card p:last-child {
  margin-bottom: 0;
}

.answers-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  border-radius: 24px;
  border: 1px solid rgba(87, 63, 37, 0.1);
  background:
    linear-gradient(180deg, rgba(255, 249, 244, 0.96), rgba(248, 238, 226, 0.92)),
    rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 28px rgba(70, 43, 19, 0.08);
}

.answers-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

.answer-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 10px;
}

.answer-button {
  min-height: 68px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(87, 63, 37, 0.12);
  cursor: pointer;
  text-align: center;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 2px;
  box-shadow: 0 8px 18px rgba(70, 43, 19, 0.08);
}

.answer-button strong {
  display: block;
  font-size: 1rem;
  line-height: 1.1;
}

.answer-button span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.answer-button.correct {
  background: rgba(31, 122, 82, 0.14);
  border-color: rgba(31, 122, 82, 0.4);
  box-shadow: 0 0 0 2px rgba(31, 122, 82, 0.14);
}

.answer-button.wrong {
  background: rgba(171, 47, 47, 0.12);
  border-color: rgba(171, 47, 47, 0.34);
  box-shadow: 0 0 0 2px rgba(171, 47, 47, 0.12);
}

.trainer-page.session-active .trainer-hero,
.trainer-page.session-active .level-links-panel,
.trainer-page.session-active .controls-panel {
  display: none;
}

.trainer-page.session-active .app-shell {
  width: min(100%, 860px);
  padding-top: 14px;
}

.trainer-page.session-active .layout {
  grid-template-columns: 1fr;
}

.trainer-page.session-active .play-panel {
  min-height: calc(100svh - 28px);
  gap: 16px;
}

.trainer-page.session-active .game-topbar,
.trainer-page.session-active .game-hud {
  display: grid;
}

.trainer-page.session-active .play-header {
  gap: 10px;
}

.trainer-page.session-active .staff-stage {
  min-height: clamp(240px, 38svh, 420px);
  display: grid;
  align-content: center;
}

.trainer-page.session-active .answers-panel {
  margin-top: auto;
}

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

  .hero {
    flex-direction: column;
  }

  .hero-card {
    width: 100%;
  }
}

small.control-help {
  color: var(--muted);
  line-height: 1.45;
}

.landing-panel,
.info-panel,
.level-links-panel {
  margin-bottom: 22px;
}

.landing-section-head,
.level-links-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.landing-section-copy {
  max-width: 42ch;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.landing-grid,
.info-grid,
.level-links {
  display: grid;
  gap: 14px;
}

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

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

.level-card,
.info-card,
.level-link {
  border-radius: 22px;
  border: 1px solid rgba(87, 63, 37, 0.12);
  background: rgba(255, 255, 255, 0.76);
}

.level-card {
  padding: 18px;
  text-decoration: none;
  color: inherit;
  display: grid;
  gap: 12px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.level-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px rgba(70, 43, 19, 0.12);
  border-color: rgba(181, 82, 45, 0.32);
}

.level-card h3,
.info-card h3 {
  font-size: 1.2rem;
}

.level-card p,
.level-card ul,
.info-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.level-card ul {
  padding-left: 18px;
}

.level-card-step,
.level-card-cta {
  font-weight: 800;
}

.level-card-step {
  color: var(--accent-strong);
}

.level-card-cta {
  color: var(--accent);
}

.info-card {
  padding: 18px;
}

.home-link {
  align-self: center;
  text-decoration: none;
  color: var(--accent-strong);
  font-weight: 700;
}

.level-links {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.level-link {
  padding: 12px 14px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.level-link:hover {
  transform: translateY(-1px);
  border-color: rgba(181, 82, 45, 0.3);
}

.level-link.active {
  background: rgba(181, 82, 45, 0.12);
  border-color: rgba(181, 82, 45, 0.34);
}

.note-map-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  margin-bottom: 22px;
}

.note-map-panel {
  display: grid;
  gap: 18px;
}

.note-map-links {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.note-map-stage {
  padding-bottom: 12px;
}

.note-map-svg {
  width: 100%;
  display: block;
}

.note-color-legend,
.note-map-button-grid {
  display: grid;
  gap: 12px;
}

.note-color-legend {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.note-legend-pill,
.note-map-button {
  border-radius: 20px;
  border: 1px solid rgba(87, 63, 37, 0.12);
  background: linear-gradient(180deg, var(--note-soft), rgba(255, 255, 255, 0.94));
  box-shadow: 0 10px 20px rgba(70, 43, 19, 0.08);
}

.note-legend-pill {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.note-legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--note-color);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.74);
}

.note-legend-pill strong,
.note-map-button strong {
  font-size: 1rem;
}

.note-legend-pill span,
.note-map-button span {
  color: var(--muted);
  font-size: 0.85rem;
}

.note-map-button-grid {
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
}

.note-map-button {
  padding: 12px 10px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  text-align: center;
}

.note-map-button:hover,
.note-map-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(70, 43, 19, 0.12);
}

.note-map-note:focus-visible {
  outline: none;
}

@media (max-width: 980px) {
  .note-map-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1200px);
    padding-top: 20px;
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  }

  .panel {
    padding: 18px;
  }

  .play-header,
  .answers-header,
  .landing-section-head,
  .level-links-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .button-row {
    width: 100%;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
    justify-content: center;
  }

  .staff-stage {
    padding: 14px;
  }

  .timing-caption {
    font-size: 0.9rem;
  }

  .answers-panel {
    position: sticky;
    bottom: 10px;
    z-index: 5;
    margin-top: 4px;
    padding: 14px;
    border-radius: 22px;
    backdrop-filter: blur(16px);
  }

  .answers-header h3 {
    font-size: 1rem;
  }

  #answers-help {
    font-size: 0.92rem;
  }

  .answer-buttons {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .answer-button {
    min-height: 60px;
    padding: 8px 6px;
  }

  .answer-button strong {
    font-size: 0.96rem;
  }

  .answer-button span {
    font-size: 0.72rem;
  }

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

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

  .trainer-page.session-active {
    overflow: hidden;
    background:
      radial-gradient(circle at top center, rgba(255, 255, 255, 0.92), transparent 36%),
      linear-gradient(180deg, #f7efe4 0%, #ecd9bf 100%);
  }

  .trainer-page.session-active .app-shell {
    width: 100%;
    height: 100svh;
    padding: 0;
  }

  .trainer-page.session-active .layout {
    height: 100%;
  }

  .trainer-page.session-active .panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    background: transparent;
    backdrop-filter: blur(0);
  }

  .trainer-page.session-active .play-panel {
    height: 100svh;
    min-height: 100svh;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    gap: 8px;
    padding:
      calc(6px + env(safe-area-inset-top, 0px))
      10px
      calc(10px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }

  .trainer-page.session-active .game-topbar {
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    backdrop-filter: blur(18px);
    box-shadow: 0 8px 20px rgba(70, 43, 19, 0.12);
  }

  .trainer-page.session-active .game-topbar-label {
    font-size: 0.62rem;
  }

  .trainer-page.session-active .game-topbar-copy strong {
    font-size: 0.84rem;
  }

  .trainer-page.session-active .ghost-button,
  .trainer-page.session-active .game-topbar-button {
    width: auto;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .trainer-page.session-active .game-hud {
    gap: 6px;
  }

  .trainer-page.session-active .game-hud-main {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .trainer-page.session-active .game-hud-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .trainer-page.session-active .play-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
  }

  .trainer-page.session-active .play-label,
  .trainer-page.session-active .feedback-label,
  .trainer-page.session-active .answers-header {
    display: none;
  }

  .trainer-page.session-active #round-title {
    font-size: 1rem;
    line-height: 1.05;
  }

  .trainer-page.session-active .chip-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .trainer-page.session-active .chip,
  .trainer-page.session-active .hud-stat {
    background: rgba(255, 252, 247, 0.94);
  }

  .trainer-page.session-active .chip {
    padding: 6px 8px;
    font-size: 0.74rem;
    text-align: center;
  }

  .trainer-page.session-active .hud-stat {
    padding: 8px 6px;
    border-radius: 14px;
    text-align: center;
  }

  .trainer-page.session-active .hud-stat span {
    font-size: 0.64rem;
    margin-bottom: 4px;
  }

  .trainer-page.session-active .hud-stat strong {
    font-size: 0.96rem;
  }

  .trainer-page.session-active .staff-stage {
    min-height: min(28svh, 220px);
    padding: 10px 8px;
    border-radius: 24px;
    box-shadow: 0 12px 24px rgba(70, 43, 19, 0.08);
  }

  .trainer-page.session-active .timing-caption {
    margin-top: 4px;
    font-size: 0.72rem;
    line-height: 1.2;
  }

  .trainer-page.session-active .feedback-card {
    padding: 8px 10px;
    border-radius: 16px;
    background: rgba(255, 252, 248, 0.92);
  }

  .trainer-page.session-active .last-note-card {
    padding: 10px 12px;
    border-radius: 18px;
    background: rgba(255, 252, 247, 0.96);
  }

  .trainer-page.session-active .feedback-card h3 {
    margin: 0;
    font-size: 0.9rem;
  }

  .trainer-page.session-active .last-note-card h3 {
    margin: 0 0 4px;
    font-size: 0.98rem;
  }

  .trainer-page.session-active .last-note-card p:last-child {
    font-size: 0.76rem;
    line-height: 1.25;
  }

  .trainer-page.session-active .feedback-card p:last-child {
    margin-top: 4px;
    font-size: 0.74rem;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .trainer-page.session-active .answers-panel {
    margin: 0;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    border-radius: 18px;
    box-shadow: 0 8px 20px rgba(70, 43, 19, 0.12);
  }

  .trainer-page.session-active .answer-buttons {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
  }

  .trainer-page.session-active .answer-button {
    min-height: 48px;
    padding: 6px 2px;
    border-radius: 14px;
    box-shadow: none;
  }

  .trainer-page.session-active .answer-button strong {
    font-size: 0;
    line-height: 1;
  }

  .trainer-page.session-active .answer-button strong::after {
    content: attr(data-short);
    font-size: 0.72rem;
    line-height: 1;
  }

  .trainer-page.session-active .answer-button span {
    display: none;
  }
}
