:root {
    --primary: #e63946;
    --primary-glow: rgba(230, 57, 70, 0.4);
    --bg: #f8f9fa;
    --surface: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(0, 0, 0, 0.1);
    --text: #212529;
    --text-dim: #6c757d;
    /* 右上の介助者ボタン（⛶ ⚙ ◎）の縦の列。質問モードの上のボタンもこの高さにそろえる */
    --qa-size: 64px;
    --qa-gap: 8px;
    --qa-top: 0.5rem;   /* #ui-layer の上の余白と同じ */
    --qa-right: 12px;
    /* 画面の右に空ける幅（ボタンの列 + すき間。#ui-layer の右の余白 1rem の分は引く） */
    --qa-gutter: calc(var(--qa-right) + var(--qa-size) + var(--qa-gap) - 1rem);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
}

/* ── camera / face tracking ─────────────────────── */
#mirror-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

#webcam {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.04;
    transform: scaleX(-1);
}

#canvas-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0.5;
    transform: scaleX(-1);
}

/* ── pointer ─────────────────────────────────────── */
#pointer {
    position: fixed;
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 16px var(--primary-glow), 0 0 36px var(--primary-glow);
    pointer-events: none;
    top: 0;
    left: 0;
    /* 位置は JS が --pointer-x / --pointer-y を更新する（left/top より軽い） */
    transform: translate3d(var(--pointer-x, 50vw), var(--pointer-y, 50vh), 0) translate(-50%, -50%) scale(var(--pointer-scale, 1));
    will-change: transform;
    z-index: 600;
    /* above ui-layer(10), confirm overlay(500) precedes confirm *zone* */
    transition: background 0.15s;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

/* 右上に縦に並ぶ、介助者がマウスで押すボタン（全画面・設定・正面取り直し） */
#quick-actions {
    position: fixed;
    top: var(--qa-top);
    right: var(--qa-right);
    z-index: 590; /* ポインタ(600)の下。設定画面(2000)を開くと隠す */
    display: grid;
    grid-template-rows: repeat(3, var(--qa-size));
    gap: var(--qa-gap);
    pointer-events: none;
}

/* 全画面が使えない環境でも、⚙ と正面取り直しは同じ段のまま */
#fullscreen-btn { grid-row: 1; }
#settings-btn { grid-row: 2; }
#recapture-front-btn { grid-row: 3; }

.quick-action-btn {
    width: var(--qa-size);
    height: var(--qa-size);
    padding: 0;
    border-radius: 999px;
    border: 1px solid rgba(100, 116, 139, 0.35);
    background: rgba(255, 255, 255, 0.85);
    color: #334155;
    font-size: 1.9rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    pointer-events: auto;
    transition: opacity 0.15s;
}

.quick-action-btn:hover {
    opacity: 1;
}

body.calib-active #quick-actions,
body.settings-open #quick-actions {
    display: none;
}

/* 姿勢ずれのお知らせ: 端に張り付いたままのとき、「◎ 正面取り直し」を光らせる */
#recapture-front-btn.suggest {
    opacity: 1;
    border-color: #f4a261;
    animation: front-recapture-pulse 1.4s ease-in-out infinite;
}

@keyframes front-recapture-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(244, 162, 97, 0.7); }
    50% { box-shadow: 0 0 0 10px rgba(244, 162, 97, 0); }
}

/* ── dwell indicator (滞留確定の円グラフ) ──────────── */
#dwell-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 96px;
    height: 96px;
    border-radius: 50%;
    pointer-events: none;
    /* --dwell-progress (0〜1) の割合だけ時計回りに塗る */
    background: conic-gradient(rgba(230, 57, 70, 0.85) calc(var(--dwell-progress, 0) * 360deg), rgba(255, 255, 255, 0.55) 0);
    border: 3px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
    transform: translate3d(var(--dwell-x, 50vw), var(--dwell-y, 50vh), 0) translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 590; /* pointer(600) の下 */
}

#dwell-indicator.active {
    opacity: 1;
}

/* ── ui layer ────────────────────────────────────── */
#ui-layer {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem 1rem;
    /* 右上の ⛶ ⚙ ◎ の列に、どのモードでも画面を重ねない */
    padding-right: calc(1rem + var(--qa-gutter));
    gap: 0.5rem;
    pointer-events: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── panel grid ─────────────────────────────────── */
#simple-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

#simple-body {
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 0.6rem;
}

/* 前へ・次へ: パネルの左端・右端の縦長ボタン */
.simple-side {
    flex: 0 0 clamp(76px, 7.5vw, 128px);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* 次へは画面の右端（⛶ ⚙ ◎ の列の右端）まで寄せ、空いた幅をパネルに回す。
   ⛶ ⚙ ◎ と重なる高さは --side-next-clear（JS で計測）だけ上を空ける */
#simple-side-next {
    margin-right: calc(var(--qa-right) - 1rem - var(--qa-gutter));
    padding-top: var(--side-next-clear, 0px);
}

.simple-side .simple-ctrl--side {
    flex: 1 1 0;
    white-space: pre-line;
    font-size: clamp(1.4rem, 2.4vw, 2.2rem);
    background: linear-gradient(180deg, rgba(232, 244, 253, 0.9) 0%, rgba(208, 228, 244, 0.8) 100%);
    border-color: rgba(69, 123, 157, 0.45);
}

/* 質問モードの休憩（いちばん左） */
.simple-side--rest .h-btn.simple-ctrl--rest {
    background: linear-gradient(180deg, rgba(237, 250, 242, 0.92) 0%, rgba(210, 240, 222, 0.82) 100%);
    border-color: rgba(45, 106, 79, 0.45);
}

.simple-page-label--side {
    padding: 0;
    text-align: center;
    font-size: clamp(1rem, 1.6vw, 1.5rem);
}

#app .simple-grid {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: grid;
    gap: 0.6rem;
    position: relative;
}

/* 質問モード: 介助者がマウスで質問を切り替えるボタン（ポインタの対象外）
   年配の介助者でも押しやすいよう、同じ大きさのボタンを左端から並べる。会話中も並びは変わらない */
#question-mode-bar {
    flex: 0 0 auto;
    display: grid;
    /* 8つずつ2段（既定の16問）。どの画面幅でも同じ場所に同じボタンが来る */
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 0.45rem;
}

/* 縦が短い画面（ノートPCなど）は、回答パネルの高さを残すためボタンを低くする（アイコンと文字を横に並べる） */
@media (max-height: 820px) {
    #question-mode-bar {
        gap: 0.35rem;
    }

    .question-mode-btn {
        flex-direction: row;
        gap: 0.25rem;
        padding: 0.35rem 0.3rem;
    }

    .question-mode-icon {
        font-size: 1.2em;
    }
}

/* 狭い画面では8列だと文字が切れるので、入るだけ並べる */
@media (max-width: 1200px) {
    #question-mode-bar {
        grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
    }
}

.question-mode-btn {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    padding: 0.3rem 0.4rem;
    border: 3px solid rgba(69, 123, 157, 0.45);
    border-radius: 0.9rem;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: clamp(0.95rem, 1.3vw, 1.35rem);
    font-weight: 900;
    line-height: 1.15;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.08);
    /* #ui-layer は pointer-events: none なので、マウスで押せるようにボタンだけ戻す */
    pointer-events: auto;
}

.question-mode-icon {
    font-size: 1.35em;
    line-height: 1;
}

img.question-mode-icon {
    width: 1em;
    height: 1em;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

.simple-message-question-icon {
    width: 1.25em;
    height: 1.25em;
    vertical-align: -0.2em;
    object-fit: contain;
    margin-right: 0.35rem;
    display: inline-block;
}

/* 設定画面の「今すぐ質問する」ボタンと質問一覧で、文の前に置く質問のアイコン */
.question-inline-icon {
    width: 1.2em;
    height: 1.2em;
    vertical-align: -0.22em;
    object-fit: contain;
    margin-right: 0.3rem;
    display: inline-block;
}

.question-mode-label {
    max-width: 100%;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.question-mode-btn:hover {
    background: #eef5fa;
    border-color: #457b9d;
}

.question-mode-btn.active {
    background: #457b9d;
    border-color: #1d3557;
    color: #fff;
    box-shadow: 0 0 0 3px rgba(69, 123, 157, 0.35);
}

/* ページ送り・休憩のバー */
#simple-bar {
    flex: 0 0 clamp(56px, 10vh, 96px);
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
    justify-content: center;
}

/* 休憩は下の幅いっぱい（前へ・次へはパネルの左右） */
#simple-bar .h-btn.simple-ctrl.simple-ctrl--rest {
    flex: 1 1 0;
}

#simple-bar .h-btn.simple-ctrl {
    flex: 1 1 0;
    font-size: clamp(1.4rem, 2.6vw, 2.4rem);
    padding: 0.2rem 0.6rem;
    background: linear-gradient(180deg, rgba(232, 244, 253, 0.9) 0%, rgba(208, 228, 244, 0.8) 100%);
    border-color: rgba(69, 123, 157, 0.45);
}

#simple-bar .h-btn.simple-ctrl--rest {
    background: linear-gradient(180deg, rgba(237, 250, 242, 0.92) 0%, rgba(210, 240, 222, 0.82) 100%);
    border-color: rgba(45, 106, 79, 0.45);
}

.simple-page-label {
    flex: 0 0 auto;
    align-self: center;
    padding: 0 0.6rem;
    font-size: clamp(1.2rem, 2.2vw, 2rem);
    font-weight: 900;
    color: #334155;
}

.simple-empty-notice {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    color: #475569;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 1.4rem;
}

.h-btn-emoji {
    font-size: 2.2em;
    line-height: 1.1;
    flex: 0 1 auto;
}

/* 休憩中: 再開パネル以外を暗くする（左右の前へ・次へ、お話のタブも） */
#app[data-simple-paused="1"] .simple-grid .h-btn,
#app[data-simple-paused="1"] #simple-bar .h-btn:not(.simple-ctrl--rest),
#app[data-simple-paused="1"] .simple-side:not(.simple-side--rest),
#app[data-simple-paused="1"] #simple-tabs .h-btn {
    opacity: 0.3;
    filter: grayscale(0.8);
}

#app[data-simple-paused="1"] .simple-grid::after {
    content: "休憩中";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(3rem, 9vw, 7rem);
    font-weight: 900;
    color: #2d6a4f;
    pointer-events: none;
}

#app .simple-grid .h-btn {
    font-size: clamp(1.6rem, 3.4vw, 3.2rem);
    min-height: 0;
    padding: 0.4rem;
}

#app .simple-grid .h-btn-icon {
    width: auto;
    height: 62%;
    max-width: 90%;
    flex: 0 1 auto;
    min-height: 0;
}

/* ホバー中のパネルは離れた介助者からも分かるよう太い枠で強調 */
#app #simple-panel .h-btn.hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 5px var(--primary), 0 16px 32px rgba(15, 23, 42, 0.2);
    transform: scale(1.02);
    background: linear-gradient(180deg, #fff 0%, #ffe9ec 100%);
    z-index: 1;
}

/* ── base button ─────────────────────────────────── */
.h-btn {
    border-radius: 1.4rem;
    border: 2px solid rgba(255, 255, 255, 0.72);
    color: var(--text);
    font-family: inherit;
    font-size: clamp(3.4rem, 6.8vw, 5.4rem);
    font-weight: 900;
    line-height: 1.1;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-align: center;
    padding: 0.75rem 0.6rem;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(248, 249, 250, 0.56) 100%);
    transition: background 0.25s, border-color 0.25s, transform 0.15s, box-shadow 0.2s, opacity 0.2s;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.1);
    backdrop-filter: blur(4px) saturate(1.05);
    pointer-events: auto;
    user-select: none;
}

.h-btn::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0) 52%);
    pointer-events: none;
}

.h-btn::after {
    content: "";
    position: absolute;
    inset: auto 14% 10px;
    height: 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.1);
    filter: blur(10px);
    opacity: 0.32;
    pointer-events: none;
}

/* button content: アイコンは幅・高さを固定してサイズを揃える（object-fit:containで縦横比は保持） */
.h-btn-icon {
    width: min(64%, 150px);
    height: min(64%, 150px);
    object-fit: contain;
    margin-bottom: 0;
    flex: 0 0 auto;
}

.h-btn-text {
    font-size: inherit;
    line-height: 1.05;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
    flex: 0 0 auto;
}

/* empty slot */
.h-btn--empty {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.2);
    cursor: default;
    pointer-events: none;
    font-size: 4.8rem;
}

/* ── confirm overlay ─────────────────────────────── */
#confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
}

#confirm-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#confirm-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 2rem;
    padding: 4rem 6rem; /* Increased padding */
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    max-width: 80vw;
    animation: popIn 0.4s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

@keyframes popIn {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

#confirm-icon {
    font-size: 5rem; /* Larger icon */
    color: #52b788;
    text-shadow: 0 0 20px rgba(82, 183, 136, 0.8);
}

#confirm-text {
    font-size: clamp(3rem, 7vw, 6rem); /* Significantly larger text */
    font-weight: 900;
    color: #fff;
    text-align: center;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.04em;
}

/* ── gesture indicator ───────────────────────────── */
#gesture-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 160px;
    height: 160px;
    border: 4px solid var(--primary);
    border-radius: 50%;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.19, 1, 0.22, 1),
        width 0.35s cubic-bezier(0.19, 1, 0.22, 1),
        height 0.35s cubic-bezier(0.19, 1, 0.22, 1),
        border-width 0.35s cubic-bezier(0.19, 1, 0.22, 1),
        box-shadow 0.35s cubic-bezier(0.19, 1, 0.22, 1);
}

#gesture-indicator.active {
    opacity: 1;
    width: 260px;
    height: 260px;
    border-width: 8px;
    box-shadow: 0 0 40px var(--primary-glow);
}

/* ── loading ─────────────────────────────────────── */
#loading {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    gap: 1rem;
}

.loader {
    width: 52px;
    height: 52px;
    border: 5px solid rgba(255, 255, 255, 0.15);
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.tts-preview-row {
    display: flex;
    gap: 0.6rem;
}

.tts-preview-row input {
    flex: 1;
    min-width: 0;
}

.tts-preview-btn {
    flex-shrink: 0;
    width: 3rem;
    padding: 0;
    font-size: 1.2rem;
}

.tts-preview-btn.is-loading {
    opacity: 0.5;
    animation: tts-preview-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes tts-preview-pulse {
    from { transform: scale(1); }
    to { transform: scale(0.9); }
}

/* ── calibration wizard ──────────────────────────── */
/* 計測中はワイヤーフレームを最前面（ウィザードの直下）に薄く出し、後ろの画面は隠す */
body.calib-active #mirror-container {
    z-index: 2400;
    background: rgba(248, 249, 250, 0.94);
    pointer-events: none;
}

body.calib-active #canvas-overlay {
    opacity: 0.35;
}

body.calib-active #pointer,
body.calib-active #dwell-indicator {
    display: none;
}

#calib-wizard {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: none;
    pointer-events: auto;
}

#calib-wizard.active {
    display: block;
}

#calib-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 1.2rem 0.6rem;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    color: var(--text);
}

#calib-topbar-text {
    flex: 1;
    min-width: 0;
    text-align: center;
}

/* .ctrl-btn の display 指定が hidden 属性より優先されるため明示する */
#calib-topbar-actions [hidden] {
    display: none;
}

#calib-topbar-actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

#calib-wizard.done #calib-topbar-actions {
    display: none;
}

#calib-step-count {
    font-size: 0.9rem;
    color: var(--text-dim);
}

#calib-instruction {
    font-size: clamp(1.2rem, 2.6vw, 1.8rem);
    font-weight: 900;
    line-height: 1.3;
}

#calib-arrow {
    margin-right: 0.4em;
}

#calib-sub {
    margin-top: 0.2rem;
    min-height: 1.4em;
    font-size: 1rem;
    color: var(--text-dim);
}

#calib-progress {
    margin: 0.5rem auto 0;
    max-width: 640px;
    height: 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

#calib-progress-bar {
    width: 0;
    height: 100%;
    background: var(--primary);
}

#calib-progress-bar.is-prepare {
    background: #adb5bd;
}

/* 見てもらう○。--calib-hold(0〜1) の割合だけ縁を塗って、止まっている時間を見せる */
#calib-target {
    position: absolute;
    top: 0;
    left: 0;
    width: 92px;
    height: 92px;
    border-radius: 50%;
    display: none;
    transform: translate3d(var(--calib-x, 50vw), var(--calib-y, 50vh), 0) translate(-50%, -50%);
    background:
        radial-gradient(circle, var(--primary) 0 7px, transparent 8px),
        radial-gradient(circle, rgba(255, 255, 255, 0.85) 0 37px, transparent 38px),
        conic-gradient(var(--primary) calc(var(--calib-hold, 0) * 360deg), rgba(230, 57, 70, 0.25) 0);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
    transition: transform 0.25s ease, background 0.15s;
    pointer-events: none;
}

#calib-wizard.is-target #calib-target {
    display: block;
}

#calib-target.matched {
    background:
        radial-gradient(circle, #2b8a3e 0 7px, transparent 8px),
        radial-gradient(circle, rgba(235, 251, 238, 0.95) 0 37px, transparent 38px),
        conic-gradient(#2b8a3e 360deg, #2b8a3e 0);
    transform: translate3d(var(--calib-x, 50vw), var(--calib-y, 50vh), 0) translate(-50%, -50%) scale(1.15);
}

/* 今の顔の向きから予測したカーソル。○より目立たないよう薄く小さくする */
#calib-cursor {
    position: absolute;
    top: 0;
    left: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(69, 123, 157, 0.7);
    background: rgba(69, 123, 157, 0.25);
    transform: translate3d(var(--calib-x, 50vw), var(--calib-y, 50vh), 0) translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s, background 0.15s;
    pointer-events: none;
}

#calib-wizard.is-target #calib-cursor.visible {
    opacity: 0.8;
}

#calib-cursor.in-circle {
    border-color: rgba(43, 138, 62, 0.9);
    background: rgba(43, 138, 62, 0.35);
}

#calib-box {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(620px, calc(100% - 2rem));
    padding: 1.2rem 1.6rem;
    border-radius: 1.4rem;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
    color: var(--text);
}

#calib-wizard.done #calib-box {
    display: block;
}

#calib-wizard.done #calib-progress {
    display: none;
}

#calib-result {
    margin: 0 0 0.6rem;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    font-family: inherit;
}

#calib-actions {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
}

/* =========================================================
   共通ボタン
   ========================================================= */
.ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.7rem;
    border: 1px solid #d0d7de;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    pointer-events: auto;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.ctrl-btn:hover {
    background: #f6f8fa;
    border-color: #afb8c1;
}

.ctrl-btn:focus-visible,
.settings-tab-btn:focus-visible,
.filter-chip:focus-visible {
    outline: 3px solid rgba(230, 57, 70, 0.35);
    outline-offset: 2px;
}

.ctrl-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.ctrl-btn.primary:hover {
    background: #d62839;
}

.ctrl-btn.secondary {
    background: #fff;
}

.ctrl-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* 設定の音声タブ: 保存済みの件数 */
.audio-cache-summary {
    margin: 0 0 0.5rem;
    font-weight: 700;
    color: var(--text);
}

/* 進捗表示（音声データ生成） */
.status-info {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding: 0.6rem 0.8rem;
    border-radius: 0.6rem;
    border: 1px solid rgba(45, 157, 107, 0.3);
    background: rgba(45, 157, 107, 0.08);
    color: #1f7a52;
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease;
}

.status-label {
    font-weight: 700;
}

.status-progress-bar {
    height: 6px;
    border-radius: 3px;
    background: rgba(45, 157, 107, 0.2);
    overflow: hidden;
}

.status-progress-fill {
    width: 0%;
    height: 100%;
    background: #2d9d6b;
    transition: width 0.15s linear;
}

/* =========================================================
   設定 → ポインタと確定: 感度スライダー・計測値
   ========================================================= */
#quick-tuning {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.compact-slider-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.compact-slider-item label {
    display: flex;
    justify-content: space-between;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
}

.compact-slider-item label span {
    font-variant-numeric: tabular-nums;
    color: var(--primary);
}

.compact-slider-item input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
}

#telemetry-panel summary {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-dim);
}

#telemetry-values {
    margin: 0.4rem 0 0;
    padding: 0.5rem 0.6rem;
    border-radius: 0.5rem;
    background: #1f2933;
    color: #d9f7ff;
    font-family: monospace;
    font-size: 11px;
    line-height: 1.45;
    white-space: pre;
}

/* =========================================================
   設定モーダル
   ========================================================= */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    width: min(980px, 100%);
    height: min(720px, 100%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 1.4rem;
    background: #f6f8fa;
    color: var(--text);
    box-shadow: 0 30px 60px rgba(15, 23, 42, 0.35);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.2rem;
    background: #fff;
    border-bottom: 1px solid #eaeef2;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 900;
}

.modal-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-dim);
}

.modal-close:hover {
    background: #eaeef2;
    color: var(--text);
}

.settings-body {
    flex: 1;
    min-height: 0;
    display: flex;
}

.settings-tabs {
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 1rem 0.7rem;
    background: #fff;
    border-right: 1px solid #eaeef2;
}

.settings-tab-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    border: none;
    border-radius: 0.7rem;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.98rem;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.settings-tab-btn:hover {
    background: #f6f8fa;
    color: var(--text);
}

.settings-tab-btn.active {
    background: rgba(230, 57, 70, 0.1);
    color: var(--primary);
}

.settings-panes {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 1.1rem 1.3rem;
}

.settings-tab-content {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.settings-tab-content.active {
    display: flex;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 1rem 1.1rem;
    border-radius: 1rem;
    background: #fff;
    border: 1px solid #eaeef2;
}

.settings-section h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 900;
}

.settings-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

/* 説明文が長くてもボタンの文字は折り返さない */
.settings-section-head > .ctrl-btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

.settings-badge {
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    background: #eaeef2;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-dim);
}

.settings-help {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.5;
}

/* 左の分類の見出し（全体の設定 / 画面ごとの中身） */
.settings-tab-group {
    padding: 0.8rem 0.9rem 0.2rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text-dim);
}

.settings-tab-group:first-child {
    padding-top: 0;
}

/* タブの先頭の「このタブで何を決めるか」 */
.settings-pane-lead {
    margin: 0;
    font-size: 0.92rem;
    color: var(--text);
    line-height: 1.6;
}

.settings-subheading {
    margin-top: 0.4rem !important;
    padding-top: 0.8rem;
    border-top: 1px solid #eaeef2;
}

/* 基本タブ: はじめて使うときの手順 */
.settings-guide {
    background: #fffaf0;
    border-color: rgba(244, 162, 97, 0.45);
}

.settings-steps {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.settings-steps li {
    counter-increment: step;
    display: grid;
    grid-template-columns: 1.8rem 1fr;
    column-gap: 0.6rem;
    font-size: 0.9rem;
}

.settings-steps li::before {
    content: counter(step);
    grid-row: 1 / span 2;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
    background: #f4a261;
    color: #fff;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-steps li > span {
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.6;
}

/* 手順の1番目（キャリブレーション）は目立たせ、その場で始められるボタンを置く */
.settings-step--primary {
    padding: 0.6rem 0.7rem 0.7rem;
    border-radius: 0.8rem;
    background: #fff;
    border: 1px solid rgba(244, 162, 97, 0.45);
}

.settings-step--primary::before {
    background: var(--primary) !important;
}

.settings-step-action {
    grid-column: 2;
    justify-self: start;
    margin-top: 0.5rem;
}

.calib-status-badge {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.05rem 0.55rem;
    border-radius: 999px;
    background: #fff1f2;
    color: var(--primary);
    font-size: 0.75rem;
    vertical-align: middle;
}

.calib-status-badge.is-done {
    background: #e6f6f2;
    color: #1d6f65;
}

/* 初回の案内（キャリブレーションがまだのとき起動時に出す） */
.welcome-content {
    width: min(640px, 100%);
    height: auto;
}

.welcome-body {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 1.6rem 1.8rem 1.2rem;
    background: #fff;
}

.welcome-icon {
    font-size: 2.6rem;
    line-height: 1;
}

.welcome-body h3 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 900;
}

.welcome-lead {
    margin: 0;
    color: var(--text-dim);
    font-size: 0.92rem;
}

/* ほかのタブへ移るボタン（文中に置く） */
.link-btn {
    display: inline-block;
    margin: 0.1rem 0.15rem 0.1rem 0;
    padding: 0.1rem 0.6rem;
    border-radius: 999px;
    border: 1px solid #d0d7de;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

.link-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* 選んだ声では使わない設定 */
.settings-section.is-inactive {
    opacity: 0.5;
}

.settings-panes select,
.settings-panes input[type="text"],
.settings-panes input[type="number"],
.settings-panes input[type="password"] {
    width: 100%;
    min-height: 2.6rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.7rem;
    border: 1px solid #d0d7de;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
}

.settings-panes select:focus,
.settings-panes input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.15);
}

/* モード選択カード */
.choice-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
}

.choice-card {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 0.7rem;
    row-gap: 0.15rem;
    padding: 0.9rem 1rem;
    border-radius: 0.9rem;
    border: 2px solid #d0d7de;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.choice-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.choice-card-icon {
    grid-row: 1 / 3;
    font-size: 2rem;
    line-height: 1;
    align-self: center;
}

.choice-card-title {
    font-weight: 900;
}

.choice-card-desc {
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.45;
}

.choice-card:has(input:checked) {
    border-color: var(--primary);
    background: rgba(230, 57, 70, 0.06);
}

.choice-card:has(input:focus-visible) {
    outline: 3px solid rgba(230, 57, 70, 0.35);
    outline-offset: 2px;
}

/* セグメント選択（滞留時間・グリッドサイズ） */
.segmented {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.segmented label {
    flex: 1 1 0;
    min-width: 64px;
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 2.8rem;
    padding: 0.35rem 0.4rem;
    border-radius: 0.7rem;
    border: 1px solid #d0d7de;
    background: #fff;
    font-weight: 700;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.segmented span small {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-dim);
}

.segmented label:hover span {
    border-color: #afb8c1;
}

.segmented input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.segmented input:checked + span small {
    color: rgba(255, 255, 255, 0.85);
}

.segmented input:focus-visible + span {
    outline: 3px solid rgba(230, 57, 70, 0.35);
    outline-offset: 2px;
}

/* トグル（チェックボックス） */
.toggle-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0;
    cursor: pointer;
    font-weight: 700;
}

.toggle-row > span:last-child {
    display: flex;
    flex-direction: column;
}

.toggle-row small {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-dim);
}

.toggle-row input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-switch {
    flex: 0 0 auto;
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background:
        radial-gradient(circle at 12px 50%, #fff 9px, transparent 9.5px),
        #9aa5b1;
    transition: background 0.2s;
}

.toggle-row input:checked + .toggle-switch {
    background:
        radial-gradient(circle at 32px 50%, #fff 9px, transparent 9.5px),
        #2d9d6b;
}

.toggle-row input:focus-visible + .toggle-switch {
    outline: 3px solid rgba(230, 57, 70, 0.35);
    outline-offset: 2px;
}

/* 選んだポインタの動かし方では働かない補助（切り替えはできる） */
.toggle-row.is-inactive {
    opacity: 0.45;
}

/* 入力欄 */
.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-dim);
}

.field em {
    font-style: normal;
    color: var(--primary);
    font-size: 0.75rem;
}

.field--row {
    flex-direction: row;
    align-items: center;
    gap: 0.8rem;
}

.field--row > span {
    flex: 0 0 5.5rem;
}

.input-with-button {
    display: flex;
    gap: 0.5rem;
}

.input-with-button .ctrl-btn {
    flex: 0 0 auto;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.7rem;
    padding: 0.8rem 1.2rem;
    background: #fff;
    border-top: 1px solid #eaeef2;
}

.modal-actions .ctrl-btn {
    min-width: 9rem;
}

.modal-actions-note {
    margin-right: auto;
    align-self: center;
    font-size: 0.82rem;
    color: var(--text-dim);
}

/* =========================================================
   設定: パネル一覧（分類で絞り込み・編集）
   ========================================================= */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    border: 1px solid #d0d7de;
    background: #fff;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
}

.filter-chip:hover {
    border-color: #afb8c1;
}

.filter-chip.active {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

.filter-chip-count {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.7;
}

.simple-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.simple-editor-toolbar .ctrl-btn {
    min-height: 2.1rem;
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
}


.simple-editor-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.7rem;
    border: 1px solid #eaeef2;
    background: #fff;
}

.simple-editor-row:hover {
    border-color: #d0d7de;
}

.simple-editor-row.is-disabled {
    background: #f6f8fa;
}

.simple-editor-row.is-disabled .simple-editor-thumb,
.simple-editor-row.is-disabled .simple-editor-text {
    opacity: 0.5;
}

.simple-editor-row input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
    accent-color: var(--primary);
    cursor: pointer;
}

.simple-editor-thumb {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 0.5rem;
    background: #f6f8fa;
    font-size: 1.7rem;
}

.simple-editor-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.simple-editor-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.simple-editor-text strong {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.simple-editor-group {
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: #eaeef2;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-dim);
}

.simple-editor-text small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-dim);
}

.simple-editor-actions {
    display: flex;
    gap: 0.3rem;
}

.simple-editor-actions .ctrl-btn {
    min-height: 2.1rem;
    min-width: 2.3rem;
    padding: 0.2rem 0.55rem;
    font-size: 0.85rem;
}

/* 任意パネル追加フォーム */
.simple-custom-form {
    display: grid;
    grid-template-columns: 1fr 1.6fr 0.6fr;
    gap: 0.7rem;
    align-items: end;
}

.field--image {
    grid-column: 1 / 3;
}

.image-picker {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.image-picker-btn {
    position: relative;
    overflow: hidden;
}

.image-picker-btn input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

#simple-custom-image-preview {
    width: 52px;
    height: 52px;
    object-fit: contain;
    border-radius: 0.5rem;
    border: 1px solid #eaeef2;
    background: #fff;
}

#simple-custom-add-btn {
    grid-column: 3;
}

@media (max-width: 720px) {
    .settings-body {
        flex-direction: column;
    }

    .settings-tabs {
        flex: 0 0 auto;
        flex-direction: row;
        overflow-x: auto;
        padding: 0.5rem;
        border-right: none;
        border-bottom: 1px solid #eaeef2;
    }

    .settings-tab-group,
    .modal-actions-note {
        display: none;
    }

    .choice-cards,
    .simple-custom-form {
        grid-template-columns: 1fr;
    }

    .field--image,
    #simple-custom-add-btn {
        grid-column: auto;
    }

    .modal-content {
        height: 100%;
    }
}

/* =========================================================
   質問文 / お話の文の表示
   ========================================================= */
#simple-message {
    flex: 0 0 clamp(60px, 10vh, 92px);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 1rem;
    overflow: hidden;
    border-radius: 1.2rem;
    background: rgba(255, 255, 255, 0.92);
    border: 2px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

#simple-message.is-question {
    justify-content: center;
    background: linear-gradient(135deg, #fff7e6 0%, #ffe8c2 100%);
    border-color: rgba(244, 162, 97, 0.6);
}

.simple-message-question {
    font-size: clamp(1.6rem, 3.6vw, 3rem);
    font-weight: 900;
    color: #7f5539;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.simple-message-chip {
    flex: 0 0 auto;
    padding: 0.3rem 0.9rem;
    border-radius: 999px;
    background: #fff1f2;
    border: 2px solid rgba(230, 57, 70, 0.35);
    font-size: clamp(1.2rem, 2.6vw, 2.2rem);
    font-weight: 900;
    color: var(--text);
}

/* 押しても何も起きない操作ボタン（ためた文が空の「話す」など） */
#simple-bar .h-btn.simple-ctrl.is-disabled {
    opacity: 0.35;
    filter: grayscale(0.8);
}

#simple-bar .h-btn.simple-ctrl.simple-ctrl--cancel {
    flex: 0 1 min(420px, 40%);
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
    border-color: rgba(100, 116, 139, 0.45);
}

/* 回答パネルの文字・アイコンは大きめ */
#app[data-question="1"] .simple-grid .h-btn {
    font-size: clamp(2rem, 4.4vw, 4rem);
}

/* 既存パネルを答えにした質問は枚数が多い（4列）。文字を控えめにしてアイコンを見せる */
#app[data-question="1"] .simple-grid[data-cols="4"] .h-btn {
    font-size: clamp(1.3rem, 2.6vw, 2.4rem);
}

/* =========================================================
   設定 → 質問モード: 今すぐ質問する
   ========================================================= */
.question-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.5rem;
}

.question-btn {
    padding: 0.7rem 0.5rem;
    border-radius: 0.7rem;
    border: 1px solid #d0d7de;
    background: #fff;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
}

.question-btn:hover {
    border-color: #f4a261;
    background: #fff7e6;
}

.question-btn.active {
    background: #f4a261;
    border-color: #f4a261;
    color: #fff;
}

/* =========================================================
   設定: 質問エディタ
   ========================================================= */
#question-editor-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.question-editor-row .simple-editor-text small {
    white-space: normal;
}

.question-custom-form {
    display: grid;
    grid-template-columns: 1.6fr 1fr 0.8fr;
    gap: 0.7rem;
    align-items: end;
}

.field--full {
    grid-column: 1 / -1;
}

.question-custom-form textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.7rem;
    border: 1px solid #d0d7de;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
}

.question-custom-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.15);
}

#question-custom-add-btn {
    grid-column: 1 / -1;
    justify-self: end;
}

/* 質問の答えにするパネルを選ぶ */
.question-picker-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.question-picker-toolbar .ctrl-btn {
    min-height: 2rem;
    padding: 0.2rem 0.7rem;
    font-size: 0.82rem;
}

.question-panel-picker {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid #d0d7de;
    border-radius: 0.7rem;
    background: #fafbfc;
}

.question-picker-group {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.question-picker-head {
    flex: 0 0 5.5rem;
    padding: 0.3rem 0.4rem;
    border: 1px solid #d0d7de;
    border-radius: 0.5rem;
    background: #fff;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-dim);
    cursor: pointer;
}

.question-picker-head.active {
    background: #457b9d;
    border-color: #457b9d;
    color: #fff;
}

.question-picker-chips {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.question-picker-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem 0.15rem 0.2rem;
    border: 1px solid #d0d7de;
    border-radius: 999px;
    background: #fff;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
}

.question-picker-chip:hover {
    border-color: #457b9d;
}

.question-picker-chip.active {
    background: #e8f1f7;
    border-color: #457b9d;
    color: #1d3557;
}

.question-picker-thumb {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    background: #f1f3f5;
    font-size: 0.95rem;
}

.question-picker-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 回答パネルは文字を大きくする分、絵文字は控えめにして文字が切れないようにする */
#app[data-question="1"] .simple-grid .h-btn-emoji {
    font-size: 1.3em;
}

/* =========================================================
   設定を開いている間はポインタと滞留表示を隠す（機能も停止中）
   ========================================================= */
body.settings-open #pointer,
body.settings-open #dwell-indicator {
    display: none;
}

/* =========================================================
   お話モード
   ========================================================= */
#simple-tabs {
    flex: 0 0 clamp(52px, 9vh, 80px);
    display: flex;
    gap: 0.75rem;
}

#simple-tabs .h-btn.simple-ctrl.simple-tab {
    flex: 1 1 0;
    font-size: clamp(1.3rem, 2.4vw, 2.2rem);
    padding: 0.2rem 0.6rem;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-color: rgba(100, 116, 139, 0.35);
}

#simple-tabs .h-btn.simple-ctrl.simple-tab.active {
    background: linear-gradient(180deg, #334155 0%, #1f2933 100%);
    border-color: #1f2933;
    color: #fff;
}

/* お話モード: 続きのある言葉=青 / そのまま話す言葉=赤 / 「これで話す」=橙 / 相づち=緑 */
#app[data-talk="1"] .simple-grid .h-btn.talk-panel--branch {
    background: linear-gradient(180deg, #ffffff 0%, #e8f1fb 100%);
    border-color: rgba(69, 123, 157, 0.4);
}

#app[data-talk="1"] .simple-grid .h-btn.talk-panel--leaf {
    background: linear-gradient(180deg, #ffffff 0%, #ffecef 100%);
    border-color: rgba(230, 57, 70, 0.35);
}

#app[data-talk="1"] .simple-grid .h-btn.talk-panel--say {
    background: linear-gradient(180deg, #f4a261 0%, #e76f51 100%);
    border-color: #e76f51;
    color: #fff;
}

#app[data-talk="1"] .simple-grid .h-btn.talk-panel--aizuchi {
    background: linear-gradient(180deg, #ffffff 0%, #e6f6ea 100%);
    border-color: rgba(42, 157, 143, 0.45);
}

#app[data-talk="1"] .simple-grid .h-btn.talk-panel--partner.is-selected {
    background: linear-gradient(180deg, #334155 0%, #1f2933 100%);
    border-color: #1f2933;
    color: #fff;
}

#app[data-talk="1"] .simple-grid .h-btn {
    font-size: clamp(1.5rem, 3.2vw, 3rem);
}

/* お話モードは上部に文・タブがあり行が低いので、絵文字・アイコンは縮められるようにして文字を優先 */
#app[data-talk="1"] .simple-grid .h-btn-emoji {
    font-size: 1.1em;
    flex: 0 1 auto;
    min-height: 0;
    overflow: hidden;
}

#app[data-talk="1"] .simple-grid .h-btn-icon {
    height: 48%;
}

/* 質問中は上の質問文を低くして、回答パネルの高さを確保する */
#app[data-question="1"] #simple-panel {
    gap: 0.45rem;
}

#app[data-question="1"] #simple-message {
    flex-basis: clamp(40px, 6.5vh, 60px);
    padding-top: 0.15rem;
    padding-bottom: 0.15rem;
    border-radius: 0.9rem;
}

#app[data-question="1"] .simple-message-question {
    font-size: clamp(1.15rem, 2.4vw, 2rem);
}

/* 質問モード: 質問文の右に直前の答え */
.simple-message-question {
    min-width: 0;
}

.simple-message-answer {
    flex: 0 1 auto;
    max-width: 45%;
    padding: 0.15rem 0.8rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    border: 2px solid rgba(100, 116, 139, 0.3);
    font-size: clamp(0.9rem, 1.6vw, 1.35rem);
    font-weight: 700;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.simple-message-answer.is-current {
    background: #e6f6f2;
    border-color: rgba(42, 157, 143, 0.6);
    color: #1d6f65;
}

#simple-message.is-question:has(.simple-message-answer) {
    justify-content: space-between;
}

#app[data-talk="1"] #simple-message {
    flex-basis: clamp(72px, 13vh, 116px);
}

.simple-message-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.simple-message-chips {
    display: flex;
    gap: 0.5rem;
    overflow: hidden;
}

.simple-message-preview {
    font-size: clamp(1rem, 2vw, 1.6rem);
    font-weight: 700;
    color: #7f5539;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================================
   設定: 画面配置エディタ
   ========================================================= */
.layout-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.layout-page {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.6rem;
    border-radius: 0.9rem;
    background: #eef2f5;
}

.layout-page-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-dim);
}

.layout-grid {
    display: grid;
    gap: 4px;
    width: 100%;
}

.layout-tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 3px;
    border-radius: 0.45rem;
    border: 2px solid #d0d7de;
    background: #fff;
    cursor: grab;
    overflow: hidden;
    user-select: none;
    transition: border-color 0.12s, box-shadow 0.12s, opacity 0.12s;
}

.layout-tile:hover {
    border-color: #afb8c1;
}

.layout-tile.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(230, 57, 70, 0.3);
}

.layout-tile.dragging,
.palette-item.dragging {
    opacity: 0.35;
}

.layout-tile.is-empty {
    border-style: dashed;
    background: rgba(255, 255, 255, 0.5);
    cursor: default;
}

.layout-tile.drop-target,
.layout-palette.drop-target {
    border-color: var(--primary);
    box-shadow: inset 4px 0 0 var(--primary);
}

/* ドロップ位置: 左半分なら前、右半分なら後ろに入る */
.layout-tile.drop-before {
    box-shadow: inset 6px 0 0 var(--primary);
}

.layout-tile.drop-after {
    box-shadow: inset -6px 0 0 var(--primary);
}

.layout-thumb {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 2.2vw, 1.8rem);
    line-height: 1;
}

.layout-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.layout-thumb.is-text {
    display: none;
}

.layout-tile-name {
    flex: 0 0 auto;
    max-width: 100%;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout-thumb.is-text + .layout-tile-name {
    font-size: 0.85rem;
    white-space: normal;
    text-align: center;
}

.layout-tile-remove {
    position: absolute;
    right: 2px;
    top: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(15, 23, 42, 0.65);
    color: #fff;
    font-size: 0.7rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s;
}

.layout-tile:hover .layout-tile-remove,
.layout-tile.selected .layout-tile-remove,
.palette-item .layout-tile-remove {
    opacity: 1;
}

.layout-detail {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.8rem;
    border-radius: 0.8rem;
    border: 1px solid #eaeef2;
    background: #f6f8fa;
}

.layout-detail.is-empty {
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* 追加できるパネル: 小さなタイルを並べる（スクロールは設定画面全体の1本だけ） */
.layout-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 0.45rem;
    min-height: 4rem;
    padding: 0.4rem;
    border-radius: 0.8rem;
    border: 2px dashed transparent;
}

.palette-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    height: 84px;
    padding: 4px;
    border-radius: 0.6rem;
    border: 1px solid #d0d7de;
    background: #fff;
    cursor: grab;
    user-select: none;
}

.palette-item:hover {
    border-color: var(--primary);
}

.palette-item.is-disabled {
    opacity: 0.45;
}

.talk-editor-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 360px;
    overflow-y: auto;
}

.talk-editor-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem 0.3rem calc(0.5rem + var(--depth, 0) * 1.4rem);
    border-radius: 6px;
    cursor: pointer;
}

.talk-editor-row:hover {
    background: rgba(100, 116, 139, 0.08);
}

.talk-editor-row.is-disabled {
    opacity: 0.45;
}

.talk-editor-row input[type="checkbox"] {
    accent-color: var(--primary);
}

.talk-editor-name {
    font-weight: 600;
    white-space: nowrap;
}

.talk-editor-say {
    flex: 1;
    min-width: 0;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.talk-editor-remove {
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
}

.talk-set-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.talk-set-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid #d0d7de;
    border-radius: 0.6rem;
    cursor: pointer;
}

.talk-set-row.active {
    border-color: var(--primary);
    background: rgba(230, 57, 70, 0.05);
}

.talk-set-row input[type="radio"] {
    accent-color: var(--primary);
}

.talk-set-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.talk-set-name {
    font-weight: 700;
}

.talk-set-meta {
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.talk-set-btn {
    flex: 0 0 auto;
    padding: 0.3rem 0.7rem;
}

.talk-profile-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.7rem;
    margin-bottom: 0.6rem;
}

.talk-ai-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    margin-top: 0.6rem;
}

#talk-ai-status.is-error {
    color: var(--primary);
    font-weight: 600;
}

.talk-interview-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.talk-interview-item textarea {
    width: 100%;
    resize: vertical;
    font: inherit;
    padding: 0.4rem 0.5rem;
    border: 1px solid #d0d7de;
    border-radius: 0.5rem;
}

.talk-custom-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.7rem;
    align-items: end;
}

.field--wide2 {
    grid-column: span 2;
}

#talk-custom-add-btn {
    grid-column: 1 / -1;
    justify-self: end;
}

/* 配置プレビュー（左）と追加できるパネル（右・固定表示）を横並びにして、ドラッグ中にスクロールしなくて済むようにする */
.layout-editor {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(240px, 1fr);
    gap: 1rem;
    align-items: start;
}

.layout-editor .layout-pages {
    grid-template-columns: 1fr;
}

.layout-palette-section {
    position: sticky;
    top: 0;
    max-height: calc(min(720px, 100vh - 2rem) - 180px);
    overflow-y: auto;
}

.layout-palette-section .layout-palette {
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
}

.layout-palette-section .palette-item {
    height: 76px;
}

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

    .layout-palette-section {
        position: static;
        max-height: none;
    }
}

/* 選んだ相手のタブ */
#simple-tabs .h-btn.simple-ctrl.simple-tab.simple-tab--partner {
    background: linear-gradient(180deg, #fff8e1 0%, #ffe9a8 100%);
    border-color: rgba(214, 158, 46, 0.55);
}

#simple-tabs .h-btn.simple-ctrl.simple-tab.simple-tab--partner.active {
    background: linear-gradient(180deg, #f4a261 0%, #e76f51 100%);
    border-color: #e76f51;
    color: #fff;
}

.simple-message-chip--partner {
    background: #fff4d6;
}

.simple-message-preview.is-placeholder {
    font-weight: 400;
    color: var(--text-dim);
}

/* よく話す文（そのまま発話する候補） */
#app[data-talk="1"] .simple-grid .h-btn.talk-panel--phrase {
    background: linear-gradient(180deg, #ffffff 0%, #fff4d6 100%);
    border-color: rgba(244, 162, 97, 0.6);
    font-size: clamp(1rem, 1.9vw, 1.7rem);
}

#app[data-talk="1"] .simple-grid .h-btn.talk-panel--phrase .h-btn-text {
    white-space: normal;
    line-height: 1.25;
}

.tts-credit-note {
    display: block;
    color: var(--text-dim);
}

.tts-model-row {
    display: flex;
    gap: 0.6rem;
}

.tts-model-row select,
.tts-model-row input {
    flex: 1;
    min-width: 0;
}

.tts-model-row button {
    flex-shrink: 0;
    white-space: nowrap;
}

/* 質問の答えのパネル: 枚数に合わせてマスが増えるので、最後に足す受け口を置く */
.question-answer-dropzone {
    padding: 0.7rem;
    border: 2px dashed #c4ccd4;
    border-radius: 0.8rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
}

.question-answer-dropzone.drop-target {
    border-color: var(--primary);
    background: #fff1f2;
    color: var(--primary);
}

/* 質問モード: 上の2段と質問文を、右上の ⛶ ⚙ ◎ と同じ高さ・すき間にそろえる
   （1段目 = ⛶、2段目 = ⚙、質問文 = ◎ の横）。
   同じ強さの #app[data-question="1"] の指定より優先させるため、ファイルの最後に置く */
#app[data-question-mode="1"] #simple-panel {
    gap: var(--qa-gap);
}

#app[data-question-mode="1"] #question-mode-bar {
    grid-auto-rows: var(--qa-size);
    gap: var(--qa-gap);
}

#app[data-question-mode="1"] .question-mode-btn {
    flex-direction: row;
    gap: 0.3rem;
    padding: 0 0.45rem;
}

#app[data-question-mode="1"] .question-mode-icon {
    font-size: 1.25em;
}

/* 横に並べると文字が切れる幅では、アイコンを文字の上に小さく置く（高さはそのまま） */
@media (max-width: 1600px) {
    #app[data-question-mode="1"] .question-mode-btn {
        flex-direction: column;
        gap: 0.08rem;
        padding: 0.15rem 0.25rem;
        line-height: 1.15;
    }

    #app[data-question-mode="1"] .question-mode-icon {
        font-size: 1.15em;
        line-height: 1;
    }
}

#app[data-question-mode="1"] #simple-message {
    flex: 0 0 var(--qa-size);
}
