:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1f2933; --muted: #66727d;
  --line: #e3e7eb; --line-strong: #c5ced6;
  --accent: #2f5f84; --accent-hover: #244b69; --accent-soft: #eaf1f7;
  --success: #2b7a4b; --success-soft: #e4f3ea;
  --warning: #9a6200; --warning-soft: #fdf3e1;
  --danger: #b3261e; --danger-soft: #fdeeed;
  --radius: 10px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(16 24 40 / .05);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .5; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden, .speaker-name, .topic-card input { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.app-header { width: 100%; max-width: 848px; margin: 0 auto; padding: 10px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.brand { display: inline-flex; align-items: center; min-height: 44px; color: inherit; font-size: 17px; font-weight: 700; text-decoration: none; }
.test-badge { padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.language-switch { margin-left: auto; }
.header-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.language-switch select { min-height: 44px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; }
.language-switch select:hover, .language-switch select:focus-visible { border-color: var(--line-strong); background: var(--surface); color: var(--text); }
.icon-link { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid transparent; border-radius: var(--radius-sm); background: none; color: var(--muted); flex-shrink: 0; }
.icon-link:hover, .icon-link:focus-visible { border-color: var(--line-strong); background: var(--surface); color: var(--text); }
main { max-width: 848px; margin: 0 auto; padding: 8px 24px 32px; }
h1 { font-size: 22px; line-height: 1.5; font-weight: 700; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600; line-height: 1.3; transition: background-color .15s, border-color .15s, color .15s; }
.primary { background: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.error { margin: 0 0 16px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.record-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }

.topic-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.topic-grid > p { grid-column: 1 / -1; color: var(--muted); }
.topic-card { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 16px 48px 18px 18px; background: var(--surface); border-radius: var(--radius); box-shadow: inset 0 0 0 1px var(--line), var(--shadow); cursor: pointer; transition: box-shadow .15s, background-color .15s; }
.topic-card::after { content: ""; position: absolute; top: 16px; right: 16px; width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.topic-card:hover { box-shadow: inset 0 0 0 1px var(--line-strong), var(--shadow); }
.topic-card:has(input:checked) { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.topic-card:has(input:checked)::after { background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12 4 4 8-8'/%3E%3C/svg%3E") center / 14px no-repeat; box-shadow: none; }
.topic-card:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.topic-title { font-size: 16px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.topic-description { color: var(--muted); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.topic-card:has(input:checked) .topic-description { color: #4b5763; }
.start-row { position: sticky; bottom: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 24px 0 12px; background: linear-gradient(transparent, var(--bg) 20px); }
.start-row .button { min-height: 48px; padding: 0 24px; font-size: 16px; }
.session-note { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.session-note svg { width: 18px; height: 18px; }
.setup-footer { display: flex; flex-wrap: wrap; gap: 4px 20px; padding-top: 8px; color: var(--muted); font-size: 13px; }
.setup-footer > span { display: inline-flex; align-items: center; gap: 6px; }
.setup-footer svg { width: 16px; height: 16px; }
.teacher-link { margin-left: auto; color: var(--muted); }
.teacher-link:hover { color: var(--accent); }

.login-view { max-width: 400px; padding-top: max(24px, 10vh); }
.login-form { display: grid; gap: 12px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-form .error { margin: 0; }
.login-form input { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font-size: 16px; }
.login-form input:focus-visible { outline-offset: 0; }
.login-form .button { min-height: 48px; margin-top: 4px; font-size: 16px; }

body:has(#conversation-view:not([hidden])) { display: flex; flex-direction: column; height: 100dvh; }
body:has(#conversation-view:not([hidden])) main { display: flex; flex: 1; min-height: 0; width: 100%; }
.conversation-view { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.conversation-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 16px; margin-bottom: 12px; }
.conversation-heading h1 { min-width: 0; font-size: 20px; overflow-wrap: anywhere; }
.timer { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.timer .record-dot { margin-right: 2px; animation: pulse 2s ease-in-out infinite; }
.transcript-panel { display: flex; flex-direction: column; flex: 1; min-height: 280px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.transcript-scroll { position: relative; flex: 1; min-height: 0; padding: 20px; overflow-y: auto; overscroll-behavior: contain; }
#log { display: flex; flex-direction: column; gap: 12px; }
.message { display: flex; }
.message.student { justify-content: flex-end; }
.avatar { display: none; }
.message-content { min-width: 0; max-width: 80%; }
.bubble { padding: 10px 14px; border-radius: 16px 16px 16px 4px; background: #f1f3f5; font-size: 16px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.student .bubble { border-radius: 16px 16px 4px 16px; background: var(--accent-soft); }
.bubble.pending:empty::after, .review-state[data-state=loading]::before { content: ""; display: block; width: 6px; height: 6px; margin: 10px 20px 11px 0; border-radius: 50%; color: #9aa5af; background: currentColor; box-shadow: 10px 0 currentColor, 20px 0 currentColor; animation: typing 1.2s infinite; }
.interim { width: fit-content; max-width: 80%; margin: 12px 0 0 auto; padding: 9px 13px; border: 1px dashed var(--line-strong); border-radius: 16px 16px 4px 16px; color: var(--muted); font-size: 16px; line-height: 1.7; overflow-wrap: anywhere; }
.voice-panel { display: flex; align-items: center; gap: 16px; margin-top: 12px; padding: 12px 12px 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.orb { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--muted); color: #fff; flex-shrink: 0; transition: background-color .2s, box-shadow .1s linear; }
.orb svg { grid-area: 1 / 1; width: 22px; height: 22px; stroke-width: 2; }
.orb-wave, [data-state=thinking] .orb-mic, [data-state=speaking] .orb-mic { display: none; }
[data-state=thinking] .orb-wave, [data-state=speaking] .orb-wave { display: block; }
[data-state=connecting] .orb { animation: pulse 1.6s ease-in-out infinite; }
[data-state=listening] .orb { background: var(--accent); box-shadow: 0 0 0 calc(var(--level, 0) * 10px) rgb(47 95 132 / .2); }
[data-state=thinking] .orb { background: var(--warning); animation: ripple 1.4s ease-out infinite; }
[data-state=speaking] .orb { background: var(--success); }
[data-state=speaking] .orb-wave { animation: wave .9s ease-in-out infinite; }
.voice-caption { flex: 1; min-width: 0; }
#status { font-size: 17px; font-weight: 600; line-height: 1.4; }
#state-hint { display: none; margin-top: 2px; color: var(--muted); font-size: 14px; line-height: 1.5; }
[data-state=connecting] #state-hint { display: block; }
.stop-button { flex-shrink: 0; padding: 0 16px; background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.stop-button:hover { background: var(--danger-soft); border-color: #efc3bf; color: var(--danger); }
.stop-square { width: 10px; height: 10px; border-radius: 2px; background: currentColor; }

.end-view { max-width: 720px; margin: 24px auto 0; padding: 32px 24px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
.end-icon { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.end-icon svg { width: 28px; height: 28px; stroke-width: 2.2; }
.session-summary { display: flex; justify-content: center; gap: 48px; margin: 20px 0 28px; }
.session-summary > div { display: flex; flex-direction: column-reverse; }
.session-summary > div > span { color: var(--muted); font-size: 13px; }
.session-summary strong { font-size: 28px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.session-summary small { margin-left: 4px; color: var(--muted); font-size: 14px; font-weight: 400; }
.end-view .error { text-align: left; }
.end-view .button { width: 100%; min-height: 48px; font-size: 16px; }
.session-reference { margin-top: 16px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.review { margin-bottom: 28px; text-align: left; }
.review-state { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 14px; }
.review-state[data-state=error] { color: var(--danger); }
.end-view .review-retry { width: auto; min-height: 44px; padding: 0 12px; background: var(--accent-soft); color: var(--accent); font-size: 14px; }
.feedback-content { display: grid; gap: 16px; text-align: left; overflow-wrap: anywhere; }
.feedback-content:empty { display: none; }
.feedback-overall { font-size: 17px; line-height: 1.8; }
.feedback-content ul { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.feedback-content li, .feedback-suggestion { display: flex; gap: 10px; align-items: flex-start; }
.feedback-icon { width: 18px; height: 18px; margin-top: 3px; stroke-width: 2.2; }
.feedback-strengths .feedback-icon { color: var(--success); }
.feedback-advice .feedback-icon, .feedback-suggestion .feedback-icon { color: var(--accent); }
.feedback-improvements { display: grid; gap: 8px; }
.feedback-improvement { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--bg); }
.feedback-original { color: var(--muted); font-size: 14px; text-decoration: line-through; text-decoration-color: var(--line-strong); }
.feedback-suggestion { color: var(--accent); font-weight: 600; }
.feedback-note { margin-top: 4px; color: var(--muted); font-size: 13px; }
.review-transcript { margin-top: 20px; border-top: 1px solid var(--line); }
.review-transcript summary { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; list-style: none; }
.review-transcript summary::-webkit-details-marker { display: none; }
.review-transcript summary::before { content: ""; width: 7px; height: 7px; margin: 0 2px; border-right: 1.7px solid; border-bottom: 1.7px solid; transform: rotate(-45deg); transition: transform .15s; }
.review-transcript[open] summary::before { transform: rotate(45deg); }
.review-transcript summary:hover { color: var(--text); }
#review-log { display: flex; flex-direction: column; gap: 12px; padding: 4px 0 8px; }
#review-log .bubble { font-size: 15px; }

@keyframes pulse { 50% { opacity: .45; } }
@keyframes ripple { from { box-shadow: 0 0 0 0 rgb(154 98 0 / .35); } to { box-shadow: 0 0 0 12px rgb(154 98 0 / 0); } }
@keyframes wave { 50% { transform: scaleY(.6); } }
@keyframes typing {
  0%, 100% { background: var(--muted); box-shadow: 10px 0 var(--line-strong), 20px 0 var(--line-strong); }
  33% { background: var(--line-strong); box-shadow: 10px 0 var(--muted), 20px 0 var(--line-strong); }
  66% { background: var(--line-strong); box-shadow: 10px 0 var(--line-strong), 20px 0 var(--muted); }
}
@media (max-width: 600px) {
  .app-header { padding: 10px 16px; }
  main { padding: 4px 16px 16px; }
  .transcript-scroll { padding: 16px 12px; }
  .message-content, .interim { max-width: 88%; }
  .voice-panel { position: sticky; bottom: 8px; gap: 8px; padding: 10px 10px 10px 14px; box-shadow: 0 4px 16px rgb(16 24 40 / .1); }
  #status { font-size: 16px; }
  .stop-button { gap: 6px; padding: 0 12px; font-size: 14px; }
  .end-view { margin-top: 8px; padding: 28px 20px 20px; }
  .login-form { padding: 20px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation: none !important; transition: none !important; }
}
