* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --accent: #ff3b30;
  --bg: #0a0a0a;
  --card: #1c1c1e;
  --line: #333;
  --muted: #8e8e93;
  --ts: 0.68;
  --tmax: 34vh;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: white;
  font-family: -apple-system, 'Helvetica Neue', 'Hiragino Sans', sans-serif;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}
button { font-family: inherit; }
[hidden] { display: none !important; }

.screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 20px 20px 40px; }

/* ═══ ホーム ═══ */
.home-head { text-align: center; margin: 12px 0 24px; }
.home-head h1 { font-size: 1.9rem; font-weight: 900; letter-spacing: 0.08em; }
.tagline { color: var(--muted); margin-top: 6px; font-size: 0.95rem; }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 480px;
}
.mode-card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 20px;
  padding: 20px 14px 16px;
  text-align: left;
  color: white;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 150px;
}
.mode-card:active { transform: scale(0.97); }
.mode-card .emoji { font-size: 2.2rem; line-height: 1; }
.mode-card .name { font-size: 1.15rem; font-weight: 800; }
.mode-card .desc { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }
.mode-card:hover { border-color: var(--c); box-shadow: 0 0 16px color-mix(in srgb, var(--c) 40%, transparent); }
.mode-card .name { color: var(--c); }

.home-foot { margin-top: 28px; }
.link-btn { background: none; border: 1px solid var(--line); color: var(--muted); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; cursor: pointer; }

/* ═══ タイマー画面 ═══ */
.timer-head {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.timer-head h2 {
  font-size: 1.4rem; font-weight: 900; letter-spacing: 0.15em; color: var(--accent);
  text-shadow: 0 0 20px color-mix(in srgb, var(--accent) 50%, transparent);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px;
}
/* 中央のタイトルが伸びても両端のボタンを押し出さない */
.timer-head .back-btn, .timer-head .size-btn { flex: 0 0 auto; }
.back-btn, .size-btn {
  background: var(--card); border: 1px solid var(--line); color: #ccc;
  padding: 8px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}

.panel { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset-grid.cols2 { grid-template-columns: repeat(2, 1fr); }
.time-btn {
  background: var(--card); border: 2px solid var(--line); color: #ccc;
  padding: 14px 4px; border-radius: 14px; font-size: 1rem; font-weight: 700; cursor: pointer; user-select: none;
  transition: all 0.15s; white-space: nowrap;
}
.time-btn.selected { background: var(--accent); border-color: var(--accent); color: white; box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.time-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.custom-area { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.custom-area .field { flex: 1; min-width: 80px; display: flex; flex-direction: column; gap: 4px; }
.custom-area label { font-size: 0.72rem; color: var(--muted); padding-left: 4px; }
.custom-input {
  width: 100%; background: var(--card); border: 2px solid var(--line); color: white;
  padding: 12px 8px; border-radius: 14px; font-size: 1rem; font-weight: 700; text-align: center;
}
.custom-input::placeholder { color: #555; }
.custom-btn {
  background: var(--card); border: 2px solid #555; color: #ccc;
  padding: 12px 16px; border-radius: 14px; font-size: 0.95rem; font-weight: 700; cursor: pointer; white-space: nowrap; align-self: flex-end;
}
.custom-btn:disabled { opacity: 0.4; }

/* ── 表示 ── */
.stage { width: 100%; display: flex; flex-direction: column; align-items: center; }
.phase-label { font-size: 1.1rem; font-weight: 800; color: var(--accent); letter-spacing: 0.1em; min-height: 1.4em; }
.phase-label.rest { color: #64d2ff; }

body.ts2 { --ts: 0.85; }
body.ts3 { --ts: 1.00; }

.timer-display {
  font-size: calc(var(--ts) * min((100vw - 44px) / 2.80, var(--tmax)));
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  line-height: 1.05;
  margin: 4px 0;
  text-align: center;
  transition: color 0.4s, font-size 0.2s;
}
.timer-display.normal  { color: white; }
.timer-display.rest    { color: #64d2ff; }
.timer-display.warning { color: #ff9500; text-shadow: 0 0 20px rgba(255,149,0,0.4); }
.timer-display.danger  { color: #ff3b30; text-shadow: 0 0 20px rgba(255,59,48,0.5); animation: pulse 0.5s infinite alternate; }
.timer-display.done    { color: var(--accent); animation: pulse 0.8s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.65; } }

.status { font-size: 0.95rem; color: var(--muted); margin: 6px 0 16px; min-height: 1.4em; text-align: center; letter-spacing: 0.05em; }

.progress-wrap { width: 100%; max-width: 380px; height: 6px; background: var(--card); border-radius: 3px; margin-bottom: 10px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 3px; transition: width 0.9s linear, background 0.5s; width: 100%; }
.progress-bar.normal  { background: var(--accent); }
.progress-bar.rest    { background: #64d2ff; }
.progress-bar.warning { background: #ff9500; }
.progress-bar.danger  { background: #ff3b30; }
.progress-bar.done    { background: var(--accent); }

.phase-dots { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; max-width: 380px; margin-bottom: 18px; min-height: 8px; }
.phase-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.phase-dots span.rest { width: 5px; height: 5px; margin-top: 1.5px; }
.phase-dots span.done { background: var(--muted); }
.phase-dots span.cur  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

.controls { display: flex; gap: 8px; width: 100%; max-width: 380px; flex-wrap: wrap; }
.btn-start {
  flex: 2 1 55%; background: #30d158; color: white; border: none; border-radius: 16px;
  padding: 20px; font-size: 1.2rem; font-weight: 800; cursor: pointer; letter-spacing: 0.05em; user-select: none;
  transition: opacity 0.15s, background 0.2s;
}
.btn-start:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-start.running { background: #ff3b30; }
.btn-start.paused  { background: #ff9500; }
.btn-reset {
  flex: 1 1 25%; background: var(--card); color: #ff3b30; border: 2px solid #ff3b30; border-radius: 16px;
  padding: 20px 6px; font-size: 0.9rem; font-weight: 700; cursor: pointer; user-select: none; white-space: nowrap;
}
.btn-sub {
  flex: 1 1 40%; background: var(--card); color: #ccc; border: 2px solid var(--line); border-radius: 16px;
  padding: 14px 6px; font-size: 0.9rem; font-weight: 700; cursor: pointer; user-select: none; white-space: nowrap;
}

/* ═══ PC（横幅900px以上）：2カラム ═══ */
@media (min-width: 900px) {
  body { --pw: 380px; --ts: 0.95; --tmax: 55vh; }
  body.ts2 { --pw: 260px; --ts: 1.00; --tmax: 68vh; }
  body.ts3 { --pw: 0px;   --ts: 1.00; --tmax: 78vh; }

  #timerScreen {
    height: 100vh; padding: 0;
    display: grid;
    grid-template-columns: var(--pw) 1fr;
    grid-template-rows: auto 1fr;
    align-items: stretch; overflow: hidden;
  }
  body.ts3 #timerScreen { grid-template-columns: 1fr; }
  body.ts3 .panel { display: none; }
  body.ts2 .panel { padding: 0 14px; }

  .timer-head { grid-column: 1 / -1; padding: 16px 24px; border-bottom: 1px solid #222; margin: 0; }
  .timer-head h2 { font-size: 2.2rem; }

  .panel { max-width: none; margin: 0; justify-content: center; gap: 16px; padding: 0 28px; border-right: 1px solid #222; background: #0d0d0d; }
  .stage { justify-content: center; gap: 12px; padding: 0 48px; min-width: 0; }
  .time-btn { padding: 20px 0; font-size: 1.2rem; }
  .btn-start { padding: 26px; font-size: 1.5rem; }
  .btn-reset, .btn-sub { padding: 22px 10px; font-size: 1.1rem; }
  .timer-display {
    font-size: calc(var(--ts) * min((100vw - var(--pw) - 96px) / 2.80, var(--tmax)));
    line-height: 1; margin: 0;
  }
  .phase-label { font-size: 1.8rem; }
  .status { font-size: 1.6rem; margin: 0; }
  .progress-wrap, .controls, .phase-dots { max-width: 640px; }
  .progress-wrap { height: 14px; border-radius: 7px; }
  .progress-bar { border-radius: 7px; }

  #home .mode-grid { max-width: 820px; grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .mode-card { min-height: 180px; padding: 26px 20px; }
  .home-head h1 { font-size: 2.6rem; }
}

/* ═══ 複数同時タイマー（料理）═══ */
#multiScreen { max-width: 640px; margin: 0 auto; }
.multi-add { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--card); border: 2px solid var(--line); color: #ccc;
  padding: 8px 12px; border-radius: 999px; font-size: 0.9rem; font-weight: 700; cursor: pointer; user-select: none;
}
.chip.selected { background: var(--accent); border-color: var(--accent); color: #111; }
.custom-btn.accent { background: var(--accent); border-color: var(--accent); color: #111; }
/* 長いラベルは縮まないので、狭い画面では丸ごと次の行へ送る */
.multi-add .custom-btn.accent { flex: 1 1 100%; }
.multi-list { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.multi-item {
  background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 14px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center;
}
/* 配置は必ず明示する。auto配置任せだと「行だけ確定した要素」が先に置かれ、
   時間が1fr列を奪って名前が右のauto列に押し出され、画面外へはみ出す。 */
.multi-item.done { border-color: var(--accent); animation: pulse 0.8s infinite alternate; }
.multi-item.paused { opacity: 0.7; }
.multi-item .mname { grid-column: 1; grid-row: 1; font-size: 1rem; font-weight: 800; color: var(--accent); min-width: 0; overflow-wrap: anywhere; }
.multi-item .mtime { grid-column: 2; grid-row: 1; font-size: 2.4rem; font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.multi-item.done .mtime { font-size: 1.4rem; }
.multi-item .mbar { grid-column: 1 / -1; grid-row: 2; height: 5px; background: #000; border-radius: 3px; overflow: hidden; }
.multi-item .mbar > div { height: 100%; background: var(--accent); transition: width 0.9s linear; }
.multi-item .mbtns { grid-column: 1 / -1; grid-row: 3; display: flex; gap: 6px; margin-top: 4px; }
.multi-item .mbtns button {
  flex: 1; background: #000; border: 1px solid var(--line); color: #ccc; padding: 9px 4px; border-radius: 10px;
  font-size: 0.85rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.multi-item .mbtns button.danger { color: #ff3b30; border-color: #ff3b30; }
.multi-empty { color: var(--muted); font-size: 0.9rem; text-align: center; line-height: 1.6; margin-top: 12px; }
