/* 全ページ共通のスタイル。色・角丸・ボタン・右上の操作ボタン・設定パネルはここで決める */
:root {
  --bg: #1a1a2e;
  --text: #fff;
  --muted: #aaa;
  /* カード・プリセット・設定パネルなど背景から一段浮いた面 */
  --surface: #16213e;
  --surface-accent: #a8d8ea;
  /* 戻る・テーマ切替などの控えめな操作ボタン */
  --control-bg: rgba(255, 255, 255, 0.15);
  --border: #444;
  --divider: rgba(255, 255, 255, 0.1);
  --shadow: rgba(0, 0, 0, 0.3);
  --accent: #4caf50;
  --error-text: #ff5252;

  /* スタート・リセットなどのボタンの内縁の色 */
  --success: #4caf50;
  --warning: #ff7043;
  --danger: #ef5350;
  --info: #42a5f5;

  --ink-shift: 0.07em;

  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 16px;
}
html[data-theme="light"] {
  --bg: #eef1f6;
  --text: #2b2d42;
  --muted: #666;
  --surface: #fff;
  --surface-accent: #4a4e69;
  --control-bg: rgba(0, 0, 0, 0.1);
  --border: #ccc;
  --divider: rgba(0, 0, 0, 0.1);
  --shadow: rgba(0, 0, 0, 0.12);
  --accent: #2e7d32;
  --error-text: #c62828;
  --success: #2e7d32;
  --warning: #e65100;
  --danger: #c62828;
  --info: #1565c0;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  font-family:
    "IBM Plex Sans",
    "IBM Plex Sans JP",
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Noto Sans JP",
    sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: background 0.3s;
}

/* ---- ボタン ---- */
.btn {
  white-space: nowrap;
  border: none;
  border-radius: var(--radius);
  /* 和文の字面は行の中心より上に寄るので、上を少し厚くして見た目の中央にそろえる */
  padding: calc(14px + var(--ink-shift)) 28px calc(14px - var(--ink-shift));
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.15s,
    opacity 0.15s;
}
.btn:not(:disabled):hover {
  transform: scale(1.05);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
/* 面は塗らず、内縁だけ役割の色にする */
.btn.start,
.btn.reset,
.btn.lap {
  --ring: var(--success);
  background: var(--surface);
  box-shadow: inset 0 0 0 3px var(--ring);
}
.btn.start.resume {
  --ring: var(--warning);
}
.btn.reset {
  --ring: var(--danger);
}
.btn.lap {
  --ring: var(--info);
}
.btn.secondary {
  background: var(--surface);
  color: var(--surface-accent);
}

/* ---- 戻る・右上の操作ボタン ---- */
.control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6em;
  min-height: calc(1.2em + 20px);
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--control-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
.control.home {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
}
.toolbar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 8px;
}
.font-size-label {
  font-size: 0.7em;
  margin-left: 3px;
}
.font-size-value {
  min-width: 3.2em;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.keep-awake-label {
  font-size: 0.7em;
  margin-left: 4px;
  min-width: 2.2em;
  text-align: left;
}
/* 画面つけっぱなしが有効なときは、スタートボタンと同じく内縁を緑にする */
.control.keep-awake[aria-pressed="true"] {
  box-shadow: inset 0 0 0 2px var(--success);
}
/* 狭い画面では「戻る」と重ならないようサイズ名・ON/OFF を隠す */
@media (max-width: 420px) {
  .font-size-label,
  .keep-awake-label {
    display: none;
  }
}

/* ---- 右上のボタンから開く設定パネル (.toolbar の中に置く) ---- */
.panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  flex-direction: column;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  box-shadow: 0 4px 16px var(--shadow);
}
.panel.open {
  display: flex;
}
.panel .row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel .control {
  padding: 8px 16px;
  font-size: 0.9rem;
}
.hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 18em;
}
.hint a {
  color: inherit;
}

/* ---- 入力欄 ---- */
.field {
  padding: 8px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--field-bg, var(--surface));
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  color-scheme: light dark;
}
.panel .field {
  --field-bg: var(--bg);
}
input[type="range"] {
  width: 160px;
  accent-color: var(--accent);
}
input[type="checkbox"] {
  width: 1.2em;
  height: 1.2em;
  accent-color: var(--accent);
}

/* ---- 大きな数字表示 ---- */
.big-digits {
  font-family: "Unbounded", sans-serif;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1.1;
  user-select: none;
}

.error-text {
  color: var(--error-text);
  font-size: 0.95rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---- 初回のチュートリアル (tutorial.js) ---- */
.tutorial {
  width: min(32rem, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 24px;
  border: none;
  border-radius: var(--radius-l);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 32px var(--shadow);
  line-height: 1.6;
}
.tutorial::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.tutorial-count {
  color: var(--muted);
  font-size: 0.8rem;
}
.tutorial h2 {
  margin: 4px 0 12px;
  font-size: 1.25rem;
}
.tutorial-body {
  min-height: 9em;
  font-size: 0.95rem;
}
.tutorial-body p + p,
.tutorial-body ul + p {
  margin-top: 0.6em;
}
.tutorial-body ul {
  padding-left: 1.2em;
}
.tutorial-body li + li {
  margin-top: 0.4em;
}
.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
}
.tutorial-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--control-bg);
}
.tutorial-dots span.on {
  background: var(--accent);
}
.tutorial-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tutorial-spacer {
  flex: 1;
}
.tutorial .control.primary {
  background: var(--accent);
  color: #fff;
}
.tutorial .control[hidden] {
  display: none;
}
.text-link {
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
