:root {
  --brown:   #7c5a3a;
  --brown-d: #5f4630;
  --cream:   #fff6e6;
  --cream-2: #f3e3c4;
  --line:    #f0d9c2;
  --card:    #fffdf8;
  --gold:    #e8b54a;
  --danger:  #e06b5e;
  --shadow:  0 4px 14px rgba(95, 70, 48, 0.16);

  /* フェーズ色（body[data-phase] で切替） */
  --work:    #e0533c;
  --work-d:  #c8432e;
  --short:   #38b09a;
  --short-d: #2c9080;
  --long:    #5a8fd6;
  --long-d:  #4374bf;
  --accent:  var(--work);
  --accent-d:var(--work-d);
}

body[data-phase="short"] { --accent: var(--short); --accent-d: var(--short-d); }
body[data-phase="long"]  { --accent: var(--long);  --accent-d: var(--long-d); }

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

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

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color: var(--brown-d);
  background:
    radial-gradient(circle at 50% -8%, color-mix(in srgb, var(--accent) 22%, #fff) 0%, transparent 60%),
    linear-gradient(170deg, #fbf1e0 0%, #f3e0c2 100%);
  background-attachment: fixed;
  -webkit-user-select: none; user-select: none;
  transition: background .4s ease;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
}

/* ---- ヘッダー ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 2px 6px; }
.logo { font-size: 1.18rem; margin: 0; letter-spacing: .01em; }
.paw { filter: drop-shadow(0 1px 1px rgba(0,0,0,.12)); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: #fff; color: var(--brown);
  font-size: 1.05rem; box-shadow: var(--shadow); cursor: pointer;
}
.icon-btn:active { transform: scale(.92); }

/* ---- フェーズタブ ---- */
.phase-tabs {
  display: flex; gap: 6px; background: #fff;
  padding: 5px; border-radius: 999px; box-shadow: var(--shadow);
  margin: 10px 0 6px;
}
.phase-tab {
  flex: 1; border: none; background: none; cursor: pointer;
  padding: 9px 4px; border-radius: 999px;
  font-size: .92rem; font-weight: 800; color: var(--brown);
  transition: background .2s, color .2s;
}
.phase-tab.active { background: var(--accent); color: #fff; }

/* ---- タイマー ---- */
.timer-area { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px 0; }
.ring-wrap { position: relative; width: min(78vw, 320px); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #fff; stroke-width: 14; opacity: .65; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 678.58; stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke .4s ease;
  filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--accent) 45%, transparent));
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
}
.cat-stage { width: 36%; max-width: 116px; aspect-ratio: 1.2; margin-bottom: 2px; }
.cat-stage svg { width: 100%; height: 100%; display: block; }
.time {
  font-size: 3.1rem; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
  color: var(--brown-d);
}
.phase-label { font-size: .92rem; font-weight: 700; color: var(--accent-d); }

body.running .cat-stage { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ---- サイクルドット ---- */
.cycle-dots { display: flex; gap: 8px; margin: 14px 0 4px; min-height: 16px; }
.cycle-dots .dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; box-shadow: inset 0 0 0 2px var(--cream-2);
  transition: background .2s, transform .2s;
}
.cycle-dots .dot.done { background: var(--accent); box-shadow: none; transform: scale(1.05); }

.cat-msg {
  text-align: center; font-size: .92rem; font-weight: 600;
  color: var(--brown); margin: 8px 12px 4px; min-height: 1.3em; line-height: 1.4;
}

/* ---- コントロール ---- */
.controls { display: flex; align-items: center; gap: 16px; margin-top: 10px; }
.ctrl-btn {
  border: none; cursor: pointer; font-family: inherit;
  background: #fff; color: var(--brown-d);
  width: 56px; height: 56px; border-radius: 50%;
  font-size: 1.4rem; box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.ctrl-btn:active { transform: scale(.92); }
.ctrl-btn.main {
  width: 150px; height: 60px; border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 1.15rem; font-weight: 800;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ---- 統計 ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat-box { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 6px; text-align: center; box-shadow: var(--shadow); }
.stat-num { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.stat-num small { font-size: .8rem; font-weight: 700; }
.stat-cap { font-size: .72rem; color: var(--brown); opacity: .82; margin-top: 5px; }

/* ---- モーダル共通 ---- */
.hidden { display: none !important; }
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(75,55,38,0.42); }
.modal-card {
  position: relative; width: 100%; max-width: 480px;
  background: var(--cream); border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
  max-height: 90dvh; overflow-y: auto; animation: slideUp .26s ease;
}
.modal-card h2 { margin: 0 0 12px; font-size: 1.2rem; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

.btn {
  border: none; border-radius: 12px; padding: 13px 16px;
  font-size: 1rem; font-weight: 800; font-family: inherit; cursor: pointer;
  background: #fff; color: var(--brown-d); box-shadow: var(--shadow);
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: #fff; color: var(--danger); }

/* ---- 設定 ---- */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.setting-row label { font-size: .94rem; font-weight: 600; flex: 1; }
.num-input {
  width: 76px; text-align: center; border: 1.5px solid var(--line);
  border-radius: 10px; padding: 9px; font-size: 1rem; font-family: inherit;
  color: var(--brown-d); background: #fff; -webkit-user-select: text; user-select: text;
}
.num-input:focus { outline: none; border-color: var(--accent); }
.hint { font-size: .78rem; color: var(--brown); opacity: .75; margin: 8px 2px 0; line-height: 1.5; }

/* トグルスイッチ */
.switch { appearance: none; -webkit-appearance: none; position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--cream-2); cursor: pointer; transition: background .2s; flex: 0 0 auto; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* ---- バッジ ---- */
.badge-sub { font-size: .85rem; color: var(--brown); margin: -6px 0 14px; }
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.badge {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 6px 10px; text-align: center; box-shadow: var(--shadow);
}
.badge.locked { opacity: .55; filter: grayscale(.85); }
.badge-ill { width: 60px; height: 60px; margin: 0 auto 6px; position: relative; }
.badge-ill svg { width: 100%; height: 100%; }
.badge-ring { position: absolute; inset: -3px; border-radius: 50%; border: 3px solid var(--gold); }
.badge-name { font-size: .76rem; font-weight: 800; line-height: 1.25; }
.badge-need { font-size: .68rem; color: var(--brown); opacity: .8; margin-top: 2px; }

/* ---- お祝い ---- */
.reward-card { text-align: center; }
.reward-badge { width: 130px; height: 130px; margin: 6px auto 4px; position: relative; animation: pop .5s ease; }
.reward-badge svg { width: 100%; height: 100%; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.reward-name { font-size: 1.15rem; font-weight: 800; margin: 4px 0; }
.reward-desc { font-size: .9rem; color: var(--brown); margin: 0 0 6px; }

.howto { padding-left: 1.1em; line-height: 1.7; font-size: .92rem; }
.howto li { margin-bottom: 7px; }

/* ---- トースト ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%) translateY(10px);
  background: var(--brown-d); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,0.28);
  z-index: 40; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
