:root {
  --bg: #ffffff;
  --ink: #17202a;
  --muted: #637083;
  --line: #dbe3ee;
  --blue: #d9ecff;
  --blue-strong: #2a7ccf;
  --blue-deep: #0f63c8;
  --green: #dcf4e8;
  --green-strong: #18875a;
  --green-deep: #0f7a4f;
  --orange: #ffedd7;
  --orange-strong: #c46b1d;
  --orange-deep: #d95f02;
  --red: #df3b36;
  --yellow: #ffe66b;
  --shadow: 0 16px 40px rgba(39, 55, 77, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(18px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.15;
}

.brand small {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.support-link,
.ghost-button,
.home-button,
.pinyin-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: #405062;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
}

.support-link {
  min-width: 112px;
  padding-inline: 16px;
  color: var(--blue-deep);
  border-color: #b9d7ff;
  background: #f4f9ff;
}

.youtube-link {
  color: #c91d2a;
  border-color: #ffc5cc;
  background: #fff4f5;
}

.resources-link {
  color: var(--blue-deep);
  border-color: #b9d7ff;
  background: #f4f9ff;
}

.tools-link {
  color: var(--green-deep);
  border-color: #bce8cf;
  background: #f3fcf7;
}

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

.access-screen {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  padding: 36px 0;
}

.access-card {
  width: min(480px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  text-align: center;
}

.access-logo {
  width: 88px;
  height: 88px;
  border-radius: 8px;
  object-fit: cover;
}

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

.access-card h1,
.intro h1 {
  margin-bottom: 10px;
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  line-height: 1.12;
}

.access-card p,
.intro p {
  color: var(--muted);
  line-height: 1.6;
}

.access-form {
  display: grid;
  gap: 10px;
  margin-top: 24px;
  text-align: left;
}

label {
  color: #344256;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 15px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
  line-height: 1.7;
}

button[type="submit"],
.controls button,
.access-form button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--blue-deep);
  color: white;
  font-weight: 850;
  padding: 12px 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-screen {
  padding: 34px 0 58px;
}

.intro,
.practice-topline,
.report-header,
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.practice-topline {
  justify-content: space-between;
  position: sticky;
  top: 72px;
  z-index: 12;
  padding: 12px 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.practice-topline > div {
  width: 100%;
}

.home-button {
  background: #eff6ff;
  border-color: #a9ccff;
  color: var(--blue-deep);
  font-weight: 850;
  box-shadow: 0 8px 18px rgba(42, 124, 207, 0.14);
  margin-top: 8px;
}

.home-view {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 26px;
}

.mode-card {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 24px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  box-shadow: 0 12px 28px rgba(31, 45, 61, 0.08);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.mode-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(31, 45, 61, 0.12);
}

.mode-card strong {
  font-size: 1.35rem;
}

.mode-card span,
.mode-card small {
  line-height: 1.5;
}

.mode-card small {
  color: #38485b;
  font-size: 0.98rem;
}

.mode-blue {
  background: var(--blue);
}

.mode-green {
  background: var(--green);
}

.mode-orange {
  background: var(--orange);
}

.mode-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(39, 55, 77, 0.12);
}

.mode-icon svg {
  width: 36px;
  height: 36px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mode-pencil {
  color: var(--blue-deep);
}

.mode-video {
  color: var(--green-deep);
}

.mode-book {
  color: var(--orange-deep);
}

.practice-view {
  display: grid;
  gap: 18px;
  margin-top: 24px;
}

.panel,
.reading-panel,
.recorder-panel,
.report-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: white;
  box-shadow: 0 10px 24px rgba(31, 45, 61, 0.06);
}

.recorder-panel {
  border-color: #c9d8ee;
  background: #fbfdff;
  box-shadow: 0 12px 28px rgba(31, 45, 61, 0.1);
}

.mode-hint {
  margin-bottom: 14px;
  color: #405062;
  line-height: 1.55;
  font-size: 0.94rem;
  white-space: pre-line;
}

.limit-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.limit-row .over-limit {
  color: #b42318;
  font-weight: 850;
}

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

.segment {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: #38485b;
  font-weight: 800;
}

.segment span {
  font-weight: 650;
  color: var(--muted);
  font-size: 0.85rem;
}

.segment.active {
  border-color: #111827;
  background: #111827;
  color: white;
}

.segment.active span {
  color: rgba(255, 255, 255, 0.78);
}

.select-label {
  display: block;
  margin-top: 16px;
}

.select-trigger {
  width: 100%;
  min-height: 64px;
  margin-top: 10px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  color: var(--ink);
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(15, 99, 200, 0.02);
}

.select-trigger span,
.select-trigger small {
  display: block;
}

.select-trigger span {
  font-weight: 850;
  line-height: 1.25;
}

.select-trigger small {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 700;
}

.select-trigger:hover {
  border-color: #9bc5fb;
  background: #f2f8ff;
}

.select-trigger::after {
  content: "v";
  float: right;
  margin-top: -32px;
  color: var(--blue-deep);
  font-size: 1.2rem;
  font-weight: 900;
}

.material-layout {
  display: grid;
  gap: 18px;
}

.video-frame {
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #101820;
}

.video-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.reading-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.pinyin-toggle {
  flex: 0 0 auto;
  color: var(--orange-deep);
  border-color: #ffd0a6;
  background: #fff7ed;
}

.pinyin-toggle[aria-pressed="false"] {
  color: #536174;
  border-color: var(--line);
  background: #f8fafc;
}

.reading-heading p {
  color: var(--muted);
  margin: 0;
}

.reading-text {
  white-space: pre-wrap;
  font-size: 1.16rem;
  line-height: 2;
}

.ruby-reading {
  white-space: normal;
  font-size: 1.28rem;
  line-height: 3.1;
  letter-spacing: 0;
}

.ruby-reading ruby {
  display: inline-flex;
  flex-direction: column-reverse;
  align-items: center;
  min-width: 1.7em;
  margin: 0 0.08em;
  vertical-align: bottom;
}

.ruby-reading rt {
  color: var(--blue-deep);
  font-size: 0.55em;
  font-weight: 750;
  line-height: 1.1;
  text-align: center;
}

.ruby-reading .punctuation {
  display: inline-block;
  margin: 0 0.12em;
}

.status-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  font-weight: 850;
  background: #eef2f7;
  color: #344256;
}

.status-pill.recording {
  background: #e7f8ef;
  color: var(--green-strong);
}

.status-pill.paused {
  background: #fff2db;
  color: var(--orange-strong);
}

.status-pill.assessing {
  background: #e6efff;
  color: var(--blue-strong);
}

.timer {
  display: block;
  margin-top: 8px;
  font-size: 2.1rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.timer-green {
  color: var(--green-strong);
}

.timer-orange {
  color: var(--orange-strong);
}

.timer-red {
  color: #c83333;
}

#privacyNotice {
  max-width: 440px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.92rem;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.controls #startBtn {
  background: var(--blue-deep);
}

.controls #pauseBtn {
  background: var(--orange-deep);
}

.controls #resumeBtn {
  background: var(--green-deep);
}

.controls #stopBtn {
  background: var(--red);
}

.controls .secondary-button {
  background: white;
  color: #111827;
  border: 1px solid var(--line);
}

.message {
  min-height: 24px;
  margin: 12px 0 0;
  color: #b42318;
  line-height: 1.5;
  font-weight: 700;
}

.message.ok {
  color: var(--green-strong);
}

.countdown {
  position: fixed;
  left: 50%;
  top: 104px;
  z-index: 50;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.countdown-ring {
  display: grid;
  place-items: center;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: conic-gradient(var(--blue-deep) 0deg, var(--blue-deep) 250deg, #e8edf5 250deg);
  box-shadow: 0 16px 36px rgba(15, 99, 200, 0.2);
}

.countdown-ring span {
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: white;
  color: var(--blue-deep);
  font-size: clamp(1.45rem, 2vw, 2.1rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.05;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.42);
}

.dialog-panel {
  width: min(620px, 100%);
  max-height: min(680px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-radius: 8px;
  background: white;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin-bottom: 4px;
}

.dialog-header p {
  margin: 0;
  color: var(--muted);
}

.dialog-close {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #1f2937;
  font-size: 1.4rem;
  line-height: 1;
}

.dialog-tabs {
  padding: 14px 20px 0;
}

.dialog-list {
  display: grid;
  gap: 10px;
  padding: 16px 20px 20px;
  overflow-y: auto;
}

.dialog-item {
  width: 100%;
  min-height: 78px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  text-align: left;
}

.dialog-item:hover {
  border-color: #9bc5fb;
  background: #f7fbff;
}

.dialog-item strong,
.dialog-item span {
  display: block;
}

.dialog-item strong {
  line-height: 1.35;
}

.dialog-item span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.dialog-item.active {
  border-color: #111827;
  box-shadow: inset 0 0 0 1px #111827;
}

.report-panel {
  border-color: #cfd9e6;
}

.small .segment {
  min-height: 38px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 18px 0;
}

.score-grid-overall {
  grid-template-columns: minmax(180px, 260px);
}

.score-grid-compact {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
}

.score {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fafcff;
}

.score strong {
  display: block;
  font-size: 1.55rem;
}

.score span {
  color: var(--muted);
  font-size: 0.88rem;
}

.performance-block {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.performance-block h4 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.report-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.report-metrics p,
.pronunciation-practice p,
.advice-text p {
  margin-bottom: 8px;
  line-height: 1.6;
}

.pronunciation-practice {
  margin: 10px 0;
}

.pronunciation-practice ol {
  margin: 8px 0 0;
}

.report-meta {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #d8e7f8;
  border-radius: 8px;
  background: #f7fbff;
}

.report-meta h3 {
  margin-bottom: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: minmax(140px, 0.35fr) minmax(0, 1fr);
  gap: 10px;
}

.meta-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
}

.meta-grid strong,
.meta-grid span {
  display: block;
}

.meta-grid strong {
  line-height: 1.5;
}

.meta-grid span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.report-section {
  margin-top: 16px;
}

.report-section h3 {
  margin-bottom: 8px;
}

.report-section li {
  margin-bottom: 8px;
  line-height: 1.55;
}

.report-note {
  border-top: 1px solid var(--line);
  margin: 20px 0 0;
  padding-top: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.guided-note {
  border-top: 0;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff8df;
  color: #6b5200;
}

@media (max-width: 820px) {
  .site-header,
  .intro,
  .practice-topline,
  .status-row,
  .report-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .home-view,
  .score-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .mode-card {
    min-height: 190px;
  }

  .access-card {
    padding: 24px;
  }

  .brand-logo {
    width: 38px;
    height: 38px;
  }

  .limit-row {
    flex-direction: column;
  }

  .controls button {
    width: 100%;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
  }

  .support-link {
    min-width: 0;
    width: 100%;
    padding-inline: 8px;
  }

  .reading-heading {
    flex-direction: column;
  }

  .pinyin-toggle {
    width: 100%;
  }

  .ruby-reading {
    font-size: 1.16rem;
    line-height: 3;
  }

  .countdown {
    top: 84px;
  }

  .recorder-panel {
    padding: 14px;
  }

  .recorder-panel .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .recorder-panel .controls button {
    min-height: 44px;
    padding: 10px 12px;
  }

  .recorder-panel #restartBtn {
    grid-column: 1 / -1;
  }

  .recorder-panel .status-row {
    gap: 10px;
  }

  #privacyNotice {
    font-size: 0.82rem;
  }

  .dialog-backdrop {
    align-items: end;
    padding: 10px;
  }

  .dialog-panel {
    max-height: calc(100vh - 20px);
  }

  .dialog-header,
  .dialog-tabs,
  .dialog-list {
    padding-left: 14px;
    padding-right: 14px;
  }
}
