/* ===== TimerTrain — Apple-minimal design ===== */
:root {
  --bg: #FFF9EE;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --text2: #8E8E93;
  --line: rgba(0,0,0,.06);
  --accent: #1C1C1E;
  --accent-text: #FFFFFF;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --card: #1C1C1E;
    --text: #F2F2F7;
    --text2: #8E8E93;
    --line: rgba(255,255,255,.08);
    --accent: #F2F2F7;
    --accent-text: #111113;
    --shadow: none;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100%;
  line-height: 1.6;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.app { max-width: 460px; margin: 0 auto; padding: 24px 16px calc(48px + env(safe-area-inset-bottom)); }

.header { text-align: center; margin-bottom: 24px; }
.logo { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.tagline { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ---- timer list ---- */
.timer-list { list-style: none; }
.timer-row {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px 12px 6px 14px; margin-bottom: 10px;
  touch-action: pan-y;
  transition: transform .15s ease, opacity .15s ease;
}
.timer-row.dragging { opacity: .85; transform: scale(1.02); position: relative; z-index: 5; transition: none; }
.color-dot {
  width: 22px; height: 22px; border-radius: 50%;
  flex-shrink: 0; border: none;
  transition: transform .1s ease;
}
.color-dot:active { transform: scale(1.2); }
.name-input {
  flex: 1; min-width: 0;
  border: none; background: none; color: var(--text);
  font-size: 16px; font-weight: 500; padding: 12px 0;
  outline: none;
}
.name-input::placeholder { color: var(--text2); }
.time-btn {
  font-size: 22px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 8px 6px; border-radius: 10px;
  letter-spacing: -.01em;
}
.time-btn:hover { background: var(--line); }
.time-input {
  width: 92px; font-size: 22px; font-weight: 600; text-align: right;
  font-variant-numeric: tabular-nums;
  border: none; border-bottom: 2px solid var(--text); background: none; color: var(--text);
  outline: none; padding: 8px 2px;
}
.dup-btn { color: var(--text2); font-size: 15px; padding: 10px 4px; border-radius: 8px; }
.dup-btn:hover { color: var(--text); }
.del-btn { color: var(--text2); font-size: 15px; padding: 10px 4px; border-radius: 8px; }
.del-btn:hover { color: #FF6B6B; }
.drag-handle { color: var(--text2); font-size: 16px; padding: 10px 2px 10px 6px; cursor: grab; touch-action: none; user-select: none; }
.drag-handle:active { cursor: grabbing; }

.add-btn {
  width: 100%; padding: 14px; margin: 4px 0 20px;
  border: 1.5px dashed var(--text2); border-radius: var(--radius);
  color: var(--text2); font-size: 15px; font-weight: 500;
}
.add-btn:hover { color: var(--text); border-color: var(--text); }

/* ---- repeat ---- */
.repeat-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.repeat-label { font-size: 15px; color: var(--text2); }
.repeat-ctrl { display: flex; align-items: center; gap: 4px; }
.repeat-ctrl button {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 18px; color: var(--text);
}
.repeat-ctrl button.active { background: var(--accent); color: var(--accent-text); }
#rep-count { min-width: 56px; text-align: center; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

.total-row { text-align: right; font-size: 13px; color: var(--text2); margin-bottom: 20px; min-height: 1.2em; }

/* ---- actions ---- */
.action-row { display: flex; gap: 10px; }
.share-btn {
  padding: 16px 18px; border-radius: 999px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 15px; font-weight: 500;
}
.start-btn {
  flex: 1; padding: 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-size: 17px; font-weight: 700; letter-spacing: .02em;
  transition: transform .1s ease;
}
.start-btn:active { transform: scale(.98); }

/* ---- run view ---- */
.run {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.run.hidden, .hidden { display: none; }
.close-btn { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 20px; font-size: 20px; color: var(--text2); padding: 10px; }
.run-cycle { font-size: 14px; color: var(--text2); font-variant-numeric: tabular-nums; }
.run-name { font-size: 20px; font-weight: 600; color: var(--text2); margin-bottom: 2px; }
.run-time {
  font-size: clamp(44px, 14vw, 68px); font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
  line-height: 1.1;
}
.run-time.finished { font-size: clamp(28px, 8vw, 40px); }

/* ---- progress ring ---- */
.ring-wrap { position: relative; width: min(78vw, 340px); aspect-ratio: 1; margin: 16px 0 24px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); display: block; }
.ring circle { fill: none; stroke-width: 4.5; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--text2); stroke-linecap: round; transition: stroke-dashoffset .2s linear, stroke .3s ease; }
.ring-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12%; text-align: center;
}

/* ---- color picker ---- */
.color-pop {
  position: absolute; left: 10px; top: calc(100% - 4px); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 9px; max-width: 320px;
  background: var(--card); padding: 12px 14px; border-radius: 20px;
  box-shadow: 0 6px 28px rgba(0,0,0,.16);
}
.color-pop button { width: 27px; height: 27px; border-radius: 50%; transition: transform .1s ease; }
.color-pop button:hover { transform: scale(1.15); }
.color-pop button.sel { outline: 2.5px solid var(--text); outline-offset: 2px; }

.stations { display: flex; align-items: center; gap: 0; margin-bottom: 32px; }
.station {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--line); flex-shrink: 0;
}
.station.done { opacity: .45; }
.station.now { transform: scale(1.5); box-shadow: 0 0 0 4px var(--line); }
.rail { width: 18px; height: 2px; background: var(--line); flex-shrink: 0; }

.run-controls { display: flex; align-items: center; gap: 18px; }
.run-controls button {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 22px;
}
#pause-btn { width: 84px; height: 84px; font-size: 30px; background: var(--accent); color: var(--accent-text); }
.run-hint { position: absolute; bottom: calc(20px + env(safe-area-inset-bottom)); font-size: 12px; color: var(--text2); width: 100%; left: 0; }
@media (max-width: 600px) { .run-hint { display: none; } }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: var(--accent); color: var(--accent-text);
  padding: 10px 20px; border-radius: 999px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- about / footer ---- */
.about { margin-top: 64px; padding-top: 32px; border-top: 1px solid var(--line); }
.about h2 { font-size: 16px; margin: 24px 0 6px; }
.about p { font-size: 14px; color: var(--text2); }
.footer { margin-top: 40px; text-align: center; font-size: 12px; color: var(--text2); }
