:root {
  --bg: rgba(22, 24, 33, 0.86);
  --bg-soft: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef0f6;
  --muted: rgba(238, 240, 246, 0.55);
  --track: rgba(255, 255, 255, 0.08);
  --accent: #ff7a6b;
  --accent-2: #ffb36b;
  --radius: 22px;
}

body[data-mode="short"] { --accent: #4fd1a5; --accent-2: #7be0c3; }
body[data-mode="long"]  { --accent: #6fa8ff; --accent-2: #a58bff; }

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  background: transparent;
  overflow: hidden;
  user-select: none;
}

body {
  font-family: "Segoe UI Variable", "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--text);
  padding: 8px;
  -webkit-app-region: drag;
}

button, input, .settings { -webkit-app-region: no-drag; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- カード ---- */
.card {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px 14px;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 70% at 50% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%),
    var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  transition: background 0.6s ease;
}

.titlebar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mode-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  transition: color 0.4s, background 0.4s;
}

.win-buttons { display: flex; gap: 2px; }

.icon-btn {
  width: 26px;
  height: 26px;
  padding: 6px;
  border-radius: 8px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn.close:hover { background: rgba(255, 90, 90, 0.2); color: #ff8a8a; }

/* ---- ダイヤル ---- */
.dial {
  position: relative;
  width: 196px;
  height: 196px;
  margin-top: 14px;
}

.ring { transform: rotate(-90deg); }

.ring circle {
  fill: none;
  stroke-width: 8;
}
.ring-track { stroke: var(--track); }
.ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear, stroke 0.4s;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 60%, transparent));
}

.dial-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.time {
  font-size: 46px;
  font-weight: 300;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.task {
  width: 130px;
  font: inherit;
  font-size: 12px;
  text-align: center;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 2px 0;
  outline: none;
}
.task:hover, .task:focus { border-bottom-color: var(--border); color: var(--text); }
.task::placeholder { color: rgba(238, 240, 246, 0.3); }

/* ---- サイクルの点 ---- */
.dots {
  display: flex;
  gap: 7px;
  margin-top: 12px;
  min-height: 7px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--track);
  transition: background 0.3s;
}
.dot.done { background: var(--accent); }

/* ---- 操作ボタン ---- */
.controls {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-top: 14px;
}

.ctrl-btn {
  width: 38px;
  height: 38px;
  padding: 10px;
  border-radius: 50%;
  color: var(--muted);
  background: var(--bg-soft);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.ctrl-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.11); }

.play-btn {
  width: 56px;
  height: 56px;
  padding: 16px;
  border-radius: 50%;
  color: #1a1b22;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform 0.1s, box-shadow 0.2s;
}
.play-btn:hover { transform: scale(1.05); }
.ctrl-btn:active, .play-btn:active { transform: scale(0.94); }
.play-btn .icon-play path { fill: currentColor; }
.play-btn svg { stroke-width: 2.6; }

.icon-pause { display: none; }
body.running .icon-play { display: none; }
body.running .icon-pause { display: block; }

.stats {
  margin-top: auto;
  font-size: 11px;
  color: var(--muted);
}
.stats strong { color: var(--text); font-weight: 600; }

/* ---- 設定パネル ---- */
.settings {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(18, 20, 28, 0.97);
  border-radius: var(--radius);
  padding: 12px 16px;
  user-select: none;
}
.settings[hidden] { display: none; }

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.settings-body {
  overflow-y: auto;
  padding-right: 2px;
}
.settings-body::-webkit-scrollbar { width: 4px; }
.settings-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.row input[type="number"] {
  width: 56px;
  font: inherit;
  color: var(--text);
  text-align: right;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  outline: none;
}
.row input[type="number"]:focus { border-color: var(--accent); }
.row input[type="checkbox"], .row input[type="range"] { accent-color: var(--accent); }
.row input[type="range"] { width: 96px; }

.text-btn {
  margin-top: 10px;
  width: 100%;
  font-size: 12px;
  padding: 7px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--bg-soft);
}
.text-btn:hover { color: #ff8a8a; background: rgba(255, 90, 90, 0.12); }

/* ---- サウンドパネル ---- */
body.sound-on #soundBtn { color: var(--accent); }

.sound-master {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 10px;
}
.sound-master svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.sound-master input { flex: 1; min-width: 0; accent-color: var(--accent); }

.mini-btn {
  flex: none;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--muted);
  background: var(--bg-soft);
}
.mini-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.11); }

.sound-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 4px;
}

.sound-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 8px 7px 6px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}
.sound-tile.on {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.sound-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 11px;
  text-align: left;
  white-space: nowrap;
  color: var(--muted);
}
.sound-toggle svg { width: 17px; height: 17px; flex: none; stroke-width: 1.8; }
.sound-tile.on .sound-toggle { color: var(--text); }
.sound-tile.on .sound-toggle svg { color: var(--accent); }

.sound-tile input[type="range"] {
  width: 100%;
  height: 14px;
  accent-color: var(--accent);
  opacity: 0.35;
  transition: opacity 0.2s;
}
.sound-tile.on input[type="range"] { opacity: 1; }

/* ---- コンパクト表示 ---- */
body.compact { padding: 4px; }
body.compact .card { display: none; }

.pill {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 16px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.pill[hidden] { display: none; }

.pill-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
body.running .pill-dot { animation: pulse 2s ease-in-out infinite; }

.pill-time {
  flex: 1;
  font-size: 24px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
}

.pill .icon-btn { width: 30px; height: 30px; padding: 7px; }
.pill .icon-play path { fill: currentColor; }

@keyframes pulse {
  50% { opacity: 0.35; }
}

/* 終了時のフラッシュ */
body.flash .card, body.flash .pill { animation: flash 0.6s ease 3; }
@keyframes flash {
  50% { box-shadow: 0 0 0 3px var(--accent); }
}

/* ---- ブラウザ / スマホ版 ---- */
.web-only { display: none; }
body.web .web-only { display: flex; }
body.web .desktop-only { display: none; }

body.web {
  --bg: #161821;
  min-height: 100dvh;
  padding: 0;
  background: #0f1117;
  -webkit-app-region: no-drag;
  -webkit-tap-highlight-color: transparent;
}

body.web .card {
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(16px + env(safe-area-inset-top)) 20px
    calc(20px + env(safe-area-inset-bottom));
  border: none;
  border-radius: 0;
  box-shadow: none;
}

body.web .titlebar { gap: 8px; }
body.web .mode-label { font-size: 14px; padding: 6px 14px; }
body.web .icon-btn { width: 40px; height: 40px; padding: 9px; border-radius: 12px; }

body.web .dial {
  width: min(78vw, 320px);
  height: min(78vw, 320px);
  margin-top: auto;
}
body.web .time { font-size: clamp(56px, 18vw, 76px); }
body.web .task { width: 70%; font-size: 15px; }

body.web .dots { gap: 10px; margin-top: 24px; }
body.web .dot { width: 9px; height: 9px; }

body.web .controls { gap: 36px; margin-top: 28px; margin-bottom: auto; }
body.web .ctrl-btn { width: 54px; height: 54px; padding: 15px; }
body.web .play-btn { width: 80px; height: 80px; padding: 23px; }

body.web .stats { margin-top: 24px; font-size: 13px; }

body.web .settings {
  padding:
    calc(16px + env(safe-area-inset-top)) 20px
    calc(16px + env(safe-area-inset-bottom));
  border-radius: 0;
}
body.web .settings-head { font-size: 16px; margin-bottom: 10px; }
body.web .row { font-size: 15px; padding: 12px 0; }
body.web .row input[type="number"] { width: 72px; font-size: 16px; padding: 6px 8px; }
body.web .row input[type="checkbox"] { width: 20px; height: 20px; }
body.web .row input[type="range"] { width: 140px; }
body.web .text-btn { font-size: 14px; padding: 12px; }

body.web .sound-master { padding-bottom: 14px; }
body.web .sound-master svg { width: 20px; height: 20px; }
body.web .mini-btn { font-size: 13px; padding: 8px 12px; }
body.web .sound-grid { gap: 10px; }
body.web .sound-tile { padding: 12px 12px 10px; gap: 10px; border-radius: 16px; }
body.web .sound-toggle { font-size: 14px; gap: 8px; }
body.web .sound-toggle svg { width: 22px; height: 22px; }
body.web .sound-tile input[type="range"] { height: 22px; }

/* 横に広い画面（PC のブラウザ）ではカードとして中央に置く */
@media (min-width: 600px) and (min-height: 700px) {
  body.web { display: flex; align-items: center; justify-content: center; }
  body.web .card {
    width: 400px;
    min-height: 0;
    height: 680px;
    border: 1px solid var(--border);
    border-radius: 28px;
  }
  body.web .settings { border-radius: 28px; padding: 16px 20px; }
  body.web .dial { width: 300px; height: 300px; }
}
