:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7079;
  --line: #e6e1d9;
  --accent: #2f7d6d;
  --accent-text: #ffffff;
  --accent-soft: #dcefe9;
  --chip: #efebe4;
  --chip-on: #2f7d6d;
  --chip-on-text: #ffffff;
  --win: #2f7d6d;
  --slip: #c9a66b;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --radius: 18px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --card: #1f2227;
    --text: #ebeae6;
    --muted: #9a9ea6;
    --line: #2d3137;
    --accent: #5fb39f;
    --accent-text: #0f1a17;
    --accent-soft: #223a35;
    --chip: #2a2e34;
    --chip-on: #5fb39f;
    --chip-on-text: #0f1a17;
    --win: #5fb39f;
    --slip: #d4b67a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { max-width: 520px; margin: 0 auto; min-height: 100vh; }

.view {
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
.view.is-active { display: flex; }

.h1 { font-size: 28px; font-weight: 700; margin: 4px 0 0; }
.h2 { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
.center { text-align: center; }
.right { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.hero { min-height: 8px; }
.why-line { margin: 0; color: var(--muted); font-style: italic; text-align: center; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-label { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.card-title { font-size: 19px; font-weight: 600; }

.banner { flex-direction: row; align-items: center; justify-content: space-between; background: var(--accent-soft); }
.banner.soft { background: var(--card); }
.banner-title { font-weight: 600; }
.banner-timer { font-size: 26px; font-variant-numeric: tabular-nums; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 56px; padding: 12px 20px; border-radius: 16px;
  font-size: 18px; font-weight: 600; width: 100%;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--chip); color: var(--text); }
.btn-ghost { background: transparent; color: var(--accent); min-height: 48px; }
.btn-wide { background: var(--card); box-shadow: var(--shadow); }
.banner .btn { width: auto; min-height: 48px; padding: 8px 18px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }

.btn-big {
  width: 100%; min-height: 160px; border-radius: 28px;
  background: var(--accent); color: var(--accent-text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  box-shadow: var(--shadow);
  transition: transform .08s ease;
}
.btn-big:active { transform: scale(.985); }
.btn-big-title { font-size: 30px; font-weight: 700; }
.btn-big-sub { opacity: .85; font-size: 15px; }

.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); text-align: center; }
.stat-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 14px; }

.progress { height: 10px; border-radius: 999px; background: var(--chip); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .4s ease; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
}
.list-item .time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; }
.list-item .body { flex: 1; }
.tag { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--chip); white-space: nowrap; }
.tag.win { background: var(--accent-soft); color: var(--win); }
.tag.slip { background: var(--chip); color: var(--text); }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  max-width: 520px; margin: 0 auto;
  z-index: 20;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 13px; font-weight: 600; }
.tab.is-active { color: var(--accent); }
.tab-icon { font-size: 18px; line-height: 1; }

/* Sheets */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-panel {
  position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 24px 24px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  animation: slideUp .22s ease-out;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0 } to { transform: none; opacity: 1 } }
.sheet-handle { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 4px auto 4px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 14px; color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 16px; border-radius: 999px;
  background: var(--chip); font-weight: 600; font-size: 16px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.is-on { background: var(--chip-on); color: var(--chip-on-text); }
.intensity { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.intensity button { min-height: 52px; border-radius: 14px; background: var(--chip); font-size: 20px; font-weight: 700; }
.intensity button.is-on { background: var(--chip-on); color: var(--chip-on-text); }
.note summary { color: var(--muted); cursor: pointer; padding: 6px 0; }
.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  resize: vertical;
}
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.weight-row { display: flex; align-items: center; gap: 12px; justify-content: center; }
.weight-input {
  width: 160px; text-align: center; font-size: 44px; font-weight: 700;
  border: 0; border-bottom: 2px solid var(--line); background: transparent; color: var(--text);
  font-variant-numeric: tabular-nums; -moz-appearance: textfield;
}
.weight-input::-webkit-inner-spin-button, .weight-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.btn-round { width: 60px; height: 60px; border-radius: 50%; background: var(--chip); font-size: 30px; font-weight: 600; }

/* Fullscreen */
.fullscreen { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; }
.pause-inner {
  max-width: 520px; margin: 0 auto; min-height: 100%;
  padding: calc(32px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; justify-content: center; gap: 14px;
}
.pause-label { text-align: center; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-size: 13px; font-weight: 600; }
.pause-timer { text-align: center; font-size: 72px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.pause-alt-label { text-align: center; color: var(--muted); margin-top: 16px; }
.pause-alt { text-align: center; font-size: 30px; font-weight: 700; padding: 0 8px; }
.pause-why { text-align: center; color: var(--muted); font-style: italic; margin: 8px 0 0; min-height: 1.4em; }

/* Progress */
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--chip); padding: 4px; border-radius: 12px; }
.seg { min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg.is-active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.short { height: 180px; }
.insight { display: flex; flex-direction: column; gap: 10px; }
.insight-row { display: flex; gap: 12px; align-items: flex-start; }
.insight-icon { font-size: 22px; width: 30px; text-align: center; }
.insight-title { font-size: 14px; color: var(--muted); }
.insight-value { font-weight: 600; }

/* Me */
.level-row { display: flex; justify-content: space-between; }
.level-value { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.badges { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.badge { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 14px; background: var(--chip); }
.badge.is-on { background: var(--accent-soft); }
.badge:not(.is-on) { opacity: .6; }
.badge-icon { font-size: 24px; }
.badge-name { font-weight: 600; font-size: 15px; }
.badge-sub { font-size: 12px; color: var(--muted); }

.chip-editor { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-editor .chip button { width: 24px; height: 24px; border-radius: 50%; background: rgba(0,0,0,.12); font-size: 14px; line-height: 1; }
.chip-editor .chip.add { background: transparent; border: 2px dashed var(--line); color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-weight: 600; z-index: 60; max-width: 90vw; text-align: center;
  animation: fadeIn .2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 8px) } to { opacity: 1; transform: translateX(-50%) } }

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