:root {
  color-scheme: light;
  --ink: #493b4d;
  --ink-soft: #746577;
  --cream: #fff8ee;
  --paper: #fffdf9;
  --pink: #e278a3;
  --pink-soft: #f9dbe6;
  --green: #8ab66b;
  --green-soft: #e2f0d6;
  --purple-soft: #eee6f2;
  --line: rgba(73, 59, 77, .12);
  --shadow: 0 22px 60px rgba(91, 66, 84, .11);
  --radius: 28px;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-synthesis: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  min-height: 100%;
  scroll-behavior: smooth;
  background: var(--cream);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 5% 8%, rgba(249, 219, 230, .7), transparent 24rem),
    radial-gradient(circle at 93% 26%, rgba(226, 240, 214, .72), transparent 25rem),
    var(--cream);
}

button,
input,
select { font: inherit; }

button,
select { cursor: pointer; }

button { color: inherit; }

img { display: block; }

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 24px 50px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 7px 9px rgba(92, 61, 82, .12));
}

.brand span { display: grid; gap: 2px; }

.brand strong {
  font-size: clamp(1rem, 3vw, 1.25rem);
  letter-spacing: -.045em;
}

.brand em {
  color: var(--pink);
  font-style: normal;
}

.brand small,
footer {
  color: var(--ink-soft);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.tab-bar {
  position: sticky;
  top: 12px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(100%, 470px);
  margin: 0 auto 26px;
  padding: 6px;
  border: 1px solid rgba(73, 59, 77, .09);
  border-radius: 18px;
  background: rgba(255, 253, 249, .88);
  box-shadow: 0 12px 30px rgba(91, 66, 84, .09);
  backdrop-filter: blur(16px);
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 13px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--ink-soft);
  font-size: .88rem;
  font-weight: 800;
}

.tab span {
  font-size: 1.12rem;
  line-height: 1;
}

.tab.is-active {
  background: var(--pink-soft);
  color: #854463;
}

.view { animation: rise .26s ease-out; }

.today-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 22px;
  overflow: hidden;
  padding: 30px;
  border: 1px solid rgba(73, 59, 77, .1);
  border-radius: 34px;
  background:
    linear-gradient(125deg, rgba(255,255,255,.92), rgba(255,248,238,.78)),
    var(--paper);
  box-shadow: var(--shadow);
}

.today-card::after {
  position: absolute;
  right: -45px;
  bottom: -80px;
  width: 230px;
  height: 230px;
  border-radius: 50%;
  background: var(--green-soft);
  content: "";
  opacity: .72;
}

.tiny-snail {
  position: relative;
  z-index: 1;
  width: 118px;
  align-self: end;
  filter: drop-shadow(0 12px 10px rgba(73, 59, 77, .12));
}

.eyebrow {
  margin: 0 0 6px;
  color: #a2587a;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .15em;
  text-transform: uppercase;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 7vw, 3.5rem);
  line-height: 1;
  letter-spacing: -.065em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  letter-spacing: -.045em;
}

.today-stats,
.progress-stats {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 4px 0 0;
}

.today-stats div,
.progress-stats div {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 255, 255, .68);
}

dt {
  color: var(--ink-soft);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

dd {
  overflow: hidden;
  margin: 3px 0 0;
  font-size: 1.35rem;
  font-weight: 850;
  letter-spacing: -.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

dd small {
  color: var(--ink-soft);
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: 0;
}

.panel {
  margin-top: 20px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 249, .93);
  box-shadow: 0 14px 44px rgba(91, 66, 84, .07);
}

.panel-heading,
.history-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.field-row,
.metric-fields,
.progress-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.metric-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0;
}

.field {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.field > span {
  color: var(--ink-soft);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .045em;
}

.field > span small {
  font-size: .72rem;
  font-weight: 650;
}

.field-wide { grid-column: span 1; }

input,
select {
  width: 100%;
  min-height: 49px;
  padding: 0 14px;
  border: 1.5px solid rgba(73, 59, 77, .16);
  border-radius: 14px;
  outline: none;
  background: #fff;
  color: var(--ink);
  transition: border-color .16s ease, box-shadow .16s ease;
}

input::placeholder { color: #b0a5b2; }

input:focus,
select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(226, 120, 163, .14);
}

.input-unit {
  position: relative;
  display: block;
}

.input-unit input { padding-right: 48px; }

.input-unit small {
  position: absolute;
  top: 50%;
  right: 14px;
  color: var(--ink-soft);
  font-size: .75rem;
  font-weight: 800;
  transform: translateY(-50%);
}

.primary-button,
.secondary-button,
.icon-button,
.text-button {
  border: 0;
  font-weight: 850;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 54px;
  margin-top: 18px;
  padding: 12px 20px;
  border-radius: 16px;
  background: var(--pink);
  box-shadow: 0 11px 23px rgba(197, 86, 132, .23);
  color: #fff;
  transition: transform .14s ease, box-shadow .14s ease;
}

.primary-button:hover {
  box-shadow: 0 14px 28px rgba(197, 86, 132, .3);
  transform: translateY(-1px);
}

.primary-button:active { transform: translateY(1px); }

.primary-button img {
  width: 31px;
  height: 31px;
  padding: 3px;
  border-radius: 50%;
  background: rgba(255,255,255,.7);
}

.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: 9px 16px;
  border: 1px solid rgba(73, 59, 77, .13);
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 6px 15px rgba(91, 66, 84, .06);
}

.text-button {
  padding: 5px;
  background: transparent;
  color: #a2587a;
  font-size: .8rem;
}

.set-list,
.history-list { display: grid; gap: 10px; }

.set-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  padding: 13px;
  border: 1px solid rgba(73, 59, 77, .1);
  border-radius: 16px;
  background: #fff;
}

.set-shell {
  display: grid;
  width: 41px;
  height: 41px;
  place-items: center;
  border-radius: 50%;
  background: var(--pink-soft);
  color: #a45176;
  font-size: 1.35rem;
  font-weight: 900;
}

.set-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.set-copy strong,
.set-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.set-copy strong { font-size: .94rem; }

.set-copy span {
  color: #a45176;
  font-size: .82rem;
  font-weight: 800;
}

.set-copy small {
  color: var(--ink-soft);
  font-size: .73rem;
}

.set-actions { display: flex; gap: 3px; }

.mini-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: .76rem;
  font-weight: 850;
}

.mini-button:hover {
  background: var(--purple-soft);
  color: var(--ink);
}

.section-heading {
  padding: 14px 4px 8px;
}

.progress-panel { padding-bottom: 20px; }

.progress-controls { margin-bottom: 18px; }

.progress-stats {
  margin: 0 0 18px;
}

.progress-stats div { background: #fff; }

.chart-wrap {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(rgba(255,255,255,.75), rgba(255,255,255,.75)),
    repeating-linear-gradient(0deg, transparent 0 49px, rgba(73,59,77,.05) 50px);
}

#progressChart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 290px;
}

.chart-grid {
  stroke: rgba(73, 59, 77, .1);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--pink);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.chart-area { fill: url(#chartGradient); }

.chart-point {
  fill: #fff;
  stroke: var(--pink);
  stroke-width: 4;
}

.chart-label {
  fill: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 5px;
  text-align: center;
}

.empty-state img {
  width: 84px;
  margin-bottom: 5px;
  opacity: .9;
}

.empty-state span {
  color: var(--ink-soft);
  font-size: .82rem;
}

.nudge-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  padding: 18px 20px;
  border-radius: 19px;
  background: var(--green-soft);
}

.nudge-card p {
  margin: 3px 0 0;
  color: #5e7450;
  font-size: .84rem;
}

.shell-icon {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: var(--green);
  font-size: 1.55rem;
  font-weight: 900;
}

.history-toolbar {
  align-items: end;
  margin-bottom: 16px;
}

.history-toolbar .field { width: min(100%, 330px); }

.record-count {
  padding-bottom: 13px;
  color: var(--ink-soft);
  font-size: .78rem;
  font-weight: 800;
}

.history-day {
  margin: 15px 2px 5px;
  color: var(--ink-soft);
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.backup-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--purple-soft);
}

.backup-panel p:last-child {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: .84rem;
}

.backup-actions { display: flex; gap: 8px; }

.file-button { position: relative; }

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.blank-card {
  display: grid;
  justify-items: center;
  padding: 24px 15px;
  color: var(--ink-soft);
  text-align: center;
}

.blank-card img {
  width: 72px;
  margin-bottom: 8px;
  opacity: .75;
}

.blank-card strong { color: var(--ink); }

.blank-card span {
  margin-top: 3px;
  font-size: .8rem;
}

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 30px 0 0;
}

footer img { width: 28px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 40px));
  padding: 13px 17px;
  border-radius: 14px;
  background: var(--ink);
  box-shadow: var(--shadow);
  color: #fff;
  font-size: .84rem;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

button:focus-visible,
a:focus-visible,
.file-button:focus-within {
  outline: 3px solid rgba(226, 120, 163, .5);
  outline-offset: 3px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
}

@media (max-width: 650px) {
  .app-shell {
    padding: 14px 14px calc(100px + env(safe-area-inset-bottom));
  }

  .app-header { padding: 3px 2px 15px; }

  .brand img {
    width: 46px;
    height: 46px;
  }

  .brand small { font-size: .61rem; }

  .tab-bar {
    position: fixed;
    top: auto;
    right: 14px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 14px;
    z-index: 20;
    width: auto;
    margin: 0;
  }

  .today-card { padding: 24px 20px; }

  .tiny-snail { width: 86px; }

  .today-stats,
  .progress-stats { grid-template-columns: repeat(2, 1fr); }

  .panel {
    margin-top: 14px;
    padding: 20px 16px;
    border-radius: 23px;
  }

  .field-row,
  .metric-fields,
  .progress-controls { grid-template-columns: 1fr; }

  .set-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .set-actions {
    grid-column: 2;
    justify-content: flex-end;
  }

  .chart-wrap { min-height: 260px; }

  #progressChart { min-height: 250px; }

  .backup-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .backup-actions > * { flex: 1; }

  .toast {
    right: 14px;
    bottom: calc(90px + env(safe-area-inset-bottom));
  }

  footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
