/* 描く画面（持ち主は ux B）。夜の工作机の上の紙 */
.draw {
  --item: 64px;
  --paper: #f7f1e3;
  position: relative; display: flex; flex-direction: column; min-height: 0; flex: 1;
  background:
    radial-gradient(ellipse 120% 80% at 18% 0%, rgba(255,232,196,.17), rgba(255,232,196,0) 55%),
    radial-gradient(ellipse 130% 100% at 40% 35%, rgba(30,19,12,0) 45%, rgba(30,19,12,.82) 100%),
    url(/assets/desk-wood.jpg) 0 0 / 640px 640px,
    repeating-linear-gradient(178deg, #5a3a24 0 7px, #4f311d 7px 9px, #62402a 9px 22px, #442a19 22px 23px, #5a3a24 23px 37px);
}
.draw[hidden] { display: none; }

/* いま描くコマ */
.draw-stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; overflow: hidden; touch-action: none; }
.draw-desk { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.draw-paper {
  position: relative; flex: none; border-radius: 2px;
  background: var(--grain, none), linear-gradient(135deg, #fbf6ea, var(--paper) 45%, #eee5d1);
  box-shadow: 2px 2px 0 #c9bb9c, 3px 4px 0 rgba(0,0,0,.28), 6px 12px 22px rgba(0,0,0,.42);
}
.draw-paper::after { /* 鉛筆の枠の線 */
  content: ""; position: absolute; inset: 7px; pointer-events: none;
  border: 1px solid #c9bda6; border-radius: 3px 1px 4px 2px; box-shadow: .6px .8px 0 rgba(201,189,166,.45);
}
.draw-paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.draw-base { pointer-events: none; }
.draw-ink { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: crosshair; }
.draw-paper.is-move .draw-ink { cursor: move; }
/* 「ずらす」で引いている間: 線が外へ出る側の縁を赤くする（そこから先は、離すと消える） */
.draw-paper::before {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; border: 0 solid #c8402c;
  background: none;
}
.draw-paper.cut-left::before { border-left-width: 5px; }
.draw-paper.cut-top::before { border-top-width: 5px; }
.draw-paper.cut-right::before { border-right-width: 5px; }
.draw-paper.cut-bottom::before { border-bottom-width: 5px; }
.draw-number {position: absolute; top: 11px; left: 14px; color: #8a7d68; font: italic 13px/1 ui-serif, Georgia, serif; pointer-events: none; }

/* 「ずらす」で引いている間の、枠の外へ出た部分（薄い色。紙の2倍の広さで、紙の上は抜いてある） */
.draw .draw-paper canvas.draw-outside { left: -50%; top: -50%; width: 200%; height: 200%; z-index: 1; pointer-events: none; opacity: .5; }
.draw-outside[hidden] { display: none; }

/* 紙の下の知らせ */
.draw-slot { position: relative; z-index: 2; flex: none; height: 48px; width: 100%; display: flex; align-items: center; justify-content: center; padding: 0 8px; }
.draw-note { margin: 0; text-align: center; font-size: 13px; line-height: 1.35; white-space: pre-line; }
.draw-note:not(:empty) { background: #1e130cdd; color: #f6eedc; padding: 5px 12px; border-radius: 4px; }
.draw-note:empty { display: none; }
.draw-toast { display: flex; align-items: center; gap: 12px; background: #1e130cee; color: #f6eedc; padding: 0 2px 0 14px; border-radius: 6px; font-size: 14px; height: 48px; }
.draw-toast[hidden] { display: none; }
/* 描いた1筆の直後: ほかのコマにも写す札と、写した後の「少しずつずらす」（知らせの1行と同じ場所。道具の行は増やさない） */
.draw .draw-toast .draw-tag[hidden] { display: none; }
.draw-toast.is-offer { gap: 8px; padding: 0 4px 0 10px; max-width: 100%; font-size: 13px; line-height: 1.2; animation: draw-offer .22s ease-out; }
.draw-toast.is-offer > span { min-width: 0; white-space: pre-line; }
.draw-toast.is-offer.is-follow { font-size: 12px; } /* 知らせが3行になっても 48px に収まる大きさ */
.draw .draw-toast.is-offer .draw-tag { flex: none; }
.draw .draw-toast .draw-spread { padding: 0 9px; box-shadow: 0 0 0 2px #ffd35c, 0 4px 6px rgba(0,0,0,.35); }
@keyframes draw-offer { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .draw-toast.is-offer { animation: none; } }
@media (max-width: 380px) {
  .draw-toast.is-offer { gap: 6px; padding-left: 8px; font-size: 12px; }
  .draw .draw-toast.is-offer .draw-tag { font-size: 12px; padding: 0 7px; gap: 3px; }
}
/* 「少しずつずらす」で紙を引ける間 */
.draw-paper.is-drift { outline: 3px dashed #ffd35c; outline-offset: 2px; }
.draw-paper.is-drift .draw-ink { cursor: move; }

/* 帯の全体: 切れ目のない細長い紙 */
/* 「＋」は横送りの外の右端にいつも同じ場所で置く（コマに重ならず、続けて押せる） */
.draw-reel { flex: none; height: 80px; display: flex; align-items: stretch; }
.draw-window { position: relative; flex: 1; min-width: 0; }
.draw-film { height: 100%; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; overscroll-behavior: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; user-select: none; -webkit-user-select: none; }
.draw-film::-webkit-scrollbar { display: none; }
@media (pointer: fine) { .draw-film, .draw .draw-film .draw-thumb { cursor: grab; } }
.draw .draw-film.is-grabbed, .draw .draw-film.is-grabbed .draw-thumb { cursor: grabbing; }
/* コマが少ない時は「＋」の隣に寄せる */
.draw-film-inner { display: flex; width: max-content; margin-left: auto; height: 100%; padding: 0 8px; align-items: stretch; }
.draw-track {
  position: relative; flex: none; margin: 6px 0; border-radius: 3px;
  background: var(--grain, none), linear-gradient(#e6dcc4, #f6efde 14%, #f2ead6 82%, #d9ccae);
  box-shadow: 0 3px 5px rgba(0,0,0,.45);
}
/* 続きがある側: 端が暗くなり、矢印が出る */
.draw-more { position: absolute; top: 0; bottom: 0; width: 30px; display: flex; align-items: center; pointer-events: none; opacity: 0; transition: opacity .15s; }
.draw-more .draw-icon { width: 18px; height: 18px; padding: 3px; border-radius: 50%; color: #f6eedc; background: #1e130ce6; }
.draw-more-left { left: 0; justify-content: flex-start; background: linear-gradient(90deg, #1e130cd9, #1e130c00); }
.draw-more-left .draw-icon { transform: scaleX(-1); }
.draw-more-right { right: 0; justify-content: flex-end; background: linear-gradient(270deg, #1e130cd9, #1e130c00); }
.draw-window.has-left .draw-more-left, .draw-window.has-right .draw-more-right { opacity: 1; }
.draw .draw-thumb {
  position: absolute; top: 0; bottom: 0; width: var(--item); height: 100%; min-width: 0; min-height: 0; padding: 0;
  display: grid; place-items: center; background: transparent; border-radius: 0; box-shadow: none;
  border: 0; border-right: 1px dashed rgba(125,111,88,.45);
}
.draw .draw-thumb:active { transform: none; background: rgba(176,141,87,.18); }
.draw-thumb canvas { width: calc(var(--item) - 10px); height: calc(var(--item) - 10px); display: block; border: 1px solid #cfc2a8; border-radius: 2px; pointer-events: none; }
.draw-thumb span { position: absolute; left: 7px; top: calc(50% - var(--item) / 2 + 6px); font: italic 10px/1 ui-serif, Georgia, serif; color: #8a7d68; pointer-events: none; }
.draw-thumb.is-current canvas { border: 3px solid #8a6a34; background: #fffaee; box-shadow: 0 0 0 1px #e3c98f; }
.draw-clip { display: none; position: absolute; top: calc(50% - var(--item) / 2 - 1px); right: 3px; width: 28px; height: 12px; pointer-events: none; transform: rotate(4deg); filter: drop-shadow(1px 2px 1px #0007); }
.draw-thumb.is-current .draw-clip { display: block; }

/* 継ぎ足しの紙 */
.draw .draw-add {
  flex: none; width: 64px; min-width: 0; margin: 4px 4px 4px 2px; padding: 0; touch-action: manipulation;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  color: #2a2017; line-height: 1.1; border-radius: 2px 5px 5px 2px;
  background: var(--grain, none), linear-gradient(#fbf3dc, #eedfb9);
  border: 2px dashed #8a6a34; box-shadow: 0 3px 4px rgba(0,0,0,.4);
}
.draw-add .draw-icon { width: 28px; height: 28px; }
.draw-add small { font-size: 12px; font-weight: 700; }
.draw .draw-add:active { transform: translateY(2px); box-shadow: none; }

/* 道具の紙の札 */
.draw-side { display: flex; flex-direction: column; flex: none; }
.draw-row { display: flex; flex: none; gap: 6px; height: 48px; padding: 0 8px; align-items: center; justify-content: center; }
.draw .draw-tag {
  display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 44px; min-width: 44px; padding: 0 8px; white-space: nowrap;
  color: #2a2017; font-size: 14px; border-radius: 3px 5px 4px 6px;
  background: var(--grain, none), linear-gradient(#f6edd9, #e7d9bb);
  box-shadow: 0 2px 0 #8d7a57, 0 4px 6px rgba(0,0,0,.35);
  transition: transform .05s;
}
.draw .draw-tag:active { transform: translateY(2px); box-shadow: 0 0 0 #8d7a57, 0 1px 2px rgba(0,0,0,.35); }
.draw .draw-tag[aria-pressed="true"] {
  transform: translateY(2px); font-weight: 700;
  background: var(--grain, none), linear-gradient(#c3974f, #d4ad69);
  box-shadow: inset 0 2px 5px rgba(60,38,10,.55), inset 0 0 0 1px #8a6a34;
}
.draw-icon { width: 20px; height: 20px; flex: none; }
.draw .is-faded { opacity: .42; }
.draw-ops .draw-tag { flex: 1; max-width: 160px; }
/* コマの数: 鉛筆の印の付いた、押すと数を打てる札 */
.draw .draw-ops .draw-count { flex: 0 0 auto; min-width: 82px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.draw .draw-count .draw-icon { width: 16px; height: 16px; }

/* 数を打つ箱。数字のキーボードに隠れないように、画面の上の方に出す */
.draw-ask { position: absolute; inset: 0; z-index: 20; display: flex; justify-content: center; align-items: flex-start; padding: 12px 16px; background: #1e130c8c; }
.draw-ask[hidden] { display: none; }
.draw-ask-card {
  width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; color: #2a2017; border-radius: 4px 6px 5px 7px;
  background: var(--grain, none), linear-gradient(#fbf6ea, #eee3c8);
  box-shadow: 0 3px 0 #8d7a57, 0 10px 24px #000a;
}
.draw-ask-card label { font-size: 15px; font-weight: 700; text-align: center; }
.draw-ask-card input {
  width: 100%; height: 48px; box-sizing: border-box; font: 700 24px/1 ui-serif, Georgia, serif; text-align: center; color: #2a2017;
  background: #fffdf6; border: 2px solid #8a6a34; border-radius: 4px; user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
.draw-ask-error { margin: 0; font-size: 13px; line-height: 1.35; text-align: center; color: #9c2a18; font-weight: 700; }
.draw-ask-error:empty { display: none; }
.draw-ask-card > div { display: flex; gap: 10px; }
.draw .draw-ask-card .draw-tag { flex: 1; min-height: 48px; touch-action: manipulation; }
.draw .draw-ask-card .draw-ask-set { flex: 1.6; font-weight: 700; background: var(--grain, none), linear-gradient(#ffdf7e, #f0c24c); }
.draw-tools .draw-tag { flex: 1 1 auto; max-width: 128px; padding: 0 3px; font-size: 13px; }
/* 前のコマの絵を出すかの切り替え。選ぶ道具ではないので、金色にせず、つまみで入と切を見せる */
.draw .draw-tag.draw-onion[aria-pressed] { transform: none; font-weight: 400; background: var(--grain, none), linear-gradient(#f6edd9, #e7d9bb); box-shadow: 0 2px 0 #8d7a57, 0 4px 6px rgba(0,0,0,.35); }
.draw .draw-tag.draw-onion:active { transform: translateY(2px); }
.draw-onion span { white-space: pre-line; text-align: left; line-height: 1.15; font-size: 12px; }
.draw-switch { flex: none; width: 26px; height: 16px; }
.draw-switch rect { fill: #b9ab8c; stroke: #5c4d33; stroke-width: 1; }
.draw-switch circle { fill: #fffaee; stroke: #5c4d33; stroke-width: 1; transition: transform .12s; }
.draw-onion[aria-pressed="true"] .draw-switch rect { fill: #3f74a8; stroke: #24476a; }
.draw-onion[aria-pressed="true"] .draw-switch circle { transform: translateX(10px); }
.draw-inks { gap: 7px; }
.draw-group { display: flex; gap: 3px; }
.draw .draw-color, .draw .draw-width {
  width: 44px; height: 44px; min-width: 44px; padding: 0; display: grid; place-items: center;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f8f0dd, #ddcdac);
  box-shadow: 0 2px 0 #8d7a57, 0 3px 5px rgba(0,0,0,.35);
}
.draw-color svg { display: block; pointer-events: none; }
.draw-width i { display: block; border-radius: 50%; background: #2a2017; pointer-events: none; }
/* 太さの丸（CSP のため、インラインの style を使わない） */
.draw-width[data-width="0"] i { width: 6px; height: 6px; }
.draw-width[data-width="1"] i { width: 11px; height: 11px; }
.draw-width[data-width="2"] i { width: 18px; height: 18px; }
/* 目を引く: 消しゴムのままの時のペン、取り消しで戻したコマ */
.draw .draw-thumb.is-called, .draw .draw-paper.is-called, .draw .draw-tag.is-called { outline: 4px solid #ffd35c; outline-offset: -2px; }
.draw .draw-paper.is-called { outline-offset: 2px; }
.draw .is-called { animation: draw-call .45s ease-in-out 3; }
@keyframes draw-call { 25% { translate: -4px 0; outline-color: #fff2c4; } 75% { translate: 4px 0; } }
@media (prefers-reduced-motion: reduce) { .draw .is-called { animation: none; } }
.draw .draw-color[aria-pressed="true"], .draw .draw-width[aria-pressed="true"] {
  box-shadow: 0 0 0 2px #1e130c, 0 0 0 4px #f3dfae; background: #fff8e8;
}
.draw-sep { width: 1px; height: 28px; background: #efe4cc55; }

@media (max-height: 700px) {
  .draw { --item: 56px; }
  .draw-reel { height: 64px; }
  .draw-track { margin: 3px 0; }
  .draw .draw-add { width: 60px; margin-top: 2px; margin-bottom: 2px; }
  .draw-add .draw-icon { width: 24px; height: 24px; }
  .draw-row { height: 48px; } /* 44px の札が上下で接して影が重なって見えるので、行の間を 4px あける */
  .draw .draw-tag { font-size: 13px; }
}
@media (max-width: 380px) {
  .draw-row { gap: 4px; padding: 0 4px; }
  .draw-tools .draw-tag { font-size: 12px; gap: 3px; }
  .draw-tools .draw-icon { width: 18px; height: 18px; }
  .draw .draw-ops .draw-count { min-width: 76px; font-size: 14px; gap: 3px; padding: 0 6px; }
  .draw-inks { gap: 4px; }
  .draw-group { gap: 2px; }
}

/* スマホ: 道具が5つ横に入るように、ペン、消しゴム、ずらす、取り消しは絵の下に名前を置く */
@media (max-width: 899px) {
  .draw .draw-tools .draw-tag:not(.draw-onion) { flex: 1 1 0; flex-direction: column; gap: 1px; padding: 0 1px; line-height: 1.15; font-size: 12px; }
  .draw .draw-tools .draw-onion { flex: 0 0 auto; padding: 0 6px; gap: 4px; }
  .draw-tools .draw-tag:not(.draw-onion) .draw-icon { width: 19px; height: 19px; }
}

/* PC: 左に大きいコマ、右に道具の縦の列、下に画面の幅いっぱいの帯 */
@media (min-width: 900px) {
  .draw { --item: 96px; display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr) 116px; }
  .draw[hidden] { display: none; }
  .draw-stage { grid-column: 1; grid-row: 1; padding-left: 40px; }
  .draw-side { grid-column: 2; grid-row: 1; align-self: center; margin-right: max(24px, calc(50vw - 560px)); gap: 18px; }
  .draw-reel { grid-column: 1 / -1; grid-row: 2; height: 116px; }
  .draw .draw-add { width: 96px; margin-right: 12px; }
  .draw-add .draw-icon { width: 38px; height: 38px; }
  .draw-thumb span { font-size: 12px; }
  .draw-row { height: auto; flex-wrap: wrap; gap: 10px; }
  .draw .draw-ops .draw-count { flex: 1 1 100%; max-width: none; font-size: 18px; }
  .draw-ask { align-items: center; }
  .draw-ops .draw-tag { min-height: 48px; max-width: none; flex: 1 1 100%; }
  .draw-tools .draw-tag { flex: 1 1 40%; max-width: none; min-height: 52px; font-size: 14px; }
  .draw-tools .draw-onion span { font-size: 13px; }
  .draw-inks { flex-direction: column; gap: 16px; }
  .draw-group { gap: 12px; }
  .draw-sep { display: none; }
}
