/**
 * engine/countdown-timer.css — 受講者向けカウントダウンタイマー UI
 * - 右上 fixed overlay、白背景スライド前提で明背景 + 暗文字
 * - 色は柔らかめ + 警告/緊急で気づける階調
 * - presenter window では非表示 (countdown-timer.js 側でガード)
 */

/* ── ルート ── */
.cdt-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9000;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #2a2d35;
}

/* スクリーンショットや印刷では非表示 */
@media print { .cdt-root { display: none !important; } }

/* ── 起動ボタン (アイドル: 円形、稼働: 横長) ── */
.cdt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-width: 44px;
  height: 44px;
  padding: 0 .85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  color: #2a2d35;
  font-size: 1.0rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  cursor: pointer;
  user-select: none;
  transition: background .15s, border-color .15s, color .25s, box-shadow .15s;
  letter-spacing: .04em;
}
.cdt-btn:hover {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(0, 0, 0, 0.32);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
}
.cdt-btn:focus-visible { outline: 2px solid rgba(70, 110, 180, .65); outline-offset: 2px; }

.cdt-btn-icon { font-size: 1.1rem; opacity: .7; }
.cdt-btn-time { font-size: 1.0rem; font-variant-numeric: tabular-nums; }

/* idle 時は時刻部分を隠す (アイコンのみ) */
.cdt-root[data-state="idle"] .cdt-btn-time { display: none; }

/* ── 色の階段 (柔らかめペールトーン、原色回避) ── */
/* warn = ペールアンバー / critical = ペールコーラル */
.cdt-root[data-color="warn"] .cdt-btn {
  color: #6b4d12;
  border-color: rgba(180, 130, 30, 0.55);
  background: rgba(252, 230, 175, 0.94);
}
.cdt-root[data-color="warn"] .cdt-btn .cdt-btn-icon { opacity: 1; }

.cdt-root[data-color="critical"] .cdt-btn {
  color: #7a2c1f;
  border-color: rgba(190, 80, 60, 0.6);
  background: rgba(250, 212, 200, 0.95);
}
.cdt-root[data-color="critical"] .cdt-btn .cdt-btn-icon { opacity: 1; }

/* critical 時は弱い pulse */
@keyframes cdt-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(190, 80, 60, 0.10); }
  50%      { box-shadow: 0 2px 8px rgba(190, 80, 60, 0.10), 0 0 0 6px rgba(190, 80, 60, 0.16); }
}
.cdt-root[data-color="critical"] .cdt-btn {
  animation: cdt-pulse 1.6s ease-in-out infinite;
}

/* finished (音鳴動中) は critical と同色のまま、pulse 強調 */
.cdt-root[data-state="finished"] .cdt-btn {
  animation: cdt-pulse 1.0s ease-in-out infinite;
}

/* a11y: prefers-reduced-motion で animation/transition を停止 (前庭障害・てんかん配慮) */
@media (prefers-reduced-motion: reduce) {
  .cdt-btn,
  .cdt-root[data-color="critical"] .cdt-btn,
  .cdt-root[data-state="finished"] .cdt-btn {
    animation: none !important;
    transition: none !important;
  }
}

/* ── パネル ── */
.cdt-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  padding: .9rem 1rem 1rem;
  background: rgba(252, 252, 253, 0.97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.16);
  display: none;
  font-size: .9rem;
  color: #2a2d35;
}
.cdt-root[data-panel="open"] .cdt-panel { display: block; }

.cdt-panel-title {
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .55;
  margin-bottom: .55rem;
}

/* プリセット 3 / 10 / 30 分 */
.cdt-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .35rem;
  margin-bottom: .65rem;
}
.cdt-preset {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.16);
  color: #3a3d45;
  padding: .45rem .35rem;
  border-radius: 6px;
  font-size: .85rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.cdt-preset:hover { background: rgba(0, 0, 0, 0.08); color: #1f2128; border-color: rgba(0,0,0,.28); }
.cdt-preset.is-selected {
  background: rgba(70, 110, 180, 0.14);
  border-color: rgba(70, 110, 180, 0.5);
  color: #1c3a6c;
}

/* 数値入力 + ▲▼ */
.cdt-num-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .8rem;
}
.cdt-num-label {
  flex: 0 0 auto;
  font-size: .82rem;
  opacity: .7;
}
.cdt-num-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.85);
}
.cdt-num-input {
  flex: 1 1 auto;
  width: 100%;
  background: transparent;
  border: none;
  color: #2a2d35;
  padding: .35rem .55rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 1.0rem;
  text-align: right;
  -moz-appearance: textfield;
}
.cdt-num-input::-webkit-outer-spin-button,
.cdt-num-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.cdt-num-input:focus { outline: none; background: rgba(70, 110, 180, 0.08); }
.cdt-num-spin {
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(0, 0, 0, 0.16);
}
.cdt-num-spin button {
  background: rgba(0, 0, 0, 0.04);
  border: none;
  color: #4a4d55;
  padding: 0 .55rem;
  font-size: .65rem;
  cursor: pointer;
  line-height: 1;
  flex: 1 1 50%;
  min-height: 16px;
  transition: background .12s, color .12s;
}
.cdt-num-spin button + button { border-top: 1px solid rgba(0, 0, 0, 0.12); }
.cdt-num-spin button:hover { background: rgba(0, 0, 0, 0.10); color: #1f2128; }
.cdt-num-unit {
  flex: 0 0 auto;
  font-size: .82rem;
  opacity: .7;
}

/* 操作ボタン */
.cdt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .35rem;
}
.cdt-action {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.18);
  color: #3a3d45;
  padding: .5rem .35rem;
  border-radius: 6px;
  font-size: .85rem;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.cdt-action:hover { background: rgba(0, 0, 0, 0.10); color: #1f2128; border-color: rgba(0,0,0,.32); }
.cdt-action.is-primary {
  background: rgba(70, 110, 180, 0.18);
  border-color: rgba(70, 110, 180, 0.55);
  color: #1c3a6c;
}
.cdt-action.is-primary:hover { background: rgba(70, 110, 180, 0.28); }
.cdt-action[disabled] {
  opacity: .35;
  cursor: not-allowed;
  pointer-events: none;
}

/* finished 時の pause ボタン (音停止) はアラート色で目立たせる */
.cdt-root[data-state="finished"] .cdt-pause {
  background: rgba(250, 212, 200, 0.85);
  border-color: rgba(190, 80, 60, 0.55);
  color: #7a2c1f;
}
.cdt-root[data-state="finished"] .cdt-pause:hover {
  background: rgba(250, 212, 200, 1);
}

/* ════════════════════════════════════════════════════════════
   全画面オーバーレイ — 稼働中はスライド背景全体に半透明の巨大カウントダウン
   ════════════════════════════════════════════════════════════ */
.cdt-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;                 /* スライドより上 / timer 本体 (9000) とパネルより下 */
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;          /* slide.js の左右クリックナビ・lightbox を一切妨げない */
}
/* idle 以外 (running / paused / finished) で表示 */
.cdt-root[data-state="running"]  .cdt-overlay,
.cdt-root[data-state="paused"]   .cdt-overlay,
.cdt-root[data-state="finished"] .cdt-overlay { display: flex; }

.cdt-overlay-time {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 46vh;               /* 画面いっぱいの「でっかい」数字 */
  line-height: 1;
  letter-spacing: .02em;
  color: rgba(40, 45, 55, 0.10); /* 半透過: スライド内容を邪魔せず背景に浮く */
  transition: color .3s ease;
  user-select: none;
}
/* 一時停止中は少し沈める (進行中でないと分かるように) */
.cdt-root[data-state="paused"] .cdt-overlay-time { color: rgba(40, 45, 55, 0.07); }

/* 警告色と連動 (本体ボタンの warn / critical 階調に合わせる) */
.cdt-root[data-color="warn"]     .cdt-overlay-time { color: rgba(180, 130, 30, 0.15); }
.cdt-root[data-color="critical"] .cdt-overlay-time { color: rgba(190, 80, 60, 0.17); }

/* 終了時: 「終了」を少し濃く + 拡縮 pulse で気づかせる ("終了" 2 文字なので幅を抑える) */
.cdt-root[data-state="finished"] .cdt-overlay-time {
  font-size: 34vh;
  color: rgba(190, 80, 60, 0.24);
  animation: cdt-overlay-finish 1.0s ease-in-out infinite;
}
@keyframes cdt-overlay-finish {
  0%, 100% { transform: scale(1);    color: rgba(190, 80, 60, 0.20); }
  50%      { transform: scale(1.05); color: rgba(190, 80, 60, 0.30); }
}

/* ════════════════════════════════════════════════════════════
   スタート演出 — 押下で中央に「スタート」が出てブワッと拡大して消える
   ════════════════════════════════════════════════════════════ */
.cdt-flash {
  position: fixed;
  inset: 0;
  z-index: 9500;                 /* 一瞬だけ最前面 (panel 9000 より上) */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;                    /* 既定は不可視、is-playing 時のみアニメ */
}
.cdt-flash-text {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: 22vh;
  letter-spacing: .12em;
  color: var(--color-accent);          /* theme のアクセント色に追従 (deck 差し替えで自動変化) */
  text-shadow: 0 4px 28px rgba(0, 0, 0, 0.18);
  user-select: none;
}
.cdt-flash.is-playing { animation: cdt-flash-anim 0.9s cubic-bezier(.16, .8, .3, 1) forwards; }
@keyframes cdt-flash-anim {
  0%   { opacity: 0; transform: scale(.35); }
  22%  { opacity: 1; transform: scale(1.0); }
  55%  { opacity: 1; transform: scale(1.12); }
  100% { opacity: 0; transform: scale(2.3); }
}

/* a11y: reduced-motion ではオーバーレイ pulse / スタート演出を止める (JS 側でも flash は抑止) */
@media (prefers-reduced-motion: reduce) {
  .cdt-root[data-state="finished"] .cdt-overlay-time { animation: none !important; }
  .cdt-overlay-time { transition: none !important; }
  .cdt-flash, .cdt-flash.is-playing { animation: none !important; opacity: 0 !important; }
}

/* スクショ / 印刷ではオーバーレイ・演出を出さない */
@media print { .cdt-overlay, .cdt-flash { display: none !important; } }

/* footer hint (キーボードショートカット案内) */
.cdt-hint {
  margin-top: .65rem;
  font-size: .68rem;
  opacity: .55;
  text-align: right;
  letter-spacing: .04em;
  color: #4a4d55;
}
.cdt-hint kbd {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .7rem;
  color: #2a2d35;
}
