/* round-bell — 画面のスタイル
   工程3：骨組み／工程5：状態ごとの背景色と、色以外の手がかり（状態名の形・背景の模様）／工程7：案内文／工程8：スリープ防止の案内／工程9：設定画面 */

:root {
  --bg: #2b2b2b;
  --fg: #ffffff;
  --fg-sub: rgba(255, 255, 255, 0.75);
  --btn-bg: rgba(255, 255, 255, 0.16);
  --btn-bg-active: rgba(255, 255, 255, 0.3);
  --btn-main-bg: #ffffff;
  --btn-main-fg: #1a1a1a;
  --pattern: none;
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* 画面全体：上（ラウンド数・設定）／中央（状態・残り時間・技名）／下（ボタン） */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg);
  background-image: var(--pattern);
  color: var(--fg);
  transition: background-color 0.25s ease;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 16px)
    calc(env(safe-area-inset-left) + 16px);
}

/* 上部 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.round-label {
  font-size: clamp(1.5rem, 7vw, 2.5rem);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.settings-button {
  min-height: 48px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--btn-bg);
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.settings-button:active {
  background: var(--btn-bg-active);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* リズムモードのボタン（音楽マーク）。ON のときは白く塗りつぶして、画面を見ただけで分かるようにする */
.rhythm-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 0 12px;
}

.rhythm-button[data-on="true"] {
  background: var(--btn-main-bg);
  color: var(--btn-main-fg);
}

/* 中央 */
.timer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
}

.state-label {
  font-size: clamp(1.75rem, 9vw, 3rem);
  font-weight: 800;
  line-height: 1.2;
  padding: 0.1em 0.6em;
  border: 4px solid transparent;
  border-radius: 14px;
}

/* 残り時間：離れても読めるよう、画面幅に合わせて最大限大きく */
.time {
  font-size: min(44vw, 30vh, 18rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* 技名表示エリア（ラウンド中だけ中身が入る。空でも高さを確保して位置がずれないようにする） */
.combo {
  width: 100%;
  min-height: 6.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}

.combo-name {
  font-size: clamp(1.25rem, 6vw, 2rem);
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* 工程11：技名が切り替わったことが分かるよう、表示のたびに少し大きく出して戻す */
.combo-flash {
  animation: combo-pop 0.35s ease-out;
}

@keyframes combo-pop {
  0% { transform: scale(1.25); opacity: 0.3; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== リズムモード（2026-10-04 追加） =====
   技名は技ごとに区切り、今打つ技を枠で囲む。予告中（次に打つセット）は「次」を付けて薄く出す。
   その下に、今の拍の指示（技名／ステップ）と小節の4拍の点を出し、拍ごとに弾ませる */
.combo-next .combo-name {
  opacity: 0.6;
}

.combo-next .combo-name::before {
  content: "次 ";
  font-size: 0.75em;
}

.combo-part {
  display: inline-block;
  padding: 0 0.2em;
  border: 3px solid transparent;
  border-radius: 10px;
}

.combo-part.is-active {
  border-color: var(--fg);
}

.beat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.beat[hidden] {
  display: none;
}

.beat-cue {
  font-size: clamp(1.25rem, 6vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--fg-sub);
}

.beat-cue.is-hit {
  font-size: clamp(1.75rem, 9vw, 2.75rem);
  font-weight: 900;
  color: var(--fg);
}

.beat-dots {
  display: flex;
  gap: 12px;
}

.beat-dots span {
  width: 14px;
  height: 14px;
  border: 2px solid var(--fg-sub);
  border-radius: 50%;
}

/* 小節の1拍目は少し大きく */
.beat-dots span:first-child {
  width: 18px;
  height: 18px;
}

.beat-dots span.is-on {
  background: var(--fg);
  border-color: var(--fg);
}

.beat-pop .beat-cue {
  animation: beat-pop 0.2s ease-out;
}

@keyframes beat-pop {
  0% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* 下部：案内文（工程7）とボタン */
.footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notice {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--fg-sub);
}

/* 工程8：Wake Lock を取得できないときの案内（自動ロックの設定を促すので少し目立たせる） */
.notice-wakelock {
  color: var(--fg);
  font-weight: 700;
}

.notice[hidden] {
  display: none;
}

/* 下部ボタン：グローブでも押せるよう大きく */
.controls {
  display: flex;
  gap: 12px;
}

.btn {
  min-height: 80px;
  border-radius: 20px;
  font-size: clamp(1.25rem, 6vw, 1.75rem);
  font-weight: 800;
}

.btn-main {
  flex: 2;
  background: var(--btn-main-bg);
  color: var(--btn-main-fg);
}

.btn-main:active {
  opacity: 0.8;
}

.btn-reset {
  flex: 1;
  background: var(--btn-bg);
}

.btn-reset:active {
  background: var(--btn-bg-active);
}

/* 横向き・背の低い画面では余白を詰める */
@media (max-height: 500px) {
  .btn {
    min-height: 56px;
  }

  .combo {
    min-height: 4rem;
  }
}

/* ===== 状態ごとの見た目（工程5） =====
   背景色：待機中＝暗いグレー／カウントダウン中＝黄／ラウンド中＝赤／休憩中＝緑／一時停止中＝止めた状態の色を暗く
   色以外の手がかり：
   - 状態名の形：ラウンド＝塗りつぶしの札／休憩＝枠線だけの札／カウントダウン＝黒い札／一時停止＝点線の枠
   - 背景の模様：ラウンド中だけ斜めのしま模様 */

.app[data-state="countdown"] {
  --bg: #f5c400;
  --fg: #1a1a1a;
  --fg-sub: rgba(0, 0, 0, 0.7);
  --btn-bg: rgba(0, 0, 0, 0.14);
  --btn-bg-active: rgba(0, 0, 0, 0.26);
  --btn-main-bg: #1a1a1a;
  --btn-main-fg: #ffffff;
}

.app[data-state="round"] {
  --bg: #d0021b;
  --pattern: repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.16) 0 32px, transparent 32px 64px);
  --btn-main-fg: #b00018;
}

.app[data-state="rest"] {
  --bg: #12813a;
  --btn-main-fg: #0d6b2f;
}

/* 一時停止中：止めた状態の色を暗くする（カウントダウンの黄は暗くすると文字を白にする） */
.app[data-paused="true"][data-state="countdown"] {
  --bg: #6e5800;
  --fg: #ffffff;
  --fg-sub: rgba(255, 255, 255, 0.75);
  --btn-bg: rgba(255, 255, 255, 0.16);
  --btn-bg-active: rgba(255, 255, 255, 0.3);
  --btn-main-bg: #ffffff;
  --btn-main-fg: #1a1a1a;
}

.app[data-paused="true"][data-state="round"] {
  --bg: #5c0410;
  --pattern: repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.22) 0 32px, transparent 32px 64px);
}

.app[data-paused="true"][data-state="rest"] {
  --bg: #0a3d1c;
}

/* 状態名の札 */
.app[data-state="countdown"] .state-label {
  background: #1a1a1a;
  color: #f5c400;
}

.app[data-state="round"] .state-label {
  background: #ffffff;
  color: #b00018;
}

.app[data-state="rest"] .state-label {
  border-color: #ffffff;
}

.app[data-paused="true"] .state-label {
  background: transparent;
  color: var(--fg);
  border-color: var(--fg);
  border-style: dashed;
}

/* 一時停止中は残り時間を点滅させて「止まっている」ことを示す */
.app[data-paused="true"] .time {
  animation: paused-blink 1.6s steps(2, jump-none) infinite;
}

@keyframes paused-blink {
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .app {
    transition: none;
  }

  .app[data-paused="true"] .time {
    animation: none;
    opacity: 0.6;
  }

  .combo-flash,
  .beat-pop .beat-cue {
    animation: none;
  }
}

/* ===== 設定画面（工程9。工程13で使いやすさを見直し） =====
   待機中だけ開ける。タイマー画面の上に全画面で重ねる。
   トレーニング中に見る画面ではないので、一般的なアプリの設定画面くらいの大きさにする。
   ON/OFF はスイッチ、2択は切り替えボタン、速さはスライダー。意味のない項目は隠す */

.settings-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.settings {
  --s-bg: #1c1c1e;
  --s-card: #2c2c2e;
  --s-line: rgba(255, 255, 255, 0.1);
  --s-sub: rgba(255, 255, 255, 0.6);
  --s-accent: #f5c400;
  --s-off: #48484a;

  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--s-bg);
  color: #ffffff;
  font-size: 1rem;
}

.settings[hidden] {
  display: none;
}

/* PC など広い画面では中央に寄せる */
.settings-inner {
  max-width: 520px;
  margin: 0 auto;
  padding:
    0
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 24px)
    calc(env(safe-area-inset-left) + 16px);
}

/* 見出しはスクロールしても上に残す */
.settings-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 0 10px;
  background: var(--s-bg);
}

.settings-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 800;
}

.settings-close {
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  background: #ffffff;
  color: #1a1a1a;
  font-size: 0.9375rem;
  font-weight: 700;
}

.settings-close:active {
  opacity: 0.8;
}

.settings-close:focus-visible {
  outline: 2px solid var(--s-accent);
  outline-offset: 2px;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 4px;
}

/* 項目のまとまり（カード） */
.group-title {
  margin: 0 0 6px 4px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--s-sub);
  letter-spacing: 0.04em;
}

.group-body {
  border-radius: 12px;
  background: var(--s-card);
  overflow: hidden;
}

.sub-rows[hidden],
.row[hidden] {
  display: none;
}

/* 1行 = 1項目。左に名前、右に操作 */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  border-top: 1px solid var(--s-line);
}

.group-body > .row:first-child {
  border-top: none;
}

label.row {
  cursor: pointer;
}

/* 名前の下に操作や説明が来る行 */
.row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.row-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.row-label {
  font-size: 1rem;
  font-weight: 600;
}

.row-help {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--s-sub);
}

/* 画面ロック中・他アプリ使用中の音についての案内 */
.settings-note {
  margin: 0 4px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--s-sub);
}

.settings-storage-notice {
  margin: 0 4px;
  font-size: 0.875rem;
  line-height: 1.5;
  font-weight: 700;
}

.settings-storage-notice[hidden] {
  display: none;
}

/* スイッチ（ON/OFF） */
.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  position: relative;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 999px;
  background: var(--s-off);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
}

.switch:checked {
  background: var(--s-accent);
}

.switch:checked::before {
  transform: translateX(20px);
}

.switch:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* 切り替えボタン（2択） */
.segmented {
  flex: none;
  display: inline-flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--s-off);
}

.segmented label {
  position: relative;
  display: block;
}

.segmented input,
.check input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  min-width: 56px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.segmented input:checked + span {
  background: #ffffff;
  color: #1a1a1a;
}

.segmented input:focus-visible + span,
.check input:focus-visible + span {
  outline: 2px solid var(--s-accent);
  outline-offset: 1px;
}

/* チェックボックス（膝・肘） */
.checks {
  display: flex;
  gap: 8px;
}

.check {
  position: relative;
  display: block;
}

.check span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.check span::before {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 5px;
}

.check input:checked + span {
  border-color: var(--s-accent);
}

.check input:checked + span::before {
  border-color: var(--s-accent);
  background:
    var(--s-accent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%231a1a1a' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 14px no-repeat;
}

/* スライダー（読み上げの速さ・リズムモードのテンポ） */
.slider input {
  display: block;
  width: 100%;
  margin: 4px 0 0;
  accent-color: var(--s-accent);
  cursor: pointer;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--s-sub);
}

/* 狭い画面（320px 前後）では構えの切り替えボタンを名前の下に回す */
@media (max-width: 360px) {
  .row-line {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .row-line .segmented span {
    flex: 1;
  }

  .row-line .segmented label {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .switch,
  .switch::before {
    transition: none;
  }
}
