.ai-stage { display: grid; gap: clamp(32px, 5vw, 56px); align-items: start; }
/* タブレットの縦向きから、会話と資料を左右に並べる */
@media (min-width: 720px) { .ai-stage { grid-template-columns: 1fr 1fr; } }

/* AIチャット */
.chat { border-radius: 18px; background: #16181c; color: #e9eaec; overflow: hidden; box-shadow: 0 40px 80px -40px rgba(0, 0, 0, .5); display: flex; flex-direction: column; height: clamp(320px, 52vh, 520px); font-family: var(--font-body); letter-spacing: .02em; }
.c-top { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid rgba(255, 255, 255, .08); font-size: .8rem; flex: none; }
.c-top .logo-ai { width: 26px; height: 26px; border-radius: 8px; background: conic-gradient(from 200deg, #7aa2ff, #b07cff, #ff8fb1, #7aa2ff); flex: none; }
.c-top .plan { margin-left: auto; font-size: .75rem; color: rgba(255, 255, 255, .55); border: 1px solid rgba(255, 255, 255, .2); border-radius: 99px; padding: 1px 10px; }
.c-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; }
.c-log .hello { color: rgba(255, 255, 255, .5); font-size: .82rem; text-align: center; margin: auto 0; }
.msg { max-width: 86%; font-size: .8rem; line-height: 1.75; padding: 9px 13px; border-radius: 14px; animation: rise .35s cubic-bezier(.2, .8, .2, 1) both; position: relative; }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.msg.me { align-self: flex-end; background: #2b3a55; border-bottom-right-radius: 4px; }
.msg.me .k { display: block; font-size: .75rem; color: rgba(255, 255, 255, .55); margin-bottom: 2px; }
.msg.ai { align-self: flex-start; background: rgba(255, 255, 255, .06); border-bottom-left-radius: 4px; }
.msg.ai.typing { color: rgba(255, 255, 255, .5); letter-spacing: .3em; }
.msg .sent { display: inline-block; margin-top: 6px; font-size: .75rem; font-weight: 700; color: #fff; background: #d4442c; border-radius: 99px; padding: 0 8px; animation: pop .4s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes pop { from { transform: scale(0); } }
.c-in { flex: none; display: flex; align-items: center; gap: 10px; margin: 0 14px 14px; padding: 10px 12px 10px 16px; border-radius: 14px; background: rgba(255, 255, 255, .06); font-size: .78rem; color: rgba(255, 255, 255, .4); }
.c-in .go { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, .14); display: grid; place-items: center; }
.c-in .go svg { width: 14px; fill: #fff; }
.c-in.flash { animation: inFlash .7s ease; }
@keyframes inFlash { 30% { background: rgba(122, 162, 255, .35); } }
.cloud { display: flex; align-items: center; gap: 8px; font-size: .75rem; color: rgba(255, 255, 255, .55); padding: 0 18px 12px; flex: none; }
.cloud svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.cloud b { font-weight: 400; font-family: var(--mono); color: rgba(255, 255, 255, .7); white-space: nowrap; flex: none; }
/* 会話の欄が狭いときは、契約の表示を次の行に送る（語の途中では折り返さない） */
.c-top { flex-wrap: wrap; row-gap: 4px; white-space: nowrap; }
.cloud.hot { color: #f07468; }
.cloud.hot b { color: #f07468; }

/* 資料の山 */
.deck-wrap { display: flex; flex-direction: column; gap: 20px; }
.deck-head { display: flex; justify-content: space-between; align-items: baseline; font-size: .86rem; color: var(--ink-2); }
.deck-head b { font-family: var(--mono); font-weight: 400; }
/* 資料は同じ升目に重ね、いちばん長い資料に合わせて高さが伸びるようにする（文字がはみ出さない） */
.deck { position: relative; display: grid; min-height: 250px; perspective: 1000px; }
.deck[hidden] { display: none; }
.doc { grid-area: 1 / 1; position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 18px 40px -26px rgba(0, 0, 0, .4); transition: transform .55s cubic-bezier(.3, .7, .2, 1), opacity .45s; touch-action: pan-y; user-select: none; cursor: grab; }
.doc.under { transform: translateY(12px) scale(.95); pointer-events: none; box-shadow: none; }
.doc.under2 { transform: translateY(24px) scale(.9); pointer-events: none; box-shadow: none; }
.doc.under > *, .doc.under2 > * { opacity: 0; }
.doc > * { transition: opacity .35s .15s; }
.doc.dragging { transition: none; cursor: grabbing; }
.doc.to-ai { transform: translate(-30%, -120%) scale(.4) rotate(-6deg); opacity: 0; }
.doc.to-keep { transform: translate(30%, 70%) scale(.5) rotate(8deg); opacity: 0; }
.doc .kind { font-family: var(--mono); font-size: .75rem; letter-spacing: .15em; color: var(--accent); }
.doc .ttl { font-family: var(--font-head); font-weight: 700; font-size: 1.12rem; line-height: 1.5; }
.doc .ex { font-family: var(--mono); font-size: .8rem; line-height: 1.8; color: var(--ink-2); background: var(--bg-2); border-radius: 8px; padding: 10px 12px; margin-top: auto; word-break: break-all; }
.doc .stamp { position: absolute; top: 18px; right: 18px; font-family: var(--font-head); font-weight: 700; font-size: .9rem; border: 2px solid; border-radius: 8px; padding: 2px 10px; transform: rotate(8deg); opacity: 0; transition: opacity .15s; }
.doc .stamp.in { color: #2f6fde; }
.doc .stamp.out { color: var(--ok); left: 18px; right: auto; transform: rotate(-8deg); }
.choose { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choose .btn { width: 100%; padding-inline: 12px; gap: 6px; letter-spacing: .04em; white-space: nowrap; -webkit-tap-highlight-color: transparent; }
.choose .btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.fb { min-height: 6.5em; border-top: 1px solid var(--line); padding-top: 18px; }
.fb .v { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; }
.fb .v.ok { color: var(--ok); }
.fb .v.ng { color: var(--danger); }
.fb p { color: var(--ink-2); font-size: .92rem; margin: 0 0 12px; }
.fb .v:focus { outline: none; }
.tray { display: flex; gap: 6px; flex-wrap: wrap; min-height: 22px; }
.tray i { width: 18px; height: 22px; border-radius: 3px; background: var(--ok-soft); border: 1px solid var(--ok); animation: pop .35s cubic-bezier(.3, 1.6, .5, 1) both; }
.tray i.bad { background: var(--danger-soft); border-color: var(--danger); }
.tray-lbl { font-size: .78rem; color: var(--ink-3); }
.ai-result:empty { display: none; }
.ai-result { margin-top: 8px; }
.ai-result .big { font-family: var(--font-head); font-weight: 700; font-size: clamp(1.4rem, 3vw, 1.9rem); line-height: 1.5; margin-bottom: 12px; }
.ai-result .big:focus { outline: none; }
.review { list-style: none; margin: 20px 0 0; padding: 0; }
.review li { display: grid; grid-template-columns: 1.3em 5.6em 1fr; gap: 12px; margin: 0; padding: 12px 0; border-top: 1px solid var(--line); font-size: .9rem; }
/* 正しく仕分けたかを、行の頭の印でひと目で分かるようにする */
.review .mk { font-weight: 700; text-align: center; }
.review .mk.ok { color: var(--ok); }
.review .mk.ng { color: var(--danger); }
.review li.ng { background: linear-gradient(90deg, var(--danger-soft), transparent 70%); }
.ai-result .rule { margin: 18px 0 0; padding: 14px 18px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 12px 12px 0; line-height: 1.8; color: var(--ink-2); max-width: var(--text); }
.ai-result .rule b { color: var(--ink); }
.review li:last-child { border-bottom: 1px solid var(--line); }
.review .a { font-family: var(--font-head); font-weight: 700; font-size: .82rem; white-space: nowrap; }
.review .a.in { color: #2f6fde; }
.review .a.out { color: var(--ok); }
.review .miss { color: var(--danger); font-size: .78rem; margin-left: 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .review .a.in, :root:not([data-theme="light"]) .doc .stamp.in { color: #7aa2ff; } }
:root[data-theme="dark"] .review .a.in, :root[data-theme="dark"] .doc .stamp.in { color: #7aa2ff; }
@media (prefers-reduced-motion: reduce) { .doc, .msg, .tray i, .msg .sent { transition: none; animation: none; } }
@media (hover: hover) { .doc.top:hover { box-shadow: 0 22px 44px -24px rgba(0, 0, 0, .45); } }
@media (pointer: coarse) { .fb .btn, .ai-result .btn { min-height: 44px; } }

/* スマートフォン：会話を低くし、会話・資料・選ぶボタンが一つの画面に収まるようにする */
@media (max-width: 719px) {
  .ai-stage { gap: 16px; }
  .chat { height: clamp(172px, calc(100svh - 440px), 280px); border-radius: 16px; }
  .c-top { padding: 10px 14px; }
  .c-top .logo-ai { width: 22px; height: 22px; border-radius: 7px; }
  .c-log { padding: 12px 14px; gap: 8px; }
  .msg { max-width: 92%; padding: 7px 12px; }
  .cloud { padding: 0 14px 8px; }
  .c-in { margin: 0 10px 10px; padding: 6px 8px 6px 14px; }
  .c-in .go { width: 26px; height: 26px; }
  .deck-wrap { gap: 12px; }
  .deck { min-height: clamp(168px, 28svh, 230px); }
  .doc { padding: 16px 18px; gap: 8px; }
  .doc .ttl { font-size: 1.04rem; }
  .doc.to-ai { transform: translateY(-160%) scale(.4); }
}
/* 画面の高さが足りないときは、判定を資料と選ぶボタンの位置に重ねて出し、会話を画面に残したまま読めるようにする */
@media (max-width: 719px), (max-height: 520px) {
  .deck-wrap { display: grid; grid-template-columns: minmax(0, 1fr); }
  /* すべて1列目に置く（列を指定しないと、判定と重なる行の要素が暗黙の2列目に押し出される） */
  .deck-wrap > * { grid-column: 1; }
  .deck-head { grid-row: 1; }
  .deck { grid-row: 2; }
  .choose { grid-row: 3; }
  .fb { grid-row: 2 / 4; position: relative; z-index: 3; min-height: 0; border-top: 0; padding-top: 0; pointer-events: none; }
  .fb:not(:empty) { pointer-events: auto; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; box-shadow: 0 18px 40px -26px rgba(0, 0, 0, .4); animation: rise .3s cubic-bezier(.2, .8, .2, 1) both; }
  /* 片手でも親指が届くよう、次へ進むボタンは判定の幅いっぱいにする */
  .fb .btn { align-self: stretch; min-height: 48px; font-size: .95rem; }
  .deck-wrap > :nth-child(5) { grid-row: 4; }
  .ai-result { grid-row: 5; }
}
@media (prefers-reduced-motion: reduce) { .fb:not(:empty) { animation: none; } }
/* 幅の狭い画面では、飾りの入力欄を省いて会話の行を残す */
@media (max-width: 359px) {
  .c-in { display: none; }
  .chat { height: clamp(160px, calc(100svh - 420px), 280px); }
  .doc { padding: 14px 16px; }
  .doc .ttl { font-size: 1rem; }
  .doc .ex { font-size: .75rem; line-height: 1.7; padding: 8px 10px; }
}
/* 横向きのスマートフォン：会話を画面の高さに合わせ、資料の側を広くとり、題名と抜粋の行数を減らして、資料と選ぶボタンが画面の高さに収まるようにする */
@media (min-width: 720px) and (max-height: 520px) {
  .ai-stage { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; }
  .chat { height: calc(100svh - 84px); min-height: 220px; }
  .c-top { padding: 10px 14px; }
  .c-log { padding: 12px 14px; gap: 8px; }
  .cloud { padding: 0 14px 8px; gap: 6px; }
  .c-in { margin: 0 10px 10px; padding: 6px 8px 6px 14px; }
  .deck-wrap { gap: 8px; }
  .deck-head { line-height: 1.6; }
  .deck { min-height: 0; }
  .doc { padding: 12px 18px; gap: 4px; }
  .doc .ttl { font-size: 1rem; }
  .doc .ex { padding: 8px 12px; line-height: 1.7; }
  .choose .btn { padding-block: 10px; }
}

.checks { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
@media (min-width: 760px) { .checks { grid-template-columns: repeat(3, 1fr); } }
.checks div { background: var(--bg); padding: clamp(22px, 3vw, 32px); }
.checks .n { font-family: var(--mono); font-size: .8rem; color: var(--accent); }
.checks h3 { font-size: 1.05rem; margin: 6px 0 8px; }
.checks p { color: var(--ink-2); font-size: .92rem; }
/* 段階表示の「次へ」は、二列の並びの下に横いっぱいで置く */
.ai-stage > .steps-nav { grid-column: 1 / -1; margin-top: 0; }
