:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --ink: #1f2430;
  --ink-2: #4a5160;
  --muted: #7b8291;
  --line: #e4dfd6;
  --accent: #3b4a7a;
  --accent-2: #5a6cae;
  --accent-soft: #e9ecf7;
  --hl: #fff4c7;
  --hl-line: #f0c94a;
  --good: #2f7d5b;
  --warn: #b5562f;
  --danger: #c0392b;
  --user: #e7f0ff;
  --ai: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 6px 20px rgba(20, 24, 40, .06);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c; --panel: #1e2128; --ink: #eceef3; --ink-2: #c3c8d3; --muted: #8b92a1; --line: #2e323c;
    --accent: #8ea2e8; --accent-2: #a9b8f0; --accent-soft: #262c40; --hl: #3a3420; --hl-line: #c9a53a;
    --user: #22304a; --ai: #1e2128; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.6;
  display: grid; grid-template-rows: auto auto 1fr auto; height: 100vh; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 14px; transition: background .15s, border-color .15s, transform .05s; }
button:hover:not(:disabled) { border-color: var(--accent-2); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-2); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); font-weight: 600; }
button.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button.big { padding: 11px 28px; font-size: 16px; }
.danger-text { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 13px; }
.lesson-status { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: center; min-width: 0; }
.phase-chip { background: var(--accent-soft); color: var(--accent); padding: 3px 12px; border-radius: 99px; font-weight: 700; font-size: 13.5px; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; letter-spacing: .02em; }
.timer-total { color: var(--muted); font-variant-numeric: tabular-nums; }
.phase-bar { display: flex; gap: 3px; width: min(320px, 30vw); height: 8px; }
.phase-bar span { position: relative; background: var(--line); border-radius: 4px; overflow: hidden; }
.phase-bar span i { position: absolute; inset: 0; width: 0; background: var(--accent); border-radius: 4px; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.api-count { font-size: 12.5px; color: var(--muted); padding: 2px 8px; border: 1px solid var(--line); border-radius: 99px; white-space: nowrap; }

.banner { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 10px 16px; background: #fff3dc; color: #6b4a10; border-bottom: 1px solid #f1d9a6; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3a2f17; color: #f4dca6; border-color: #5c4a22; } }

/* lesson layout */
.lesson { display: grid; grid-template-columns: minmax(380px, 40%) 1fr; gap: 14px; padding: 14px; min-height: 0; }
.stage { display: grid; grid-template-rows: 1fr auto; gap: 10px; min-height: 0; }
.video { position: relative; border-radius: var(--radius); overflow: hidden; background: #d9cbb8; box-shadow: var(--shadow); min-height: 260px; }
.teacher-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
.teacher-fallback { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; animation: breathe 4.2s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.012) translateY(-2px); } }
.video-overlay { position: absolute; left: 12px; top: 12px; right: 12px; display: flex; justify-content: space-between; pointer-events: none; }
.live { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,.45); color: #fff; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; padding: 3px 9px; border-radius: 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #ff4d4d; box-shadow: 0 0 0 0 rgba(255,77,77,.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(255,77,77,0); } 100% { box-shadow: 0 0 0 0 rgba(255,77,77,0); } }
.nametag { background: rgba(255,255,255,.85); color: #1f2430; font-weight: 700; padding: 3px 12px; border-radius: 6px; font-size: 13px; }
.teacher-state { position: absolute; left: 12px; bottom: 12px; background: rgba(0,0,0,.45); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 99px; }
.subtitle { position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); width: min(92%, 640px); text-align: center; color: #fff; font-size: 16px; line-height: 1.5; text-shadow: 0 1px 3px rgba(0,0,0,.6); background: rgba(10,12,20,.45); border-radius: 10px; padding: 6px 12px; opacity: 0; transition: opacity .3s; pointer-events: none; }
.subtitle.show { opacity: 1; }
.self-strip { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.self-cam { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; font-size: 13px; white-space: nowrap; }
.self-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.self-cam.on .self-dot { background: #e53935; animation: pulse 1.2s infinite; }
.interim { color: var(--ink-2); font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panes { display: grid; grid-template-columns: minmax(280px, 0.9fr) 1.1fr; gap: 14px; min-height: 0; }
.material-pane, .chat-pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; }
.pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 16px 8px; border-bottom: 1px solid var(--line); }
.pane-head h2 { margin: 0; font-size: 15.5px; }
.level-badge { font-size: 12px; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 1px 10px; }
.level-badge:empty { display: none; }
.material-steps { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.material-steps:empty { display: none; }
.material-steps button { font-size: 12.5px; padding: 3px 10px; border-radius: 99px; }
.material-steps button.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.material-steps button.done { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.material-body { overflow-y: auto; padding: 12px 16px 20px; scroll-behavior: smooth; }
.mat-section { margin-bottom: 18px; border-radius: 12px; padding: 8px 10px; transition: background .3s, box-shadow .3s; }
.mat-section.active { background: color-mix(in srgb, var(--hl) 55%, transparent); box-shadow: inset 3px 0 0 var(--hl-line); }
.mat-section h3 { margin: 0 0 6px; font-size: 13.5px; color: var(--accent); letter-spacing: .02em; }
.mat-goal { font-size: 13.5px; color: var(--ink-2); margin: 0 0 12px; padding: 8px 10px; background: var(--accent-soft); border-radius: 10px; }
.mat-item { padding: 6px 8px; border-radius: 8px; margin: 2px 0; transition: background .3s; }
.mat-item.hl { background: var(--hl); box-shadow: 0 0 0 2px var(--hl-line) inset; }
.mat-item .en { font-weight: 700; }
.mat-item .ja { color: var(--ink-2); font-size: 13px; }
.mat-item .ex { color: var(--muted); font-size: 13px; }
.mat-item details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }

.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: 92%; display: flex; flex-direction: column; gap: 4px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg .meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.msg .bubble { padding: 9px 13px; border-radius: 14px; background: var(--ai); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; font-size: 15.5px; }
.msg.user .bubble { background: var(--user); border-color: transparent; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { border-bottom-left-radius: 4px; }
.msg.system .bubble { background: transparent; border-style: dashed; color: var(--muted); font-size: 13px; }
.msg .tools { display: flex; gap: 6px; }
.msg .tools button { font-size: 11.5px; padding: 1px 9px; border-radius: 99px; }
.msg .tools button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.translation { font-size: 13.5px; color: var(--ink-2); background: color-mix(in srgb, var(--accent-soft) 70%, transparent); border-radius: 10px; padding: 6px 11px; }
.corr { border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); background: color-mix(in srgb, #fff1e6 70%, var(--panel)); border-radius: 12px; padding: 7px 11px; font-size: 13.5px; max-width: 100%; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .corr { background: #2f241c; } }
.corr .label { font-size: 11px; font-weight: 700; color: var(--warn); letter-spacing: .04em; }
.corr .fix { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.corr .orig { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--warn) 60%, transparent); color: var(--muted); }
.corr .arrow { color: var(--warn); }
.corr .new { font-weight: 700; color: var(--good); }
.corr .why { color: var(--ink-2); font-size: 12.5px; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.error-line { color: var(--danger); font-size: 13px; display: flex; gap: 8px; align-items: center; }

/* controls */
.controls { display: flex; align-items: center; gap: 12px; padding: 10px 14px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.mic { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 99px; font-weight: 700; background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.ja-ask { padding: 8px 14px; border-radius: 99px; font-weight: 700; font-size: 13px; background: #fff; color: var(--accent); border: 1px solid var(--accent); white-space: nowrap; }
.ja-ask.on { background: #e53935; border-color: #e53935; color: #fff; }
.mic svg { width: 22px; height: 22px; fill: currentColor; }
.mic[aria-pressed="true"] { background: #e53935; color: #fff; box-shadow: 0 0 0 4px rgba(229,57,53,.2); }
.composer { flex: 1; display: flex; gap: 8px; align-items: flex-end; min-width: 0; }
.composer textarea { flex: 1; resize: none; max-height: 140px; min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); line-height: 1.5; }
.composer textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
.composer button { height: 44px; }
.control-group { display: flex; gap: 8px; }
.control-group button[aria-pressed="false"] { opacity: .6; }

/* dialogs */
dialog.sheet { border: none; border-radius: 18px; padding: 22px 24px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.sheet.wide { width: min(1040px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(18, 20, 28, .5); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 14px; font-size: 19px; }
dialog h3 { margin: 16px 0 8px; font-size: 14px; color: var(--ink-2); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.sheet-actions > :first-child { margin-right: auto; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; border: 0; padding: 0; }
.field > span, .field legend { font-weight: 600; font-size: 13.5px; }
.field input[type="password"], .field input[type="text"], .field select { padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field .inline { display: flex; gap: 8px; margin-top: 6px; }
.field .inline input { flex: 1; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 16px; border-radius: 8px; font-size: 14px; }
.seg input:checked + span { background: var(--accent); color: #fff; font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-block; padding: 5px 13px; border: 1px solid var(--line); border-radius: 99px; font-size: 13.5px; }
.chips input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.setup-row { display: grid; grid-template-columns: auto 1fr; gap: 28px; }
.teacher-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.teacher-card { position: relative; cursor: pointer; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--bg); transition: border-color .15s, transform .15s; }
.teacher-card:hover { transform: translateY(-2px); }
.teacher-card input { position: absolute; opacity: 0; }
.teacher-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; object-position: 50% 18%; }
.teacher-card .tc-body { padding: 8px 12px 10px; }
.teacher-card .tc-name { font-weight: 700; }
.teacher-card .tc-style { font-size: 12px; color: var(--accent); margin-left: 6px; }
.teacher-card .tc-tag { font-size: 12.5px; color: var(--ink-2); }
.teacher-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lesson-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.lesson-card { cursor: pointer; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; display: block; background: var(--bg); }
.lesson-card input { position: absolute; opacity: 0; }
.lesson-card .lc-title { font-weight: 700; }
.lesson-card .lc-en { font-size: 12.5px; color: var(--muted); }
.lesson-card .lc-level { font-size: 11.5px; padding: 0 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.lesson-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.lesson-card.off { opacity: .7; }

.history-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; min-height: 360px; margin-top: 12px; }
.history-list { list-style: none; margin: 0; padding: 0; overflow: auto; max-height: 60vh; border-right: 1px solid var(--line); padding-right: 10px; }
.history-list li { display: flex; gap: 6px; align-items: center; }
.history-list li button.open { flex: 1; text-align: left; border: 1px solid transparent; background: transparent; padding: 8px 10px; }
.history-list li button.open.current { background: var(--accent-soft); }
.history-list li button.del { font-size: 12px; padding: 2px 8px; color: var(--danger); border-color: transparent; }
.history-list .h-title { font-weight: 700; display: block; font-size: 14px; }
.history-list .h-date { font-size: 12px; color: var(--muted); }
.history-detail { overflow: auto; max-height: 60vh; }
.history-detail .chat-log { overflow: visible; padding: 0; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.expr { border-bottom: 1px solid var(--line); padding: 7px 0; }
.expr .p { font-weight: 700; }
.expr .m { color: var(--ink-2); font-size: 13.5px; }
.expr .e { color: var(--muted); font-size: 13px; }
.comment { background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin: 6px 0 14px; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #222634; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 30; max-width: calc(100vw - 32px); }

@media (max-width: 1100px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .lesson { grid-template-columns: 1fr; }
  .video { aspect-ratio: 4 / 3; }
  .panes { grid-template-columns: 1fr; }
  .material-pane { max-height: 50vh; }
  .chat-pane { min-height: 50vh; }
  .controls { position: sticky; bottom: 0; flex-wrap: wrap; }
  .control-group { width: 100%; justify-content: flex-end; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 8px 16px; }
  .brand-name { display: none; }
  .lesson-status { order: 3; width: 100%; flex-basis: 100%; }
  .phase-bar { display: none; }
  .lesson { padding: 10px 16px; }
  .teacher-cards { grid-template-columns: 1fr; }
  .setup-row, .summary-grid, .history-layout { grid-template-columns: 1fr; }
  .history-list { border-right: 0; max-height: 30vh; }
  .controls { padding: 10px 16px; }
}
.lesson-card .lc-level, .level-badge, .control-group button { white-space: nowrap; }
@media (max-width: 640px) { .control-group button { font-size: 13px; padding: 7px 10px; flex: 1; } }

.self-cam.sending .self-dot { background: var(--good); animation: none; }
.self-cam { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.heard { font-size: 12.5px; color: var(--ink-2); background: var(--accent-soft); border-radius: 10px; padding: 4px 10px; max-width: 100%; }
.heard-label { font-weight: 700; color: var(--accent); }
.pron { border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); background: var(--accent-soft); border-radius: 12px; padding: 7px 11px; font-size: 13.5px; max-width: 100%; }
.pron .label { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: .04em; }
.msg .meta .spoken { font-size: 11px; }

.lesson-cards { max-height: 34vh; overflow-y: auto; padding: 2px; }
.show-all { font-weight: 400; margin-left: 10px; cursor: pointer; }
.lc-level.lv-normal { background: #e6f3ea; color: #2f7d5b; }
.lc-level.lv-hard { background: #fbe9e4; color: #b5562f; }

/* ===================== スマホ（幅 760px 以下） =====================
   先生を上に小さく、その下で「会話／教材」をタブで切り替え、入力欄を画面下に固定する。
   ページ全体はスクロールさせず、会話・教材の中だけをスクロールさせる。 */
.mobile-tabs, .lbl-short { display: none; }
@media (max-width: 760px) {
  html, body { height: 100%; }
  body {
    height: 100dvh; min-height: 0; overflow: hidden;
    display: grid; grid-template-rows: auto 1fr auto;
    font-size: 15px; -webkit-text-size-adjust: 100%;
    padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }

  /* 上部バー: 1 行に収める */
  .topbar { flex-wrap: nowrap; gap: 8px; padding: calc(6px + env(safe-area-inset-top)) 12px 6px; min-height: 48px; }
  .brand-mark { width: 28px; height: 28px; font-size: 12px; }
  .brand-name, .api-count, .timer-total, .phase-bar { display: none !important; }
  .lesson-status { order: 0; width: auto; flex-basis: auto; flex: 1; justify-content: flex-start; gap: 8px; min-width: 0; }
  .phase-chip { font-size: 12px; padding: 2px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .timer { font-size: 17px; }
  .top-actions { gap: 6px; }
  .top-actions button { padding: 5px 10px; font-size: 13px; }

  /* 本体: 先生 → タブ → 会話か教材 */
  .lesson { display: flex; flex-direction: column; gap: 8px; padding: 8px 12px 6px; min-height: 0; overflow: hidden; }
  .stage { display: block; flex: none; }
  .video { aspect-ratio: auto; height: min(32dvh, 290px); min-height: 160px; }
  .self-strip { display: none; }
  .subtitle { font-size: 14px; bottom: 34px; padding: 4px 10px; }
  .teacher-state { bottom: 8px; left: 8px; font-size: 11px; }
  .video-overlay { left: 8px; top: 8px; right: 8px; }

  .mobile-tabs { display: flex; flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
  .mobile-tabs button { flex: 1; border: 0; border-radius: 9px; padding: 7px 0; font-weight: 700; font-size: 14px; background: transparent; color: var(--ink-2); position: relative; }
  .mobile-tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }
  .tab-dot { position: absolute; top: 6px; margin-left: 4px; width: 7px; height: 7px; border-radius: 50%; background: #f0a020; }

  .panes { display: block; flex: 1; min-height: 0; position: relative; }
  .material-pane, .chat-pane { display: none; height: 100%; max-height: none; min-height: 0; border-radius: 12px; }
  body[data-tab="chat"] .chat-pane, body:not([data-tab]) .chat-pane { display: flex; }
  body[data-tab="material"] .material-pane { display: flex; }
  .chat-pane .pane-head { display: none; }
  .chat-log { padding: 10px; gap: 10px; }
  .msg { max-width: 90%; }
  .msg .bubble { font-size: 15px; padding: 8px 11px; }
  .msg .tools button { padding: 3px 11px; font-size: 12px; }   /* 指で押しやすく */
  .material-body { padding: 10px 12px 16px; }
  .pane-head { padding: 9px 12px 6px; }
  .material-steps { flex: none; padding: 8px 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .material-steps button { flex: none; white-space: nowrap; padding: 4px 12px; }
  .material-pane .pane-head, .material-body { flex: none; }
  .material-body { flex: 1; min-height: 0; }
  .video { height: min(30dvh, 280px); }

  /* 下部: 1 段目 マイク + 入力 + 送信、2 段目 小さなボタン */
  .controls {
    position: static; display: grid; grid-template-columns: auto 1fr; gap: 8px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  }
  .mic { width: 48px; height: 48px; padding: 0; justify-content: center; border-radius: 50%; }
  .mic svg { width: 24px; height: 24px; }
  .composer { min-width: 0; }
  .composer textarea { font-size: 16px; min-height: 48px; padding: 11px 12px; }   /* 16px 未満だと iPhone が拡大してしまう */
  .composer button { height: 48px; padding: 0 14px; }
  .control-group { grid-column: 1 / -1; width: 100%; display: flex; gap: 6px; }
  .control-group button { flex: 1; font-size: 13px; padding: 7px 6px; white-space: nowrap; }

  /* ダイアログは全画面に */
  dialog.sheet, dialog.sheet.wide {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0;
    padding: calc(14px + env(safe-area-inset-top)) 16px 0;
  }
  dialog.sheet[open] { display: flex; flex-direction: column; }   /* 閉じているダイアログは表示しない */
  dialog.sheet[open] > form { display: flex; flex-direction: column; min-height: 100%; }
  .sheet-actions { position: sticky; bottom: 0; background: var(--panel); margin: auto -16px 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  dialog h2 { font-size: 18px; margin-bottom: 8px; }

  /* レッスン準備: 先生は 3 人を横並びの小さなカードに */
  .teacher-cards { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .teacher-card img { aspect-ratio: 3 / 4; object-position: 50% 12%; }
  .teacher-card .tc-body { padding: 6px 8px 7px; }
  .teacher-card .tc-name { font-size: 13px; }
  .teacher-card .tc-style { display: block; margin: 0; font-size: 11px; }
  .teacher-card .tc-tag { display: none; }
  .setup-row { display: block; }
  .setup-row > div { margin-bottom: 4px; }
  .seg span { padding: 6px 14px; }
  .lesson-cards { grid-template-columns: 1fr; max-height: none; overflow: visible; gap: 8px; }
  .lesson-card { padding: 9px 12px; }

  .history-layout { min-height: 0; }
  .summary-grid { grid-template-columns: 1fr; }
  .toast { bottom: calc(130px + env(safe-area-inset-bottom)); }
}

/* 背の低いスマホ（iPhone SE など）: 先生の映像を小さくし、会話・教材の表示を広く取る */
@media (max-width: 760px) and (max-height: 720px) {
  .video { height: 24dvh; min-height: 112px; }
  .material-pane .pane-head { display: none; }
  .lesson { gap: 6px; padding-top: 6px; }
  .mobile-tabs button { padding: 5px 0; }
  .controls { gap: 6px; padding-top: 6px; }
  .mic, .composer button { height: 44px; }
  .mic { width: 44px; }
  .composer textarea { min-height: 44px; padding: 9px 11px; }
  .control-group button { padding: 5px 6px; }
}

.tc-note { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.tc-note.jp { display: inline-block; color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); border-radius: 99px; padding: 1px 9px; font-weight: 700; }
.good { border: 1px solid color-mix(in srgb, var(--good) 30%, transparent); background: color-mix(in srgb, var(--good) 8%, var(--panel)); border-radius: 12px; padding: 7px 11px; font-size: 13.5px; margin-top: 6px; }
.good .new { font-weight: 700; color: var(--good); } .good .why { color: var(--ink-2); font-size: 12.5px; }
button.danger.armed { background: var(--danger); color: #fff; }
.field input[type="text"] { padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
@media (max-width: 760px) { .teacher-card .tc-note { display: block; font-size: 10.5px; padding: 0; background: none; } }

/* アカウント・チケット・購入（有料化しているときだけ表示） */
.account-box { margin: 12px 0 4px; padding: 10px 12px; border: 1px solid #e4dfd6; border-radius: 12px; background: #f6f4ef; display: grid; gap: 8px; }
.account-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ticket-count { color: #3b4a7a; font-size: 15px; }
.account-head .ghost { margin-left: auto; }
.buy-row { display: flex; flex-wrap: wrap; gap: 8px; }
.legal-row { display: flex; gap: 14px; font-size: 12px; }
.legal-row a { color: #5a6cae; }
.site-links { flex-basis: 100%; width: 100%; display: flex; gap: 14px; justify-content: center; font-size: 11px; line-height: 1.4; padding-top: 2px; }
.site-links a { color: #7b8291; text-decoration: none; }
.controls { flex-wrap: wrap; }
.site-links { grid-column: 1 / -1; }
@media (max-width: 760px) { body:has(#lessonStatus:not([hidden])) .site-links { display: none; } }
