/* ============================================================
   Push The Limit — Vesatile visual system
   Brand tokens follow Vesatile_Brand_Identity §8/§11.
   Light values are brand-official; dark tones are derived.
   ============================================================ */
:root {
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg: #F4F4F2;
  --surface: #FBFBF9;
  --surface-2: #ECECE7;
  --ink: #151716;
  --muted: #5C6662;
  --brand: #3B5244;
  --brand-soft: #3B52441a;
  --progress: #7A8581;
  --accent: #8B3A3A;
  --line: #DDDDD5;
  --frame: #3B5244;
  --shadow: 0 1px 2px rgba(21, 23, 22, .05), 0 8px 24px rgba(21, 23, 22, .06);

  --ease-bounce: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.2, .7, .3, 1);
  --focus: var(--accent);
}

[data-theme="dark"] {
  --bg: #111413;
  --surface: #181C1A;
  --surface-2: #1E2320;
  --ink: #EDEEEC;
  --muted: #AEB9B2;
  --brand: #8FB49D;
  --brand-soft: #8FB49D22;
  --progress: #96A29B;
  --accent: #CA6B6B;
  --line: #272C29;
  --frame: #55685C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

/* ------------------------------------------------------- motion layer */
#scroll-progress {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 100;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  pointer-events: none;
}

.bg-decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background-image: radial-gradient(circle, color-mix(in srgb, var(--ink) 7%, transparent) 1px, transparent 1.5px);
  background-size: 26px 26px;
}

.bg-decor span {
  position: absolute;
  display: block;
  font-family: var(--font-mono);
  line-height: 1;
  opacity: .5;
  user-select: none;
  translate: calc(var(--mx, 0px) * var(--dp, 1)) calc(var(--my, 0px) * var(--dp, 1));
  animation: drift var(--dur, 11s) ease-in-out var(--del, 0s) infinite alternate;
}

.bg-decor span:nth-child(even) { animation-direction: alternate-reverse; }
.bg-decor .c-brand { color: var(--brand); }
.bg-decor .c-accent { color: var(--accent); }
.bg-decor .c-muted { color: var(--muted); }

@keyframes drift {
  from { transform: translateY(12px) rotate(-8deg); }
  to { transform: translateY(-12px) rotate(8deg); }
}

.app-header,
.app-main,
.app-footer { position: relative; z-index: 1; }

@keyframes rise-in {
  from { opacity: 0; transform: translateY(18px); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
}

@keyframes tab-in {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes bar-grow {
  from { transform: scaleY(0); }
}

@keyframes cell-in {
  from { opacity: 0; transform: scale(.8); }
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(6px); }
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
}

@keyframes banner-in {
  from { opacity: 0; transform: translateY(-6px); }
}

@keyframes spin-toggle {
  to { transform: rotate(360deg); }
}

@keyframes card-glow {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 35%, transparent), var(--shadow); }
  100% { box-shadow: 0 0 0 14px transparent, var(--shadow); }
}

@keyframes ring-pop {
  40% { stroke-width: 15; }
}

@keyframes spark {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(0deg); }
  10% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(1) rotate(var(--rot, 0deg)); }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding-bottom: 76px;
  transition: background-color .35s ease, color .35s ease;
}

h1, h2, h3, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------ utilities */
.label {
  margin: 0 0 .5rem;
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}

.mono-meta {
  margin: .4rem 0;
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--muted);
}

.hint {
  margin: .35rem 0;
  font-size: .82rem;
  color: var(--muted);
}

.error {
  min-height: 1.2em;
  margin: .4rem 0;
  font-size: .85rem;
  color: var(--accent);
}

.status { min-height: 1.2em; font-size: .82rem; }
.status.is-ok { color: var(--brand); }
.status.is-error { color: var(--accent); }

.empty {
  padding: 1rem 0;
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

/* --------------------------------------------------------------- header */
.app-header { border-bottom: 1px solid var(--line); }

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}

.wordmark {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: .01em;
}

.wordmark .letters span {
  display: inline-block;
  transition: transform .22s var(--ease-bounce), color .22s ease;
}

.wordmark .letters .space { width: .28em; }

.tagline {
  margin-top: .2rem;
  font-family: var(--font-mono);
  font-size: .64rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --------------------------------------------------------- icon buttons */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s var(--ease-out), border-color .2s ease, color .2s ease;
}

#settings-btn.spun { animation: spin-toggle .5s ease; }

.icon-btn:disabled { opacity: .4; cursor: default; }

/* ----------------------------------------------------------------- tabs */
.tabs {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.tab {
  position: relative;
  flex: 1 1 0;
  min-height: 56px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
}

.tab::after {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transform: scaleX(0);
  transform-origin: left;
}

.tab[aria-current="page"] {
  color: var(--brand);
  background: var(--brand-soft);
}

.tab[aria-current="page"]::after {
  transform: scaleX(1);
  animation: tab-in .35s var(--ease-out) forwards;
}

/* ----------------------------------------------------------------- main */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
}

/* -------------------------------------------------------------- banners */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin: 0 0 1.25rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  font-size: .9rem;
  position: relative;
  z-index: 1;
  animation: banner-in .3s var(--ease-out);
}

body > .banner {
  width: calc(100% - 2.5rem);
  max-width: 720px;
  margin: 1rem auto 0;
}

.banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

/* ------------------------------------------------------------ ring card */
.ring-card {
  position: relative;
  margin: .75rem 0 1.75rem;
  padding: 1.5rem 1rem 1.25rem;
  border: 1px solid var(--frame);
  outline: 1px solid var(--frame);
  outline-offset: 5px;
  border-radius: 2px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  transition: outline-offset .35s var(--ease-out), transform .18s ease-out;
}

.ring-card.celebrate { animation: card-glow .7s var(--ease-out); }

.ring.celebrate .ring-fill { animation: ring-pop .6s var(--ease-bounce); }

.corner {
  position: absolute;
  width: 7px;
  height: 7px;
  background: var(--accent);
  transform: rotate(45deg);
  z-index: 2;
  pointer-events: none;
  transition: transform .5s var(--ease-bounce), background .3s ease;
}

.corner.tl { top: -4px; left: -4px; }
.corner.tr { top: -4px; right: -4px; }
.corner.bl { bottom: -4px; left: -4px; }
.corner.br { bottom: -4px; right: -4px; }

.spark {
  position: absolute;
  top: 42%;
  left: 50%;
  z-index: 3;
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  animation: spark .9s var(--ease-out) forwards;
}

.ring-stage {
  position: relative;
  width: min(230px, 58vw);
  margin: 0 auto;
}

.ring {
  display: block;
  width: 100%;
  height: auto;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 10;
}

.ring-fill {
  fill: none;
  stroke: var(--progress);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 552.92;
  stroke-dashoffset: 552.92;
  transition: stroke-dashoffset .3s var(--ease-out), stroke .3s ease;
}

.ring.reached .ring-fill { stroke: var(--brand); }

.ring-numbers {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  font-weight: 800;
  line-height: 1;
}

.ring-total,
.ring-goal {
  max-width: 6ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ring-total {
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: -.02em;
}

.ring-sep,
.ring-goal {
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
}

.over-goal {
  margin: .6rem 0 0;
  font-size: .85rem;
  font-weight: 600;
  color: var(--brand);
}

/* ----------------------------------------------------------- segmented */
.segmented {
  display: inline-flex;
  gap: 2px;
  margin-top: 1.25rem;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.segment {
  min-height: 40px;
  padding: 0 1.1rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s var(--ease-out), background .2s ease, color .2s ease;
}

.segment[aria-pressed="true"] {
  background: var(--brand-soft);
  color: var(--brand);
}

.segment[aria-pressed="true"]::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: .45rem;
  border-radius: 50%;
  background: currentColor;
  vertical-align: .1em;
  animation: live-pulse 2.4s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* --------------------------------------------------------------- entry */
.entry { margin-bottom: 2rem; }

.stepper-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: .5rem;
  align-items: stretch;
}

.step-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s var(--ease-out), border-color .2s ease;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: .75rem 0 1rem;
}

.chip {
  min-width: 3.25rem;
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: 3px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s var(--ease-out), background .2s ease, color .2s ease;
}

input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

input[type="text"]::placeholder { color: var(--muted); opacity: 1; }

#count-input {
  min-width: 0;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 1rem 0 .4rem;
  font-family: var(--font-mono);
  font-size: .66rem;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}

.optional {
  font-family: var(--font-sans);
  font-size: .78rem;
  letter-spacing: 0;
  text-transform: none;
}

/* -------------------------------------------------------------- buttons */
.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .55rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: transform .15s var(--ease-out), background .2s ease, border-color .2s ease, color .2s ease;
}

.btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -70%;
  width: 45%;
  height: 100%;
  transform: skewX(-20deg);
  background: linear-gradient(105deg, transparent, color-mix(in srgb, var(--bg) 40%, transparent), transparent);
  pointer-events: none;
}

.btn:not(.btn-primary):not(.btn-danger)::after {
  background: linear-gradient(105deg, transparent, color-mix(in srgb, var(--brand) 18%, transparent), transparent);
}

.btn-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--bg);
}

.btn-danger {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.btn-small {
  min-height: 44px;
  padding: .4rem .9rem;
  font-size: .85rem;
}

.btn-block { width: 100%; margin-top: .5rem; }

.text-btn {
  min-height: 44px;
  padding: .5rem .65rem;
  border: 0;
  border-radius: 3px;
  background: none;
  color: var(--brand);
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
}

.text-danger { color: var(--accent); }

/* ---------------------------------------------------------------- sets */
.sets-list { border-top: 1px solid var(--line); }

.set-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}

.set-row.stagger,
.day-row.stagger {
  animation: row-in .25s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 25ms);
}

.set-main { min-width: 0; }

.set-count {
  font-size: 1.05rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.set-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem .55rem;
}

.set-time {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--muted);
}

.set-note {
  margin-top: .15rem;
  font-size: .9rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.set-actions {
  display: flex;
  flex-shrink: 0;
  gap: .15rem;
}

/* ------------------------------------------------------------- history */
.history-block { margin-bottom: 2rem; }

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .4rem;
}

.block-head .label { margin: 0; }

.week-nav {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.week-label {
  min-width: 9rem;
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--muted);
  text-align: center;
}

.chart-wrap { margin-top: .5rem; }
.chart-wrap svg { display: block; width: 100%; height: auto; }

.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-goal { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 2 5; }
.chart-bar {
  fill: var(--progress);
  transform-box: fill-box;
  transform-origin: bottom;
  animation: bar-grow .55s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.chart-bar.reached { fill: var(--brand); }

.chart-goal { animation: fade-in .6s ease .2s backwards; }

.chart-value,
.chart-day { animation: fade-in .5s ease .15s backwards; }

.chart-value {
  fill: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.chart-day {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.bar-group { cursor: default; }

.bar-group:focus-visible .chart-bar {
  stroke: var(--accent);
  stroke-width: 2;
}

.bar-group:focus-visible .chart-value { fill: var(--brand); }

.heatmap-months {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 460px;
  margin: 0 auto .35rem;
  min-height: 1.1em;
  font-family: var(--font-mono);
  font-size: .6rem;
  color: var(--muted);
}

.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
}

.heat-cell {
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  background: var(--surface-2);
  cursor: pointer;
  transition: transform .15s var(--ease-out), outline-color .15s ease;
  animation: cell-in .25s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 4ms);
}

.heat-cell:disabled {
  cursor: default;
  opacity: .45;
  background: var(--surface-2);
}

.heat-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.heat-cell.level-1,
.legend-cell.level-1 { background: color-mix(in srgb, var(--progress) 25%, var(--surface-2)); }

.heat-cell.level-2,
.legend-cell.level-2 { background: color-mix(in srgb, var(--progress) 55%, var(--surface-2)); }

.heat-cell.level-3,
.legend-cell.level-3 { background: color-mix(in srgb, var(--progress) 80%, var(--surface-2)); }

.heat-cell.level-4,
.legend-cell.level-4 { background: var(--brand); }

.legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  margin-top: .6rem;
}

.legend-text {
  font-family: var(--font-mono);
  font-size: .6rem;
  color: var(--muted);
}

.legend-text:first-child { margin-right: .2rem; }
.legend-text:last-child { margin-left: .2rem; }

.legend-cell {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: var(--surface-2);
}

.past-list { border-top: 1px solid var(--line); }

.day-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: .75rem;
  width: 100%;
  min-height: 48px;
  padding: .5rem .25rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 3px;
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.day-row::before {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--brand), var(--accent));
  transform: scaleY(0);
  transform-origin: top;
  transition: transform .25s var(--ease-out);
}

.day-date {
  font-family: var(--font-mono);
  font-size: .78rem;
}

.day-nums { font-size: .9rem; font-weight: 600; overflow-wrap: anywhere; }
.day-check { color: var(--brand); font-weight: 700; }

/* --------------------------------------------------------------- stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform .2s var(--ease-out), border-color .2s ease;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .35s var(--ease-out);
}

.view-in .stat-card {
  animation: card-in .35s var(--ease-out) backwards;
}

.view-in .stat-card:nth-child(2) { animation-delay: .05s; }
.view-in .stat-card:nth-child(3) { animation-delay: .1s; }
.view-in .stat-card:nth-child(4) { animation-delay: .15s; }
.view-in .stat-card:nth-child(5) { animation-delay: .2s; }
.view-in .stat-card:nth-child(6) { animation-delay: .25s; }

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}

.stat-label {
  margin-top: .4rem;
  font-family: var(--font-mono);
  font-size: .6rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-meta {
  min-height: 1em;
  margin-top: .2rem;
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--muted);
}

/* -------------------------------------------------------------- footer */
.app-footer { padding: .5rem 1.25rem 1.5rem; text-align: center; }

.byline {
  font-family: var(--font-mono);
  font-size: .62rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}

.byline::before,
.byline::after {
  content: '◆';
  margin: 0 .7em;
  font-size: .7em;
  vertical-align: .15em;
  color: var(--accent);
  transition: transform .5s var(--ease-bounce), color .2s ease;
}

/* ------------------------------------------------------------- dialogs */
dialog {
  width: 100%;
  max-width: min(92vw, 480px);
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(10, 12, 11, .5); }

dialog[open] { animation: dialog-in .24s var(--ease-bounce); }
dialog::backdrop { animation: backdrop-in .2s ease; }

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: none; }
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

dialog h2 {
  margin: 0 0 .5rem;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -.01em;
}

dialog h3 { margin-bottom: .4rem; }

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-head h2 { margin-bottom: .5rem; }

.dialog-lede {
  margin: .2rem 0 1rem;
  color: var(--muted);
  font-size: .9rem;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.25rem;
}

.settings-section {
  margin: 0;
  padding: 1rem 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  margin-top: 1rem;
}

.settings-section:first-of-type {
  margin-top: .5rem;
  padding-top: 0;
  border-top: 0;
}

.inline-form {
  display: flex;
  gap: .5rem;
}

.inline-form input { flex: 1; min-width: 0; }

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .5rem;
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 44px;
  cursor: pointer;
}

.radio input { accent-color: var(--brand); }

#detail-sets { border-top: 1px solid var(--line); }

.detail-log {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

/* -------------------------------------------------- view transitions */
.view-in { animation: view-in .3s var(--ease-out); }

.reveal { opacity: 0; }
.reveal.in { opacity: 1; animation: rise-in .55s var(--ease-out) backwards; }

.btn:active,
.chip:active,
.step-btn:active,
.icon-btn:active,
.segment:active { transform: scale(.95); }

.text-btn:active { transform: scale(.97); }

/* -------------------------------------------------- hover / pointer fine */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { border-color: var(--brand); color: var(--brand); }
  #settings-btn:hover { transform: rotate(20deg) scale(1.06); }
  .segment:hover { color: var(--brand); }
  .chip:hover { background: var(--brand); color: var(--bg); }
  .text-btn:hover { background: var(--brand-soft); }
  .day-row:hover { background: var(--brand-soft); }
  .day-row:hover::before { transform: scaleY(1); }
  .stat-card:hover { transform: translateY(-4px); border-color: var(--brand); }
  .stat-card:hover::before { transform: scaleX(1); }
  .ring-card:hover { outline-offset: 9px; }
  .ring-card:hover .corner { transform: rotate(225deg) scale(1.3); background: var(--brand); }
  .wordmark .letters span:hover { transform: translateY(-4px) rotate(-4deg); }
  .wordmark:hover .letters span:nth-child(3n+1) { color: var(--brand); }
  .wordmark:hover .letters span:nth-child(3n+2) { color: var(--accent); }
  .wordmark:hover .letters span:nth-child(3n) { color: var(--muted); }
  .byline:hover::before { transform: rotate(180deg); }
  .byline:hover::after { transform: rotate(-180deg); }
  .bar-group:hover .chart-value { fill: var(--brand); }
  .bar-group:hover .chart-bar { filter: brightness(1.08); }
  .heat-cell:not(:disabled):hover { transform: scale(1.18); outline: 2px solid var(--brand); outline-offset: 1px; }
  .btn-primary:hover { border-color: var(--accent); background: var(--accent); }
  .btn:not(.btn-primary):not(.btn-danger):hover { border-color: var(--brand); color: var(--brand); }
  .btn-danger:hover { filter: brightness(1.06); }
  .btn:hover::after { left: 125%; transition: left .45s ease; }
}

/* ----------------------------------------------------------- responsive */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .app-main { padding: 1.75rem 1.5rem 3rem; }

  .tabs {
    position: relative;
    z-index: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 0;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 48px;
    padding: 0 1rem;
    background: transparent;
  }

  .tab[aria-current="page"] {
    background: transparent;
  }

  .tab::after { inset: auto 0 0 0; }

  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .bg-decor span:nth-child(n+5) { display: none; }
}

@media (max-width: 400px) {
  .bg-decor span { display: none; }
}

@media (max-width: 420px) {
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; }
}

/* ------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }

  .bg-decor span { animation: none !important; translate: none !important; }
  .reveal { opacity: 1 !important; }
}
