:root {
  color-scheme: dark;
  --bg: #f6efe5;
  --surface: rgba(31, 31, 34, 0.9);
  --surface-soft: rgba(255, 248, 241, 0.72);
  --surface-card: rgba(255, 249, 243, 0.88);
  --ink: #1f2421;
  --ink-soft: #5e645d;
  --ink-inverse: #fffaf5;
  --line: rgba(49, 41, 32, 0.12);
  --accent: #d15b39;
  --accent-soft: #f4c9bb;
  --accent-deep: #8a341d;
  --sage: #42685c;
  --sage-soft: #c9d7cf;
  --gold: #e0a944;
  --shadow: 0 24px 60px rgba(68, 45, 27, 0.14);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top right, rgba(209, 91, 57, 0.22), transparent 22%),
    radial-gradient(circle at left 80%, rgba(66, 104, 92, 0.22), transparent 24%),
    linear-gradient(180deg, #fbf4eb 0%, #efe3d3 100%);
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding:
    calc(18px + var(--safe-top))
    16px
    calc(100px + var(--safe-bottom));
}

.loading-screen {
  min-height: calc(100vh - 32px);
  display: grid;
  place-content: center;
  gap: 16px;
  text-align: center;
}

.loading-rune {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  background:
    conic-gradient(from 0deg, var(--accent), transparent 45%, var(--sage), transparent 80%, var(--accent));
  animation: spin 1.1s linear infinite;
}

.loading-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
}

.loading-copy {
  color: var(--ink-soft);
}

.shell-grid {
  display: grid;
  gap: 16px;
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 22px 20px 20px;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(145deg, rgba(255, 248, 241, 0.94), rgba(252, 235, 219, 0.88)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.72);
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -12% -30% auto;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(209, 91, 57, 0.25), transparent 68%);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.hero-title {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 0.92;
}

.hero-copy {
  max-width: 34ch;
  margin: 14px 0 0;
  color: var(--ink-soft);
  line-height: 1.45;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.82);
  color: var(--accent-deep);
  font-weight: 600;
}

.hero-stats,
.cards-grid,
.section-stack,
.list-stack,
.quick-actions,
.timer-actions,
.segment-row,
.status-row,
.stats-grid {
  display: grid;
  gap: 12px;
}

.hero-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.stat-chip {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.stat-chip-label {
  display: block;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.stat-chip-value {
  display: block;
  margin-top: 6px;
  font-size: 1.45rem;
  font-weight: 700;
}

.section-card,
.metric-card,
.entry-card,
.practice-card,
.cycle-card,
.habit-card,
.timer-card,
.settings-card,
.empty-card {
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  border: 1px solid rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.section-card,
.practice-card,
.cycle-card,
.habit-card,
.timer-card,
.settings-card,
.empty-card {
  padding: 18px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
}

.section-subtitle {
  margin: 4px 0 0;
  color: var(--ink-soft);
}

.action-button,
.ghost-button,
.soft-button,
.status-button,
.nav-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 11px 14px;
}

.action-button {
  color: var(--ink-inverse);
  background: linear-gradient(135deg, var(--accent), #d78055);
  box-shadow: 0 10px 24px rgba(209, 91, 57, 0.28);
}

.ghost-button {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(49, 41, 32, 0.12);
}

.soft-button {
  color: var(--sage);
  background: rgba(66, 104, 92, 0.1);
  border: 1px solid rgba(66, 104, 92, 0.18);
}

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

.status-button {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(49, 41, 32, 0.1);
}

.status-button.is-active {
  color: var(--ink-inverse);
  background: linear-gradient(135deg, var(--sage), #5c8c7b);
}

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

.metric-card {
  padding: 16px;
}

.metric-value {
  margin-top: 6px;
  font-size: 1.5rem;
  font-weight: 700;
}

.card-meta {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.practice-card,
.cycle-card,
.habit-card,
.timer-card {
  display: grid;
  gap: 12px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.card-title {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.25;
}

.card-copy {
  margin: 4px 0 0;
  color: var(--ink-soft);
  line-height: 1.45;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font-size: 0.86rem;
}

.progress {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(49, 41, 32, 0.08);
  overflow: hidden;
}

.progress > span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button-row > button {
  flex: 1 1 120px;
}

.list-stack {
  margin-top: 10px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(49, 41, 32, 0.08);
}

.list-item-copy {
  display: grid;
  gap: 3px;
}

.list-item-title {
  font-weight: 700;
}

.list-item-meta {
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.tabbar {
  position: fixed;
  z-index: 20;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 28px;
  background: rgba(31, 31, 34, 0.84);
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 48px rgba(17, 17, 19, 0.28);
}

.nav-button {
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 8px 6px;
  color: rgba(255, 250, 245, 0.72);
  background: transparent;
}

.nav-button strong {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
}

.nav-button.is-active {
  color: var(--ink-inverse);
  background: rgba(255, 255, 255, 0.14);
}

.dev-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(224, 169, 68, 0.16);
  color: #6d4913;
  border: 1px solid rgba(224, 169, 68, 0.28);
}

.sheet,
.toast {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(720px, calc(100vw - 20px));
  width: 100%;
}

.sheet::backdrop,
.toast::backdrop {
  background: rgba(27, 21, 15, 0.28);
  backdrop-filter: blur(10px);
}

.sheet-panel {
  padding: 18px;
  border-radius: 30px 30px 20px 20px;
  background: linear-gradient(180deg, #fffaf5, #f4e8d9);
  box-shadow: 0 24px 60px rgba(68, 45, 27, 0.26);
}

.sheet-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
}

.sheet-copy {
  margin: 6px 0 0;
  color: var(--ink-soft);
}

.form-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.helper-copy {
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.4;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-button {
  min-height: 46px;
  border-radius: 16px;
  border: 1px solid rgba(49, 41, 32, 0.12);
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
}

.mode-button.is-active {
  color: var(--ink-inverse);
  background: linear-gradient(135deg, var(--sage), #5c8c7b);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(49, 41, 32, 0.12);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.duration-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.picker-field {
  display: grid;
  gap: 6px;
}

.picker-field span {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.picker-field select {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.segments-builder {
  display: grid;
  gap: 10px;
}

.segments-list {
  display: grid;
  gap: 10px;
}

.segment-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(49, 41, 32, 0.1);
  background: rgba(255, 255, 255, 0.52);
}

.segment-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.segment-row-head strong {
  font-size: 0.95rem;
}

.segment-remove-button {
  min-height: 36px;
  padding: 8px 12px;
}

.quick-start-item {
  gap: 10px;
}

.quick-start-button {
  flex: 0 0 auto;
  min-width: 88px;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.weekday-chip {
  min-height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(49, 41, 32, 0.1);
}

.weekday-chip.is-selected {
  color: var(--ink-inverse);
  background: linear-gradient(135deg, var(--sage), #5c8c7b);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.sheet-actions button {
  flex: 1 1 auto;
}

.toast-panel {
  margin: auto auto 20px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(31, 31, 34, 0.92);
  color: var(--ink-inverse);
  text-align: center;
}

.mono {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

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

@media (min-width: 720px) {
  .app-shell {
    width: min(960px, calc(100vw - 32px));
    margin: 0 auto;
  }

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

@media (max-width: 420px) {
  .tabbar {
    gap: 4px;
    padding: 6px;
  }

  .nav-button {
    padding: 8px 2px;
  }

  .nav-button strong {
    font-size: 0.65rem;
  }

  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .section-header > button {
    width: 100%;
  }

  .duration-picker {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    grid-template-columns: 1fr;
  }

  .segment-row-head {
    align-items: stretch;
    flex-direction: column;
  }

  .segment-remove-button,
  .quick-start-button {
    width: 100%;
  }

  .quick-start-item {
    align-items: stretch;
    flex-direction: column;
  }
}
