/* 全体の枠（持ち主は ux C） */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; display: flex; flex-direction: column; background: #3a2416; color: #f2eadb; font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", sans-serif; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
[hidden] { display: none !important; }
button { font: inherit; font-size: 14px; border: 0; border-radius: 6px; background: #efe4cc; color: #2a2017; box-shadow: 0 2px 0 #0007; min-height: 44px; min-width: 44px; padding: 0 8px; touch-action: manipulation; cursor: pointer; }
button:active { transform: translateY(2px); box-shadow: none; }

/* ヘッダー。左の48pxは「作った話と感想」の場所 */
.top { flex: none; height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.feedback-space { width: 44px; flex: none; }
.top h1 { flex: 1; min-width: 0; margin: 0; font-size: 14px; font-weight: 600; text-align: center; opacity: .8; white-space: nowrap; overflow: hidden; font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; }
.top button { background: #0006; color: #f2eadb; box-shadow: none; }
.top svg { display: block; margin: auto; }
#btn-sound[data-muted="0"] .slash, #btn-sound[data-muted="1"] .waves { display: none; }
#btn-lang { white-space: nowrap; font-size: 13px; }
#btn-lang b { text-decoration: underline; text-underline-offset: 3px; }
#save-note { margin: 0; padding: 0 8px 2px; text-align: center; font-size: 12px; color: #ffe2b0; }
#save-note:empty { display: none; }

/* 筒の画面 */
.drum-screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#drum-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; cursor: grab; }
#drum-stage:active { cursor: grabbing; }
#drum-stage.is-loading #hint { visibility: hidden; }
.drum-foot { flex: none; height: 28px; display: flex; align-items: center; justify-content: center; gap: 12px; white-space: nowrap; overflow: hidden; }
#readout { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
/* 今の筒の帯が自分の帯の時の、小さな紙の札（届いた帯の紙と同じ色と字） */
#owner { flex: none; margin: 0; padding: 1px 8px 2px; border-radius: 2px; background: linear-gradient(#f4ecda, #e6d9bc); color: #2a2017; box-shadow: 0 1px 3px #0009; transform: rotate(-1.2deg); font-size: 13px; font-weight: 700; line-height: 1.35; font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; }
@media (max-width: 380px) { .drum-foot { gap: 8px; } }
#need-frames { margin: 0; font-size: 12px; color: #ffe2b0; }
#need-frames:empty { display: none; }
#keys { display: none; margin: 0; font-size: 12px; opacity: .7; }
#notice { position: absolute; z-index: 2; left: 0; right: 0; bottom: 6px; margin: 0; text-align: center; font-size: 14px; text-shadow: 0 1px 3px #000; pointer-events: none; }
#toast { position: absolute; z-index: 4; left: 50%; bottom: 30px; transform: translateX(-50%); margin: 0; padding: 4px 14px; border-radius: 999px; background: #000a; font-size: 14px; white-space: nowrap; pointer-events: none; }
#hint { position: absolute; z-index: 2; left: 0; right: 0; bottom: 30px; display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; font-size: 16px; font-weight: 600; text-shadow: 0 1px 3px #000, 0 0 8px #000; }
.hint-hand { animation: flick 1.6s infinite cubic-bezier(.5, 0, .8, .6); overflow: visible; }
.hint-hand .tail { animation: tail 1.6s infinite; }
@keyframes flick { 0% { transform: translateX(70px); opacity: 0; } 15% { opacity: 1; } 65% { transform: translateX(-64px); opacity: 1; } 85%, 100% { transform: translateX(-92px); opacity: 0; } }
@keyframes tail { 0%, 22% { opacity: 0; } 50%, 70% { opacity: .75; } 90%, 100% { opacity: 0; } }
/* 「もっと速く」: 同じ手の絵が、短い間に3回はじく */
#hint.faster .hint-touch, #hint.faster .hint-mouse, #hint:not(.faster) .hint-faster { display: none; }
#hint.faster .hint-hand { animation: flick3 2.2s infinite linear; }
#hint.faster .hint-hand .tail { animation: tail3 2.2s infinite linear; }
@keyframes flick3 { 0%, 25%, 50% { transform: translateX(46px); opacity: 0; } 4%, 29%, 54% { transform: translateX(34px); opacity: 1; } 17%, 42% { transform: translateX(-52px); opacity: 1; } 67% { transform: translateX(-52px); opacity: 1; } 22%, 47% { transform: translateX(-70px); opacity: 0; } 78%, 99.900% { transform: translateX(-70px); opacity: 0; } 100% { transform: translateX(46px); opacity: 0; } }
@keyframes tail3 { 0%, 7%, 21%, 32%, 46%, 57%, 100% { opacity: 0; } 14%, 39%, 64%, 70% { opacity: .8; } 78% { opacity: 0; } }
#broken { position: absolute; z-index: 3; left: 24px; right: 24px; top: 28%; max-width: 420px; margin: 0 auto; padding: 16px; background: #1e130cf2; border-radius: 10px; display: flex; flex-direction: column; gap: 10px; text-align: center; }

/* 届いた帯: 筒の手前に置いた紙の帯。位置は舞台の下端（数の行のすぐ上）が基準で、筒の位置には合わせない。指の入力は取らない */
#arrived { --cell: min(54px, calc((100vw - 44px) / 6)); position: absolute; z-index: 2; left: 50%; bottom: 8px; width: max-content; max-width: calc(100% - 16px); transform: translateX(-50%) rotate(-1.2deg); padding: 5px 8px 8px; border-radius: 2px; background: linear-gradient(#f4ecda, #e6d9bc); color: #2a2017; box-shadow: 0 1px 0 #fff8 inset, 0 2px 3px #0007, 0 10px 18px #0008; pointer-events: none; transition: opacity .22s ease-in, transform .22s ease-in; }
#arrived p { margin: 0 0 4px; text-align: center; font-size: 14px; font-weight: 700; line-height: 1.3; white-space: nowrap; font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; }
#arrived-film { display: flex; justify-content: center; }
#arrived-film canvas { width: var(--cell); height: var(--cell); border: solid #b5a480; border-width: 1px 1px 1px 0; }
#arrived-film canvas:first-child { border-left-width: 1px; }
#arrived.is-leaving { opacity: 0; transform: translateX(-50%) translateY(26px) rotate(-1.2deg); }
#drum-stage[data-arrived="1"] #hint { bottom: calc(var(--arrived-h, 80px) + 18px); }
@media (min-width: 900px) { #arrived { --cell: 64px; } }
@media (max-height: 700px) {
  #arrived { --cell: 44px; bottom: 6px; padding: 3px 6px 6px; }
  #arrived p { margin-bottom: 2px; font-size: 13px; }
  #drum-stage[data-arrived="1"] #hint { bottom: calc(var(--arrived-h, 70px) + 12px); }
  #drum-stage[data-arrived="1"] .hint-hand { height: 42px; width: 42px; }
}

/* 描く画面の上に重ねる誘い。指の入力は取らない */
#draw-tip { position: fixed; z-index: 5; transform: translate(-50%, -50%); width: max-content; max-width: calc(100% - 16px); margin: 0; padding: 3px 10px; border-radius: 8px; background: #1e130ce6; font-size: 12px; line-height: 1.4; text-align: center; pointer-events: none; }
#draw-tip span { display: block; }
/* 360幅では横の余白を詰めて、お手本の1行を2行以内にする（3行になると帯に重なる） */
@media (max-width: 380px) { #draw-tip { max-width: calc(100% - 4px); padding: 3px 5px; } }
#draw-ghost { position: fixed; z-index: 5; transform: translate(-50%, -50%); margin: 0; color: #8a7d68aa; font-size: 20px; white-space: nowrap; pointer-events: none; }

/* 下の帯状の場所 */
.bar { flex: none; display: flex; gap: 6px; align-items: center; width: 100%; max-width: 560px; margin: 0 auto; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.bar button { height: 52px; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; line-height: 1.2; padding: 0 3px; white-space: nowrap; overflow: hidden; }
.bar button svg { flex: none; }
#btn-strips, #btn-new { width: 80px; }
#btn-send { width: 60px; }
.bar #btn-flip { flex: 1; min-width: 128px; flex-direction: row; gap: 6px; font-size: 14px; background: #c79b55; color: #1f160c; font-weight: 700; }
#btn-flip[data-to="draw"] .to-drum, #btn-flip[data-to="drum"] .to-draw { display: none; }
#btn-flip.lift { animation: lift .5s ease-out 1; }
@keyframes lift { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); box-shadow: 0 8px 6px #0008; } }
body[data-screen="draw"] #btn-new { display: none; }
body[data-received="1"] #btn-new { width: 92px; }
@media (max-width: 380px) {
  .bar { gap: 5px; }
  #btn-strips, #btn-new { width: 72px; }
  body[data-received="1"] #btn-new { width: 86px; }
  #btn-send { width: 56px; }
  .bar button { font-size: 11px; padding: 0 2px; }
  .bar #btn-flip { font-size: 13px; min-width: 0; gap: 4px; }
  .top h1 { font-size: 13px; }
}

/* シート。ヘッダーは隠さない */
#sheet { position: fixed; inset: 48px 0 0; background: #0007; display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { width: 100%; max-width: 560px; max-height: 100%; overflow-y: auto; background: #2c2018; border-radius: 14px 14px 0 0; box-shadow: 0 -4px 16px #0008; padding: 12px 14px calc(18px + env(safe-area-inset-bottom)); touch-action: pan-y; overscroll-behavior: contain; animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }
/* 長い一覧を下まで送っても「閉じる」に届くように、見出しの行は上に残す（板が画面いっぱいだと、板の外を押して閉じる場所がない） */
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -12px; z-index: 1; margin: -12px -14px 0; padding: 12px 14px 6px; background: #2c2018; }
.sheet { scroll-padding-top: 64px; }
.sheet h2 { font-size: 16px; margin: 0; }
.sheet h3 { font-size: 14px; margin: 12px 0 6px; }
.sheet p { font-size: 14px; margin: 8px 0; text-wrap: balance; word-break: auto-phrase; }
#draw-tip span, #broken p { text-wrap: balance; }
.sheet .small { font-size: 12px; opacity: .8; }
.sheet .count { font-weight: 700; margin-bottom: 0; }
.send-status:empty { display: none; }
/* 写せた時は、緑の帯と印で出す */
.sheet .send-status.is-done { padding: 8px 10px; border-radius: 6px; background: #2f6b45; color: #fff; font-weight: 700; text-align: center; }
.sheet-buttons button.is-done, .sheet button.primary.is-done { background: #2f6b45; color: #fff; }
.sheet-buttons button svg { vertical-align: -3px; margin-right: 6px; }
.sheet .which { margin: 10px 0 0; font-weight: 700; }
.sheet .which + .peek { margin-top: 6px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.cards p { grid-column: 1 / -1; }
.card { padding: 4px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; line-height: 1.25; min-width: 0; }
.card canvas { width: 100%; aspect-ratio: 1; margin-bottom: 2px; }
.card span { white-space: nowrap; max-width: 100%; overflow: hidden; }
.card.is-open { outline: 3px solid #c79b55; outline-offset: 0; }
/* 自分の帯: 1本が1行。左は開く札（紙の帯のコマの並び）、右に離して「捨てる」 */
.strip-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.strip-list p { margin: 0; }
.strip-row { display: flex; align-items: stretch; gap: 12px; min-height: 76px; }
.strip-card { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 6px; text-align: left; }
.strip-card.is-open { outline: 3px solid #c79b55; outline-offset: 0; }
/* コマが6つより少ない帯は、紙がその分だけ短い */
.film { display: grid; grid-template-columns: repeat(6, 1fr); }
.film canvas { width: 100%; height: auto; aspect-ratio: 1; border: solid #b5a480; border-width: 1px 1px 1px 0; }
.film canvas:first-child { border-left-width: 1px; }
.strip-card .meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; line-height: 1.3; white-space: nowrap; }
.strip-card .when { opacity: .8; font-variant-numeric: tabular-nums; }
.strip-discard, .strip-restore { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; line-height: 1.2; padding: 0 2px; }
.sheet .strip-discard { width: 60px; background: #0005; color: #f2eadb; box-shadow: none; }
.strip-row.is-gone { align-items: center; padding-left: 10px; border: 1px dashed #f2eadb66; border-radius: 6px; }
.strip-row.is-gone p { flex: 1; }
.strip-restore { width: 76px; align-self: stretch; font-size: 13px; font-weight: 700; }
.peek { display: flex; gap: 2px; overflow: hidden; margin-top: 10px; }
.peek canvas { width: calc((100% - 10px) / 6); max-width: 72px; height: auto; flex: none; }
.sheet-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet-buttons button { flex: 1 1 140px; height: 48px; }
.sheet button.primary { background: #c79b55; font-weight: 700; }
/* GIF で保存: 板の下の区画。進み具合も、できた知らせも、この中に出す */
.gif { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #f2eadb55; }
.gif > button { width: 100%; height: 48px; }
.sheet .gif p { margin: 0 0 8px; }
.sheet .gif .gif-what { font-size: 13px; opacity: .85; }
.sheet .gif .gif-done { font-weight: 700; font-variant-numeric: tabular-nums; }
.sheet .gif .gif-status { margin: 8px 0 0; }
.sheet .gif .gif-status:empty { display: none; }
.gif-working { display: flex; align-items: center; gap: 12px; }
.gif-working > div { flex: 1; min-width: 0; }
.sheet .gif .gif-count { margin: 0 0 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
.gif progress { display: block; width: 100%; height: 12px; accent-color: #c79b55; }
.gif-working button { flex: none; min-width: 88px; height: 48px; }
.manual { width: 100%; margin-top: 8px; padding: 8px; font-size: 16px; user-select: text; -webkit-user-select: text; }

/* PC */
.hint-mouse { display: none; }
@media (hover: hover) and (pointer: fine) {
  .hint-touch { display: none; }
  .hint-mouse { display: inline; }
}
@media (min-width: 900px) and (hover: hover) {
  #keys { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .hint-hand, .hint-hand .tail, #hint.faster .hint-hand, #hint.faster .hint-hand .tail, .sheet, #btn-flip.lift { animation: none; }
  #arrived { transition: none; }
}
