/* 練習タブ: 描画ツール（tabs/draw.js）。すべて .dw の中だけに効かせる。
   色は --dw-* 変数で持ち、ライト/ダークを切り替える。
   ダークは「OS がダーク」または「:root[data-theme="dark"]」。data-theme="light" は OS より優先。 */

:root {
  --dw-bg: #faf5ec;
  --dw-surface: #ffffff;
  --dw-ink: #3d2817;
  --dw-muted: #7a6552;
  --dw-line: rgba(61, 40, 23, 0.16);
  --dw-stage: #0d0f14;
  --dw-active: #1a2742;
  --dw-active-ink: #ffffff;
  --dw-primary: #c9a961;
  --dw-primary-ink: #2d1e14;
  --dw-alert: #b3261e;
  --dw-focus: #1a73e8;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --dw-bg: #11151d;
    --dw-surface: #1b2230;
    --dw-ink: #f1ece2;
    --dw-muted: #a9a298;
    --dw-line: rgba(255, 255, 255, 0.14);
    --dw-stage: #000000;
    --dw-active: #d4ad53;
    --dw-active-ink: #1a1206;
    --dw-primary: #d4ad53;
    --dw-primary-ink: #1a1206;
    --dw-alert: #ff8a80;
    --dw-focus: #8ab4f8;
  }
}

:root[data-theme="dark"] {
  --dw-bg: #11151d;
  --dw-surface: #1b2230;
  --dw-ink: #f1ece2;
  --dw-muted: #a9a298;
  --dw-line: rgba(255, 255, 255, 0.14);
  --dw-stage: #000000;
  --dw-active: #d4ad53;
  --dw-active-ink: #1a1206;
  --dw-primary: #d4ad53;
  --dw-primary-ink: #1a1206;
  --dw-alert: #ff8a80;
  --dw-focus: #8ab4f8;
}

.dw {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  color: var(--dw-ink);
  background: var(--dw-bg);
  box-sizing: border-box;
}

.dw *,
.dw *::before,
.dw *::after {
  box-sizing: border-box;
}

.dw [hidden] {
  display: none !important;
}

/* ファイル選択の input は見えなくするだけ（display:none だと端末によってはラベルから開けない） */
.dw-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ── 動画を選ぶ前 ── */
.dw-empty {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 260px;
  padding: 24px 20px;
  border: 2px dashed var(--dw-line);
  border-radius: 16px;
  background: var(--dw-surface);
  text-align: center;
  cursor: pointer;
}

.dw-empty:focus-within {
  outline: 3px solid var(--dw-focus);
  outline-offset: 2px;
}

.dw-empty-ico {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--dw-primary);
  color: var(--dw-primary-ink);
}

.dw-empty-ico svg {
  width: 30px;
  height: 30px;
}

.dw-empty-title {
  font-size: 18px;
  font-weight: 700;
}

.dw-empty-note {
  max-width: 300px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--dw-muted);
}

/* ── 動画＋描画 ── */
.dw-stage {
  position: relative;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: var(--dw-stage);
}

.dw-video,
.dw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.dw-video {
  object-fit: contain;
}

.dw-canvas {
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}

/* 再生中は描けないが、タップで一時停止できるようイベントは受ける */
.dw-canvas-off {
  cursor: pointer;
}

.dw-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── ボタン共通 ── */
.dw-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  min-height: 44px;
  padding: 4px 6px;
  border: 1px solid var(--dw-line);
  border-radius: 12px;
  background: var(--dw-surface);
  color: var(--dw-ink);
  font: inherit;
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dw-btn:focus-visible,
.dw-chip:focus-visible,
.dw-swatch:focus-visible,
.dw-seek:focus-visible {
  outline: 3px solid var(--dw-focus);
  outline-offset: 2px;
}

.dw-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.dw-btn[aria-pressed="true"] {
  background: var(--dw-active);
  border-color: var(--dw-active);
  color: var(--dw-active-ink);
}

.dw-ico {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
}

/* ── 再生操作 ── */
.dw-transport {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dw-transport-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dw-btn-round {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
}

.dw-btn-round .dw-btn-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dw-btn-play {
  width: 56px;
  height: 56px;
  background: var(--dw-primary);
  border-color: var(--dw-primary);
  color: var(--dw-primary-ink);
}

.dw-time {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--dw-muted);
  font-size: 14px;
}

.dw-time-now {
  font-size: 26px;
  font-weight: 700;
  color: var(--dw-ink);
}

.dw-seek {
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--dw-primary);
}

.dw-speed {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dw-speed-label {
  font-size: 13px;
  color: var(--dw-muted);
  margin-right: 4px;
}

.dw-chip {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--dw-line);
  border-radius: 999px;
  background: var(--dw-surface);
  color: var(--dw-ink);
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.dw-chip[aria-pressed="true"] {
  background: var(--dw-active);
  border-color: var(--dw-active);
  color: var(--dw-active-ink);
  font-weight: 700;
}

/* ── 描画ツール（5列×2段。390px で1個 約64px） ── */
.dw-tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.dw-tool {
  min-height: 56px;
}

.dw-color-dot {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--dw-surface);
  box-shadow: 0 0 0 1px var(--dw-line);
}

.dw-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--dw-line);
  border-radius: 12px;
  background: var(--dw-surface);
}

.dw-swatch {
  aspect-ratio: 1;
  min-width: 36px;
  min-height: 44px;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  cursor: pointer;
}

.dw-swatch[aria-pressed="true"] {
  outline: 3px solid var(--dw-ink);
  outline-offset: 2px;
}

.dw-hint {
  min-height: 1.6em;
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--dw-muted);
}

.dw-hint-alert {
  color: var(--dw-alert);
  font-weight: 700;
}

/* ── 切り取り後の出口 ── */
.dw-crop-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dw-btn-wide {
  flex-direction: row;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  font-size: 15px;
  font-weight: 700;
}

.dw-btn-primary {
  background: var(--dw-primary);
  border-color: var(--dw-primary);
  color: var(--dw-primary-ink);
}

.dw-btn-ghost {
  background: transparent;
  font-weight: 400;
  color: var(--dw-muted);
}

.dw-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  font-size: 14px;
  color: var(--dw-muted);
  text-decoration: underline;
  cursor: pointer;
}

.dw-link:focus-within {
  outline: 3px solid var(--dw-focus);
  outline-offset: 2px;
}

/* 開発用プレビュー（dev/draw-preview.html）の地の色 */
body.dw-preview {
  margin: 0;
  background: var(--dw-bg);
}
