:root {
  color-scheme: light;
  --paper: #f8f1e5;
  --paper-2: #fffaf1;
  --ink: #332c29;
  --muted: #7e746d;
  --terracotta: #d96a4b;
  --terracotta-dark: #b94f39;
  --sage: #7d9261;
  --rose: #dba09e;
  --gold: #efb83c;
  --line: rgba(82, 65, 55, .14);
  --shadow: 0 18px 60px rgba(91, 66, 46, .12);
  font-family: ui-rounded, "Avenir Next", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }
body { min-height: 100dvh; overflow-x: hidden; }
button { font: inherit; }
button:focus-visible { outline: 4px solid rgba(217, 106, 75, .25); outline-offset: 3px; }
[hidden] { display: none !important; }
.screen { min-height: 100dvh; padding: max(24px, env(safe-area-inset-top)) max(32px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(32px, env(safe-area-inset-left)); }
.brand { margin: 0 0 12px; font-size: clamp(24px, 3vw, 42px); font-weight: 850; font-style: italic; letter-spacing: -.04em; }
.eyebrow { color: var(--terracotta-dark); font-size: 13px; font-weight: 850; letter-spacing: .15em; }
.subtitle, .progress-copy { color: var(--muted); }

.home-screen { max-width: 1240px; margin: auto; display: grid; align-content: center; gap: clamp(28px, 5vh, 58px); }
.home-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 30px; }
.home-header h1, .complete-screen h1 { margin: 0; font-size: clamp(34px, 5vw, 68px); letter-spacing: -.045em; }
.home-header .subtitle { margin: 12px 0 0; font-size: clamp(16px, 2vw, 22px); }
.today-pill, .mentor-status { padding: 11px 18px; background: rgba(255,255,255,.7); border: 1px solid var(--line); border-radius: 999px; font-weight: 750; box-shadow: 0 8px 28px rgba(80, 57, 43, .06); }
.stage-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(16px, 2.5vw, 30px); }
.stage-card { min-height: 210px; padding: 28px; background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 30px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: space-between; }
.stage-card:nth-child(2) .stage-badge { background: var(--rose); }
.stage-card:nth-child(3) .stage-badge { background: var(--sage); }
.stage-badge { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: white; background: var(--terracotta); font-weight: 900; }
.stage-card h2 { margin: 10px 0 4px; font-size: clamp(22px, 2.5vw, 32px); }
.stage-card p { margin: 0; color: var(--muted); }
.stage-card small { color: var(--sage); font-weight: 800; }
.home-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.home-actions { display: flex; align-items: center; gap: 12px; }
.primary-button, .secondary-button { min-height: 54px; padding: 14px 28px; border: 0; border-radius: 999px; font-weight: 850; cursor: pointer; }
.primary-button { color: white; background: var(--terracotta); box-shadow: 0 12px 30px rgba(185, 79, 57, .25); }
.primary-button:hover { background: var(--terracotta-dark); transform: translateY(-1px); }
.secondary-button { color: var(--ink); background: rgba(255,255,255,.76); border: 1px solid var(--line); }

.practice-screen { display: grid; grid-template-rows: auto 1fr; gap: 18px; background: radial-gradient(circle at 20% 30%, #fff8df 0, transparent 32%), var(--paper); }
.practice-header { max-width: 1380px; width: 100%; margin: auto; display: grid; grid-template-columns: 54px 1fr 120px; align-items: center; gap: 22px; }
.icon-button { width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.8); font-size: 25px; cursor: pointer; }
.stage-progress { display: flex; align-items: center; gap: 14px; color: var(--muted); font-weight: 800; }
.progress-track { flex: 1; height: 9px; overflow: hidden; background: rgba(76,59,50,.1); border-radius: 99px; }
.progress-track i { display: block; width: 33%; height: 100%; background: var(--terracotta); border-radius: inherit; transition: width .5s ease; }
.mini-stars { color: var(--gold); text-align: right; font-size: 25px; letter-spacing: 4px; }
.practice-layout { max-width: 1380px; min-height: 0; width: 100%; margin: auto; display: grid; grid-template-columns: minmax(380px, .9fr) minmax(450px, 1.1fr); gap: clamp(28px, 5vw, 80px); align-items: center; }
.mentor-panel { position: relative; display: grid; justify-items: center; align-content: center; min-height: 0; }
.mentor-aura { position: absolute; width: 72%; aspect-ratio: 1; background: rgba(217,106,75,.13); filter: blur(1px); border-radius: 50%; animation: aura 3s ease-in-out infinite; }
.mentor { position: relative; width: min(100%, 470px); aspect-ratio: 760 / 930; overflow: hidden; border: 7px solid rgba(255,255,255,.76); border-radius: 44% 44% 32% 32% / 28% 28% 18% 18%; transform-origin: 50% 90%; animation: breathe 4.8s ease-in-out infinite; filter: drop-shadow(0 22px 30px rgba(86,55,39,.16)); }
.mentor img { display: block; width: 100%; height: 100%; object-fit: cover; }
.mentor-status { position: absolute; left: 14%; top: 10%; z-index: 4; display: flex; gap: 9px; align-items: center; font-size: 14px; background: rgba(255,255,255,.94); }
.mentor-status i { width: 10px; height: 10px; border-radius: 50%; background: var(--sage); }
.mentor[data-state="speaking"] .mentor-status i { background: var(--terracotta); animation: pulse 1s infinite; }
.mentor[data-state="listening"] { animation: listen 1.4s ease-in-out infinite; }
.photo-mouth { position: absolute; left: 61.6%; top: 40.4%; width: 8.5%; height: 2.3%; border: 3px solid rgba(242,174,137,.9); border-radius: 50%; background: #8c3f35; transform: translate(-50%, -50%); transition: width .08s linear, height .08s linear; }
.mentor[data-mouth="0"] .photo-mouth { width: 8%; height: 1.4%; background: #a54c3d; }
.mentor[data-mouth="1"] .photo-mouth { width: 9%; height: 2.5%; }
.mentor[data-mouth="2"] .photo-mouth { width: 8%; height: 4%; background: #6f302d; }
.mentor[data-mouth="3"] .photo-mouth { width: 6.5%; height: 5.5%; background: #642b2a; }
.blink-lid { position: absolute; top: 30.5%; width: 6.5%; height: 1.2%; border-radius: 50%; background: #7c503d; transform: scaleY(0); transform-origin: center; animation: blink-photo 5.7s infinite; }
.blink-left { left: 47.2%; transform: rotate(4deg) scaleY(0); }
.blink-right { left: 61.4%; transform: rotate(-3deg) scaleY(0); }
.conversation-panel { padding: clamp(28px, 4vw, 58px); border: 1px solid rgba(104,81,64,.12); border-radius: 44px; background: rgba(255,250,242,.82); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.conversation-panel h2 { margin: 12px 0 18px; font-size: clamp(38px, 5vw, 72px); line-height: 1.03; letter-spacing: -.045em; }
.prompt { margin: 0 0 26px; color: var(--sage); font-size: clamp(20px, 2.3vw, 30px); font-weight: 700; }
.heard-card { margin: 16px 0; padding: 16px 20px; border-left: 5px solid var(--sage); border-radius: 14px; background: white; }
.heard-card span { color: var(--muted); margin-right: 8px; }
.message { min-height: 50px; color: var(--terracotta-dark); font-weight: 750; line-height: 1.45; }
.action-area { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.mic-button { min-width: 260px; min-height: 78px; padding: 12px 26px; display: inline-flex; align-items: center; justify-content: center; gap: 14px; color: white; border: 0; border-radius: 999px; background: var(--terracotta); box-shadow: 0 0 0 10px rgba(217,106,75,.1), 0 16px 32px rgba(185,79,57,.28); font-weight: 900; font-size: 18px; cursor: pointer; }
.mic-button.listening { background: var(--sage); animation: pulse-button 1.2s infinite; }
.mic-icon { width: 25px; height: 25px; border: 4px solid currentColor; border-radius: 50%; font-size: 0; }
.test-controls { margin-top: 24px; padding: 12px; border: 1px dashed var(--rose); border-radius: 14px; }
.test-controls button { margin: 4px; }

.result-dialog { width: min(480px, calc(100% - 32px)); padding: 36px; text-align: center; border: 1px solid var(--line); border-radius: 30px; box-shadow: 0 30px 100px rgba(62,42,30,.28); background: var(--paper-2); }
.result-dialog::backdrop { background: rgba(62,45,36,.34); backdrop-filter: blur(5px); }
.result-star { color: var(--gold); font-size: 70px; animation: pop .6s both; }
.result-dialog h2 { margin: 8px 0; font-size: 38px; }
.result-dialog p:not(.eyebrow) { color: var(--muted); }
.complete-screen { display: grid; place-content: center; justify-items: center; text-align: center; gap: 12px; }
.complete-screen > p { margin: 0; }
.big-stars { margin: 20px; color: var(--gold); font-size: clamp(58px, 9vw, 100px); letter-spacing: 12px; animation: pop .7s both; }
.summary-list { width: min(700px, 92vw); padding: 24px 30px; display: grid; gap: 14px; text-align: left; background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 26px; }
.summary-row { display: grid; grid-template-columns: 1fr auto; gap: 20px; }
.summary-row span { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(620px, calc(100% - 32px)); padding: 14px 20px; color: white; background: #4a403b; border-radius: 14px; box-shadow: var(--shadow); z-index: 20; }

.library-dialog { width: min(920px, calc(100% - 32px)); max-height: min(820px, calc(100dvh - 32px)); padding: 30px; overflow: auto; border: 1px solid var(--line); border-radius: 30px; background: var(--paper-2); box-shadow: 0 30px 100px rgba(62,42,30,.28); }
.plans-dialog { width: min(720px, calc(100% - 32px)); padding: 30px; border: 1px solid var(--line); border-radius: 30px; background: var(--paper-2); box-shadow: 0 30px 100px rgba(62,42,30,.28); }
.library-dialog::backdrop, .plans-dialog::backdrop { background: rgba(62,45,36,.34); backdrop-filter: blur(5px); }
.library-header, .library-section, .sentence-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.library-header h2 { margin: 5px 0 0; font-size: 34px; }
.privacy-note { padding: 14px 18px; color: #5d6e47; background: rgba(125,146,97,.12); border-radius: 14px; line-height: 1.5; }
.library-section { margin: 22px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.library-section h3, .sentence-heading h3 { margin: 0 0 5px; }
.library-section p { margin: 0; color: var(--muted); font-size: 14px; }
.upload-button { min-height: 50px; padding: 13px 20px; flex: 0 0 auto; color: white; background: var(--terracotta); border-radius: 999px; font-weight: 850; cursor: pointer; }
.upload-button.subtle { color: var(--ink); background: white; border: 1px solid var(--line); }
.upload-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.material-list, .sentence-list { display: grid; gap: 8px; }
.material-row, .sentence-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 11px 14px; background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 14px; }
.material-row img { width: 54px; height: 42px; object-fit: cover; border-radius: 8px; }
.material-row small, .sentence-row small { color: var(--muted); }
.material-row button { border: 0; color: var(--terracotta-dark); background: transparent; cursor: pointer; }
.sentence-heading { margin: 24px 0 10px; }
.sentence-heading span { color: var(--sage); font-weight: 800; }
.sentence-row { grid-template-columns: 1fr auto; }
.plan-list { margin-top: 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.plan-card { min-height: 132px; padding: 18px; display: grid; align-content: space-between; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.76); }
.plan-card strong { color: var(--sage); }
.plan-card b { font-size: 30px; }
.plan-card small, .plans-footnote { color: var(--muted); }
.plans-footnote { margin: 18px 0 0; line-height: 1.55; }

@keyframes breathe { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-5px) scale(1.006); } }
@keyframes aura { 50% { transform: scale(1.06); opacity: .72; } }
@keyframes blink { 0%, 46%, 50%, 100% { transform: scaleY(1); } 48% { transform: scaleY(.08); } }
@keyframes blink-photo { 0%, 46%, 50%, 100% { transform: scaleY(0); } 48% { transform: scaleY(1); } }
@keyframes pulse { 50% { transform: scale(1.45); opacity: .55; } }
@keyframes pulse-button { 50% { box-shadow: 0 0 0 18px rgba(125,146,97,.13), 0 16px 32px rgba(93,112,70,.25); } }
@keyframes listen { 50% { transform: rotate(-.7deg) translateY(-3px); } }
@keyframes pop { from { opacity: 0; transform: scale(.45) rotate(-8deg); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 900px), (orientation: portrait) {
  .screen { padding: 20px; }
  .stage-cards { grid-template-columns: 1fr; }
  .stage-card { min-height: 140px; }
  .practice-layout { grid-template-columns: .8fr 1.2fr; gap: 18px; }
  .conversation-panel { padding: 26px; border-radius: 28px; }
  .mentor-status { left: 13%; top: 9%; }
  .mentor { max-height: 53dvh; width: auto; }
}

@media (max-height: 850px) and (orientation: landscape) {
  .home-screen { gap: 22px; }
  .stage-card { min-height: 170px; padding: 22px; }
  .mentor { max-height: 64dvh; width: auto; }
}

@media (max-width: 700px) {
  .practice-layout { grid-template-columns: 1fr; }
  .mentor-panel { display: none; }
  .practice-header { grid-template-columns: 48px 1fr; }
  .mini-stars { display: none; }
  .home-footer { align-items: stretch; flex-direction: column; }
  .home-actions, .library-section { align-items: stretch; flex-direction: column; }
  .home-actions > * { width: 100%; }
  .plan-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
