:root {
  /* warm base palette */
  --bg: #fff5ec;
  --bg-2: #ffe9d6;
  --card: #fffaf4;
  --ink: #5a3d2b;
  --ink-soft: #9a7a63;
  --line: #f0dcc8;
  --accent: #e2603a;        /* terracotta */
  --accent-2: #f59e5b;      /* amber */
  --shadow: 0 18px 40px -22px rgba(120, 60, 30, 0.45);
  --ring-track: #f4ddc8;
  --ring-fill: #e2603a;
  font-size: 16px;
}

/* phase-driven theme shifts (warm throughout) */
body.phase-work {
  --bg: #fff4ea; --bg-2: #ffe2cc; --accent: #e2603a; --accent-2: #f59e5b; --ring-fill: #e2603a;
}
body.phase-short {
  --bg: #fff3e3; --bg-2: #ffe7c4; --accent: #e8973a; --accent-2: #f4c06a; --ring-fill: #e8973a;
}
body.phase-long {
  --bg: #fdeede; --bg-2: #f7dab6; --accent: #d4762e; --accent-2: #e9a85a; --ring-fill: #d4762e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Zen Maru Gothic", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-2), transparent 60%),
    linear-gradient(160deg, var(--bg), #fff);
  transition: --bg 0.6s;
  display: flex;
  justify-content: center;
  padding:
    calc(28px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(48px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

.app { width: 100%; max-width: 520px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.brand {
  font-family: "Zen Maru Gothic", sans-serif;
  font-size: 1.3rem; margin: 0; letter-spacing: 0.5px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  width: 38px; height: 38px; border-radius: 12px; font-size: 1.1rem; cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.cal-badge {
  font-size: .72rem; padding: 6px 10px; border-radius: 999px; font-weight: 600;
  border: 1px solid var(--line);
}
.cal-off { background: #fbeede; color: var(--ink-soft); }
.cal-on { background: #e6f6e6; color: #3f7d3f; border-color: #cdeccd; }
.cal-err { background: #fde0d8; color: #b6442a; border-color: #f4c5b8; }

/* timer stage */
.timer-stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 22px 22px 26px;
  box-shadow: var(--shadow);
}

.phase-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 18px; }
.phase-tab {
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft);
  padding: 8px 16px; border-radius: 999px; font-weight: 600; cursor: pointer; font-size: .85rem;
  transition: all .15s;
}
.phase-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent; box-shadow: 0 8px 18px -10px var(--accent);
}

/* task bar */
.task-bar { margin: 0 auto 14px; max-width: 400px; }
.task-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.task-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  padding: 7px 12px; border-radius: 999px; font-size: .82rem; font-weight: 600;
  cursor: pointer; max-width: 220px; font-family: inherit; transition: all .12s;
}
.task-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent; box-shadow: 0 6px 14px -8px var(--accent);
}
.task-chip .chip-x {
  border: none; background: transparent; color: inherit; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 0 0 2px; opacity: .55; font-family: inherit;
}
.task-chip .chip-x:hover { opacity: 1; }
.task-add { display: flex; justify-content: center; }
.task-input {
  width: 100%; max-width: 280px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 14px; padding: 10px 16px; font-size: .9rem; font-weight: 600;
  text-align: center; font-family: inherit;
}
.task-input::placeholder { color: var(--ink-soft); font-weight: 500; }
.task-input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }

.ring-wrap {
  position: relative; width: 300px; max-width: 86vw; margin: 4px auto 10px; aspect-ratio: 1;
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  border-radius: 50%;
}
.ring-wrap:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 4px; }
/* tap feedback elements (animated via JS Web Animations API, then removed) */
.ring-ripple {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid var(--accent); pointer-events: none;
}
.ring-tap-icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 3.4rem; color: var(--accent); pointer-events: none; line-height: 1;
}
.ring-hint {
  font-size: .72rem; color: var(--ink-soft); margin-top: 6px; letter-spacing: 1px;
  opacity: .8;
}
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 16; }
.ring-progress {
  fill: none; stroke: var(--ring-fill); stroke-width: 16; stroke-linecap: round;
  stroke-dasharray: 879.6; stroke-dashoffset: 0;
  transition: stroke-dashoffset .35s linear, stroke .5s;
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
.time { font-size: 3.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.phase-label { font-family: "Zen Maru Gothic"; color: var(--ink-soft); font-weight: 700; letter-spacing: 2px; }
.cycle-dots { display: flex; gap: 6px; margin-top: 8px; }
.cycle-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ring-track); }
.cycle-dots .dot.done { background: var(--accent); }

.controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 14px 0 6px; }
.ctrl-btn {
  border: none; cursor: pointer; font-weight: 700; transition: transform .12s, box-shadow .12s, filter .12s;
}
.ctrl-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 1.05rem; padding: 14px 42px; border-radius: 16px;
  box-shadow: 0 14px 26px -12px var(--accent); min-width: 150px;
}
.ctrl-btn.primary:hover { transform: translateY(-2px); }
.ctrl-btn.small {
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  width: 48px; height: 48px; border-radius: 14px; font-size: 1.2rem;
}
.ctrl-btn.small:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.ctrl-btn.wide { width: auto; padding: 10px 18px; }

/* finish-and-record (early completion) button — shown only during a work session */
.finish-btn {
  display: block; margin: 12px auto 0; padding: 9px 20px; border-radius: 999px;
  border: 1px solid var(--accent); background: var(--card); color: var(--accent);
  font-weight: 700; font-size: .85rem; cursor: pointer; font-family: inherit;
  transition: transform .12s, box-shadow .12s;
}
.finish-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.finish-btn:active { transform: translateY(0); }
.finish-btn.hidden { display: none; }

/* noise bar */
.noise-bar { display: flex; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.noise-label { font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.noise-options { display: flex; gap: 6px; flex-wrap: wrap; }
.noise-chip {
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft);
  padding: 6px 12px; border-radius: 999px; font-size: .78rem; cursor: pointer; font-weight: 600;
}
.noise-chip.active { background: var(--accent); color: #fff; border-color: transparent; }
.vibe-chip { margin-left: 6px; position: relative; }
.vibe-chip::before {
  content: ""; position: absolute; left: -7px; top: 20%; bottom: 20%;
  width: 1px; background: var(--line);
}
.noise-vol { flex: 1; min-width: 100px; accent-color: var(--accent); }

/* stats */
.stats {
  margin-top: 20px; background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 18px 20px; box-shadow: var(--shadow);
}
.stats-head { display: flex; align-items: baseline; justify-content: space-between; }
.stats-head h2 { font-family: "Zen Maru Gothic"; font-size: 1rem; margin: 0; }
.stats-today { display: flex; gap: 16px; color: var(--ink-soft); font-size: .85rem; }
.stats-today b { color: var(--accent); font-size: 1.05rem; }
.week-chart { display: flex; align-items: flex-end; gap: 10px; height: 120px; margin-top: 16px; }
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week-bar {
  width: 70%; max-width: 34px; border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  min-height: 4px; transition: height .4s;
}
.week-bar.empty { background: var(--ring-track); }
.week-day { font-size: .7rem; color: var(--ink-soft); }
.week-val { font-size: .68rem; color: var(--ink-soft); font-weight: 700; height: 12px; }
.week-col.is-today .week-day { color: var(--accent); font-weight: 700; }

/* task totals */
.task-totals-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 22px; }
.task-totals-head h3 { font-family: "Zen Maru Gothic"; font-size: .92rem; margin: 0; }
.task-totals { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.task-row.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.task-pick {
  border: none; background: transparent; color: var(--ink); font-weight: 700; font-size: .9rem;
  cursor: pointer; text-align: left; padding: 0; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: inherit;
}
.task-pick:hover { color: var(--accent); }
.task-meta { color: var(--ink-soft); font-size: .8rem; white-space: nowrap; }
.task-meta b { color: var(--accent); font-size: .92rem; }
.task-empty { color: var(--ink-soft); font-size: .82rem; padding: 6px 2px; }

/* settings sheet */
.overlay {
  position: fixed; inset: 0; background: rgba(90, 50, 25, .35);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }
.sheet {
  background: var(--card); width: 100%; max-width: 520px; border-radius: 24px 24px 0 0;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 -20px 50px -20px rgba(120,60,30,.5);
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.sheet-head h2 { font-family: "Zen Maru Gothic"; margin: 0; }
.sheet-body { padding: 8px 20px 28px; }
.sheet-body h3 { font-family: "Zen Maru Gothic"; font-size: .95rem; margin: 4px 0 6px; }
.sheet-body hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.hint { font-size: .78rem; color: var(--ink-soft); line-height: 1.5; margin: 0 0 12px; }
.hint code { background: var(--bg-2); padding: 1px 5px; border-radius: 5px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 6px; }
.field-grid label, .stack {
  display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--ink-soft); font-weight: 600;
}
.stack { margin: 10px 0; }
.field-grid input, .stack input {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: .95rem;
  color: var(--ink); background: #fff;
}
.field-grid input:focus, .stack input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; font-size: .9rem; font-weight: 600; border-bottom: 1px solid var(--line);
}
.toggle-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.sound-ctrls { display: flex; align-items: center; gap: 8px; }
.sound-ctrls select {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: .9rem;
  color: var(--ink); background: #fff; font-family: inherit; font-weight: 600;
}
.sound-ctrls select:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.preview-btn {
  border: 1px solid var(--accent); background: var(--card); color: var(--accent);
  border-radius: 10px; padding: 8px 12px; font-size: .82rem; font-weight: 700;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.preview-btn:hover { background: var(--bg-2); }
.cal-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.cal-status { font-size: .8rem; color: var(--ink-soft); }

@media (max-width: 420px) {
  .time { font-size: 3rem; }
  .ctrl-btn.primary { padding: 14px 30px; min-width: 130px; }
}
