:root {
  color-scheme: light;

  /* Apple Japan palette */
  --bg: #ffffff;
  --surface: #f5f5f7;
  --ink: #1d1d1f;          /* primary text (not pure black) */
  --muted: #6e6e73;        /* secondary glyph gray */
  --muted-soft: rgba(0, 0, 0, 0.56);
  --line: rgba(0, 0, 0, 0.1);
  --blue: #0071e3;         /* CTA */
  --blue-hover: #0077ed;
  --link: #0066cc;
  --alert: #d70015;        /* restrained system red for over-target */
  --focus: rgba(0, 113, 227, 0.32);

  --radius-card: 18px;
  --radius-input: 12px;
  --pill: 980px;

  --font-text: "SF Pro JP", "SF Pro Text", "SF Pro Icons",
    "Hiragino Kaku Gothic Pro", "ヒラギノ角ゴ Pro W3",
    メイリオ, Meiryo, "ＭＳ Ｐゴシック",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: "SF Pro JP", "SF Pro Display", "SF Pro Icons",
    "Hiragino Kaku Gothic Pro", "ヒラギノ角ゴ Pro W3",
    メイリオ, Meiryo, "ＭＳ Ｐゴシック",
    "Helvetica Neue", Helvetica, Arial, sans-serif;

  font-family: var(--font-text);
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
  letter-spacing: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.app {
  width: min(100%, 430px);
  margin: 0 auto;
  padding:
    max(28px, env(safe-area-inset-top))
    22px
    max(40px, env(safe-area-inset-bottom));
}

/* ---------- Masthead ---------- */

.masthead {
  text-align: center;
  margin-bottom: 30px;
}

h1 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.lede {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
}

/* ---------- Meter (hero) ---------- */

.meter {
  text-align: center;
  padding: 8px 0 4px;
}

.meter-time {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.meter-total {
  font-family: var(--font-display);
  margin: 2px 0 4px;
  font-size: clamp(68px, 23vw, 96px);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: color 0.3s ease;
}

.meter-caption {
  margin: 0;
  min-height: 1.4em;
  color: var(--muted);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

.progress {
  margin: 20px auto 0;
  width: 100%;
  height: 6px;
  border-radius: var(--pill);
  background: rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.progress-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: var(--pill);
  background: var(--blue);
  transition: width 0.25s linear, background-color 0.3s ease;
}

/* Over-target alert state */
.meter.is-over .meter-total,
.meter.is-over .meter-caption {
  color: var(--alert);
}

.meter.is-over .progress-fill {
  background: var(--alert);
}

/* ---------- Actions ---------- */

.actions {
  margin-top: 28px;
  display: grid;
  gap: 14px;
}

.btn {
  border: 0;
  border-radius: var(--pill);
  cursor: pointer;
  font-family: var(--font-text);
  white-space: nowrap;
}

.btn-primary {
  min-height: 52px;
  padding: 0 22px;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 400;
  transition: background-color 0.2s ease;
}

.btn-primary:hover {
  background: var(--blue-hover);
}

.btn-primary.is-running {
  background: var(--surface);
  color: var(--ink);
}

.btn-primary.is-running:hover {
  background: #ececee;
}

.actions-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.btn-text {
  min-height: 44px;
  padding: 0 6px;
  background: transparent;
  color: var(--link);
  font-size: 15px;
}

.btn-text:hover {
  text-decoration: underline;
}

.btn-text:disabled {
  color: var(--muted);
  opacity: 0.5;
  cursor: not-allowed;
  text-decoration: none;
}

.btn-quiet {
  color: var(--muted);
}

.dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--line);
}

/* ---------- Segmented (target) ---------- */

.segmented {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: var(--surface);
  border-radius: 14px;
}

.seg {
  min-height: 40px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.seg.is-active {
  background: var(--bg);
  color: var(--ink);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ---------- Breakdown ---------- */

.breakdown {
  margin-top: 30px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.bd-item {
  display: grid;
  gap: 5px;
  justify-items: center;
  padding: 18px 8px;
}

.bd-item + .bd-item {
  box-shadow: -1px 0 0 var(--line);
}

.bd-label {
  color: var(--muted);
  font-size: 13px;
}

.bd-value {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.usage {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.usage span {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- Disclosure (settings) ---------- */

.disclosure {
  margin-top: 30px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 2px;
  font-size: 15px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.disclosure[open] summary::after {
  transform: rotate(-135deg);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 6px 0 4px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-input);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

small {
  color: var(--muted);
  font-size: 12px;
}

.assumption {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.source {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- History ---------- */

.history {
  margin-top: 30px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.history-list {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 14px 2px;
  border-top: 1px solid var(--line);
}

.history-main {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.history-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.history-score {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-empty {
  margin: 0;
  padding: 14px 2px;
  color: var(--muted);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
