/* トンツー電報: 生成りの用紙・墨・朱1色、紙テープ(主役)と真鍮の電鍵。SPEC 6章 */
:root {
  --paper: #F2EADB; --tape: #FBF7EE; --ink: #222; --shu: #C23B22; --shu-dark: #A3301B;
  --brass: #B08A3E; --wood: #6B3A22; --gray: #8A8273; --line: #CFC4AE;
  --focus: #C23B22; --ad-line: #B5A98F; --ad-text: #6f6758;
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, Menlo, monospace;
  --gothic: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
html { background: var(--paper); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.6 var(--gothic); overflow-x: clip; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--ink); }

.page { max-width: 880px; margin: 0 auto; padding: 0 12px; min-height: 100dvh; display: flex; flex-direction: column; gap: 8px; }

/* 見出しの帯 */
.bar { height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.brand { margin: 0; font: 600 16px/1 var(--mincho); letter-spacing: .06em; white-space: nowrap; border-bottom: 2px solid var(--shu); padding-bottom: 4px; }
.bar-tools { display: flex; align-items: center; gap: 6px; }
.seg { display: flex; border: 1px solid var(--ink); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 0 8px; font-size: 13px; min-height: 44px; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg button:disabled { opacity: .45; cursor: default; }
@media (max-width: 419px) { .seg .pre { display: none; } }
.icon-btn { white-space: nowrap; border: 1px solid var(--ink); background: transparent; border-radius: 4px; min-height: 44px; min-width: 44px; padding: 0 8px; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
.icon-btn:disabled { opacity: .45; cursor: default; }

/* お題の札(電報の用紙) */
.ticket { position: relative; height: 104px; border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: -5px; background: var(--paper); padding: 6px 48px 8px; text-align: center; overflow: hidden; }
.ticket-label { margin: 0; font: 11px/1 var(--mincho); letter-spacing: .3em; color: var(--gray); display: flex; align-items: center; gap: 10px; }
.ticket-label::before, .ticket-label::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.stamp { position: absolute; right: 12px; top: 14px; width: 26px; height: 34px; color: var(--shu); font-family: var(--mincho); }
.ticket-body { height: 80px; display: flex; flex-direction: column; align-items: center; justify-content: center; animation: swap .15s ease-out; }
.ticket-body.swap { animation: none; }
@keyframes swap { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ticket h1, .ticket .headline { margin: 0; font: 600 clamp(17px, 5vw, 22px)/1.3 var(--mincho); letter-spacing: .04em; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket .topic { margin: 0; font: 600 44px/1.05 var(--mincho); letter-spacing: .12em; }
.ticket .topic.ok::after { content: " ✓"; color: var(--ink); font-size: 28px; }
.ticket .topic.ng::after { content: " ✗"; color: var(--shu); font-size: 28px; }
.ticket .code { margin: 2px 0 0; font: 15px/1.2 var(--mono); letter-spacing: .08em; color: #444; }
.ticket .count { position: absolute; left: 14px; top: 14px; font: 12px/1 var(--mono); color: var(--gray); font-variant-numeric: tabular-nums; }
.ticket .sub { margin: 4px 0 0; font-size: 13px; color: #555; }
.peek { margin-top: 6px; border: 1px solid var(--ink); background: transparent; border-radius: 4px; font-size: 13px; padding: 0 12px; min-height: 44px; user-select: none; -webkit-user-select: none; touch-action: none; }

/* 紙テープ: 画面の端から端まで */
.tape-wrap { position: relative; width: 100vw; margin-left: calc(50% - 50vw); height: 96px; }
.tape { display: block; width: 100%; height: 96px; }
.clamp { position: absolute; left: 0; top: -12px; width: 34px; height: 120px; z-index: 1; filter: drop-shadow(1px 2px 2px rgba(0,0,0,.25)); }
.tape .bg { fill: var(--tape); }
.tape .edge { stroke: rgba(60,40,10,.18); stroke-width: 1; }
.tape .tick { stroke: var(--gray); stroke-width: 1; opacity: .55; }
.tape .mark { fill: var(--ink); }
.tape .pend { fill: var(--ink); opacity: .55; }
.tape .ch { font: 22px/1 var(--mincho); fill: var(--ink); text-anchor: middle; }
.tape .ch2 { font: 15px/1 var(--mincho); fill: #666; text-anchor: middle; }
.tape .ch.bad { fill: var(--shu); }
.tape .badline { stroke: var(--shu); stroke-width: 2.5; }
.tape .sep { stroke: var(--line); stroke-width: 1; }
.tape .head { stroke: var(--shu); stroke-width: 1; opacity: .35; stroke-dasharray: 3 3; }
.tape .note { font: 12px/1 var(--gothic); fill: var(--shu); }
.tape .fresh { animation: ink .1s ease-out; }
@keyframes ink { from { opacity: .2; } to { opacity: 1; } }

/* 計器 */
.meters { height: 32px; display: flex; justify-content: center; gap: 10px; }
.meter { margin: 0; border: 1px solid var(--ink); padding: 0 4px 0 10px; display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.meter b { font: 500 16px/1 var(--mono); font-variant-numeric: tabular-nums; min-width: 3.2ch; text-align: right; }
.q { border: 1px solid var(--gray); border-radius: 50%; background: transparent; width: 22px; min-height: 22px; height: 22px; padding: 0; font-size: 12px; line-height: 1; color: var(--gray); position: relative; }
.q::before { content: ""; position: absolute; inset: -11px; }
.tip { margin: -4px auto 0; font-size: 12px; color: #555; text-align: center; }
.warn { margin: 0; text-align: center; font-size: 13px; color: var(--shu); }

/* 電鍵 */
.key-area { flex: 1 1 auto; min-height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; border-radius: 8px; outline: none; }
.key-area svg { width: min(100%, 440px); height: auto; max-height: 100%; flex: 0 1 auto; }
.key-area.off { cursor: default; opacity: .55; }
.key-hint { margin: 0; font-size: 12px; color: var(--gray); }
.lever { transform-origin: 200px 96px; transition: transform .03s linear; }
.down .lever { transform: rotate(1.6deg); }
.lamp { fill: #9e8f78; }
.lamp.on { fill: var(--shu); filter: drop-shadow(0 0 6px #ff6a3d); }

/* 場面のボタン */
.actions { min-height: 52px; display: flex; gap: 10px; justify-content: center; align-items: center; }
.btn { white-space: nowrap; border-radius: 4px; padding: 0 12px; min-height: 48px; font: 600 17px/1 var(--mincho); letter-spacing: .08em; flex: 1 1 0; max-width: 260px; }
.btn.primary { background: var(--shu); color: #fff; border: 1px solid var(--shu-dark); }
.btn.ghost { background: var(--paper); border: 1px solid var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.text-btn { border: 0; background: transparent; text-decoration: underline; font-size: 13px; padding: 0 8px; }

/* みんなでの名前・答え合わせ */
.panel { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 4px 0; flex: 1 1 auto; overflow: auto; }
.panel .names { list-style: none; padding: 0; margin: 0; width: min(100%, 360px); display: grid; gap: 6px; }
.panel .names li { display: flex; gap: 6px; align-items: center; }
.panel .names input { flex: 1; font: 16px var(--gothic); border: 1px solid var(--ink); background: var(--tape); padding: 0 10px; border-radius: 4px; }
.panel .names button { border: 1px solid var(--gray); background: transparent; border-radius: 4px; min-width: 44px; }
.panel p { margin: 0; font-size: 13px; color: #555; text-align: center; }
.panel .btn { flex: 0 0 auto; min-width: 160px; }
@media (max-width: 419px) {
  .actions { gap: 6px; }
  .actions .btn { font-size: 15px; letter-spacing: .02em; padding: 0 8px; }
}
.btn.quit { flex: 0 0 auto; padding: 0 14px; font-size: 15px; color: #555; border-color: var(--gray); }
.answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(52px, 88px)); justify-content: center; gap: 8px; width: min(100%, 560px); margin: auto 0; }
.answers.many { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin: 0; }
.answers.many .ans { min-height: 44px; font-size: 18px; }
.panel:has(> .answers) { flex: 1 1 0; min-height: 0; max-height: calc(100dvh - 340px); }
.ans { min-height: 64px; border: 1px solid var(--ink); background: var(--paper); border-radius: 4px; font: 600 22px/1 var(--mincho); }
.ans.right { background: var(--ink); color: var(--paper); }
.ans.wrong { border-color: var(--shu); color: var(--shu); text-decoration: line-through; }
.ans:disabled { cursor: default; }
.ans:disabled:not(.right):not(.wrong) { opacity: .45; }
.hand { margin: 0; width: min(100%, 420px); display: grid; gap: 4px; }
.hand div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 4px 2px; }
.hand dt { font-size: 13px; color: #555; }
.hand dd { margin: 0; font: 16px var(--mincho); text-align: right; }
.hand dd small { font-size: 12px; color: var(--gray); }
.hand .next dd { color: var(--shu); font-weight: 600; }
.ticket-lamp { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #8a6a2a; background: #e9dfcc; vertical-align: middle; margin-right: 14px; }
.ticket-lamp.on { background: var(--shu); box-shadow: 0 0 10px var(--shu); }
.turnlog { margin-top: 6px; }
.turnlog li > div { min-width: 0; }
.turnlog .who { margin: 0; font-size: 13px; }
.turnlog .who span { color: var(--gray); margin-left: 6px; }
.turnlog .play { min-width: 44px; min-height: 44px; border: 1px solid var(--ink); background: var(--paper); border-radius: 50%; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 520px; }
.chip { border: 1px solid var(--ink); background: var(--paper); border-radius: 22px; padding: 0 16px; font-size: 15px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.chip .star { color: var(--shu); margin-left: 4px; }

/* 結果 */
.result { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 24px; }
#result-body { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.result h2 { margin: 0; font: 600 20px/1.3 var(--mincho); }
.result .total { font: 600 40px/1 var(--mincho); margin: 0; font-variant-numeric: tabular-nums; }
.result .total small { font-size: 14px; font-weight: 400; margin-left: 4px; }
.result .best { margin: 0; font-size: 13px; color: #555; }
.qlist { list-style: none; padding: 0; margin: 0; width: min(100%, 560px); display: grid; gap: 6px; }
.qlist li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; background: var(--tape); border-top: 1px solid rgba(60,40,10,.12); border-bottom: 1px solid rgba(60,40,10,.12); padding: 4px 10px; }
.qlist svg { width: 100%; height: 44px; display: block; }
.tape.mini .ch { font-size: 14px; }
.qlist .pt { font: 16px var(--mono); font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; }
.ranking { list-style: none; padding: 0; margin: 0; width: min(100%, 360px); display: flex; flex-direction: column-reverse; gap: 6px; }
.ranking li { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 4px; font: 17px var(--mincho); animation: rise .35s ease-out both; }
.ranking li b { font: 18px var(--mono); font-variant-numeric: tabular-nums; }
.ranking li.first { color: var(--shu); font-weight: 600; font-size: 20px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.row-btns { display: flex; gap: 10px; width: min(100%, 440px); justify-content: center; }
.result .ad-slot.inline { margin-top: 12px; }

/* テスト用 */
.test-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; font-size: 11px; color: var(--gray); border: 1px dashed var(--gray); padding: 4px; }
.test-box button { min-height: 32px; font-size: 12px; border: 1px solid var(--gray); background: transparent; border-radius: 4px; }

/* 足もと(遊ぶ面の外) */
.foot { margin-top: 16px; padding: 12px 0 24px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.card-link { display: grid; gap: 2px; padding: 10px 14px; border: 1px solid var(--ink); text-decoration: none; max-width: 420px; }
.card-link b { font: 600 15px var(--mincho); }
.card-link span { font-size: 12px; color: #555; }
.foot-line { margin: 0; display: flex; gap: 16px; font-size: 12px; color: #555; }

/* 符号表: スマホは上から重なるシート(電鍵とボタンは隠さない) */
.table-panel { position: fixed; left: 0; right: 0; top: 48px; max-height: min(50vh, 250px); overflow: auto; background: var(--paper); border-bottom: 1px solid var(--ink); box-shadow: 0 6px 16px rgba(0,0,0,.12); padding: 6px 12px 10px; z-index: 5; display: none; }
.table-panel.open { display: block; }
.table-head { display: flex; justify-content: space-between; align-items: center; font: 600 14px var(--mincho); }
.code-list { list-style: none; padding: 0; margin: 4px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 2px 8px; }
.code-list button { width: 100%; min-height: 44px; border: 0; background: transparent; display: flex; gap: 8px; align-items: center; padding: 0 4px; text-align: left; border-radius: 3px; }
.code-list button::before { content: ""; position: absolute; }
.code-list .k { font: 16px var(--mincho); min-width: 1.4em; }
.code-list .c { font: 13px var(--mono); letter-spacing: .06em; color: #333; white-space: nowrap; }
.code-list button.mark .k, .code-list button.mark .c { color: var(--shu); font-weight: 700; }
.code-list button.playing { background: rgba(194,59,34,.1); }

/* 設定: 下から重なるシート */
.sheet { position: fixed; inset: auto 0 0 0; background: var(--paper); border-top: 1px solid var(--ink); box-shadow: 0 -6px 16px rgba(0,0,0,.12); z-index: 6; }
.sheet-inner { max-width: 520px; margin: 0 auto; padding: 8px 16px 20px; display: grid; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 14px; border: 0; padding: 0; margin: 0; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field legend { padding: 0; margin-bottom: 4px; }
.field label { margin-right: 14px; display: inline-flex; align-items: center; gap: 4px; }
.field input[type="range"] { width: 100%; accent-color: var(--shu); }
.field output { font: 13px var(--mono); color: #555; }

@media (min-width: 720px) {
  .page { padding: 0 24px; gap: 12px; }
  .bar { height: 56px; margin-top: 8px; }
  .brand { font-size: 22px; }
  .ticket { height: 150px; padding: 10px 64px; max-width: 640px; width: 100%; align-self: center; }
  .ticket-body { height: 116px; }
  .ticket .topic { font-size: 56px; }
  .ticket h1, .ticket .headline { font-size: 28px; }
  .stamp { width: 32px; height: 42px; right: 18px; top: 22px; }
  .tape-wrap, .tape { height: 110px; }
  .clamp { height: 134px; width: 40px; }
  .key-area { min-height: 230px; }
}
/* 1280px 以上: 符号表を右端の細い列に常に出す(中央の列と重ならない幅) */
@media (min-width: 1280px) {
  .table-panel { display: block; left: auto; right: 0; top: 0; bottom: 0; max-height: none; width: 200px; border-bottom: 0; border-left: 1px solid var(--ink); box-shadow: none; background: rgba(242,234,219,.92); padding-top: 72px; }
  .table-panel .text-btn { display: none; }
  .code-list { grid-template-columns: 1fr; }
  #open-table { display: none; }
  /* 紙テープは右の符号表の列の上を通して端から端まで(審査1回目 #13)。表はテープの下から2列で始め、隠れないようにする(審査2回目 #5) */
  .tape-wrap { z-index: 6; }
  .table-panel { padding-top: 352px; }
  .table-panel .code-list { grid-template-columns: 1fr 1fr; gap: 0 4px; }
  .table-panel .code-list button { min-height: 30px; padding: 0 2px; gap: 4px; }
  .table-panel .code-list .k { font-size: 15px; min-width: 1.2em; }
  .table-panel .code-list .c { font-size: 12px; letter-spacing: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .lever { transition: none; }
}
