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

:root {
  --bg: #1a1814;
  --bg-elevated: #242019;
  --bg-input: #2e2a24;
  --text: #e8e4dc;
  --text-muted: #9a948a;
  --text-dim: #6b655c;
  --accent: #c4a882;
  --accent-dim: #8a7355;
  --grid-bg: #2a2620;
  --lived: #000000;
  --future: #3d3830;
  --future-border: #4a443c;
  --current: #c4a882;
  --border: #333028;
  --border-subtle: #2e2a24;
  --border-input: #403a32;
  --scheme: dark;
  --vignette-top: rgba(196, 168, 130, 0.06);
  --vignette-bottom: rgba(0, 0, 0, 0.4);
  --cell-gap: 1px;
  --mid-gap: 0.3rem;
  --decade-gap: 0.45rem;
  --year-label-width: 1.75rem;
  --font-serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Roboto Mono', 'Consolas', monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  --bg: #f4efe4;
  --bg-elevated: #ece5d6;
  --bg-input: #fbf8f1;
  --text: #2b271f;
  --text-muted: #6b655c;
  --text-dim: #938c7f;
  --accent: #9a7b48;
  --accent-dim: #b6a079;
  --grid-bg: #e7dfcd;
  --lived: #2b271f;
  --future: #d2c8b3;
  --future-border: #c1b59c;
  --current: #9a7b48;
  --border: #d8cfbb;
  --border-subtle: #ddd5c3;
  --border-input: #cabfa6;
  --scheme: light;
  --vignette-top: rgba(154, 123, 72, 0.08);
  --vignette-bottom: rgba(120, 100, 60, 0.06);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.view-main {
  min-height: 100dvh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 0%, var(--vignette-top) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 100%, var(--vignette-bottom) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(1rem + var(--safe-top)) 1rem calc(1rem + var(--safe-bottom));
}

body.view-main .app {
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

/* Theme toggle */
.theme-toggle {
  position: absolute;
  top: calc(0.5rem + var(--safe-top));
  right: 0.75rem;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--accent);
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.theme-toggle:hover,
.theme-toggle:active {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.header__latin {
  font-family: var(--font-serif);
  font-size: 0.6875rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.375rem;
}

.header__title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.header__subtitle {
  font-size: 0.75rem;
  font-weight: 300;
  color: var(--text-muted);
}

.header__ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  color: var(--accent-dim);
  font-size: 0.5rem;
  letter-spacing: 0.2em;
}

.header__ornament::before,
.header__ornament::after {
  content: '';
  width: 2rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
}

/* Setup */
.setup {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 2px;
}

.setup__label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.setup__input {
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 2px;
  color: var(--text);
  width: 100%;
  color-scheme: var(--scheme);
}

.setup__input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.setup__btn {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.875rem 1.5rem;
  margin-top: 0.5rem;
  background: transparent;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.setup__btn:active {
  background: var(--accent);
  color: var(--bg);
}

/* Main layout */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Stats */
.stats {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.stat {
  flex: 1;
  text-align: center;
}

.stat__value {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.2;
}

.stat__label {
  display: block;
  font-size: 0.5625rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* Legend */
.legend {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.625rem;
  font-size: 0.625rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.legend__swatch {
  width: 8px;
  height: 8px;
  border-radius: 1px;
}

.legend__swatch--lived {
  background: var(--lived);
}

.legend__swatch--current {
  background: var(--current);
  box-shadow: 0 0 4px rgba(196, 168, 130, 0.5);
}

.legend__swatch--future {
  background: var(--future);
  border: 1px solid var(--future-border);
}

/* Grid */
.grid-container {
  flex: 1;
  min-height: 60dvh;
  background: var(--grid-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.375rem 0.25rem 0.375rem 0.125rem;
  overflow: hidden;
}

.grid {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
  height: 100%;
}

/* Week-number header above the grid. */
.grid-header {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
  margin-bottom: 0.2rem;
}

.grid-header__cells {
  align-items: end;
}

.week-num {
  min-width: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: clamp(0.375rem, 1vw, 0.5rem);
  line-height: 1;
  color: var(--text-dim);
  letter-spacing: -0.03em;
  overflow: visible;
  white-space: nowrap;
}

.grid-row {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  flex: 1;
  min-height: 0;
}

/* Extra breathing room after every decade. */
.grid-row--decade {
  margin-bottom: var(--decade-gap);
}

.year-label {
  flex-shrink: 0;
  width: var(--year-label-width);
  font-family: var(--font-mono);
  font-size: clamp(0.4375rem, 1.1vw, 0.5625rem);
  font-weight: 400;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.125rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

/* Bold, slightly larger label for every 5th year. */
.year-label--milestone {
  font-weight: 700;
  font-size: clamp(0.5rem, 1.3vw, 0.6875rem);
  color: var(--text-muted);
}

.grid-row__cells {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(26, 1fr) var(--mid-gap) repeat(26, 1fr);
  gap: var(--cell-gap);
}

/* Empty spacer cell separating the two halves of the year. */
.cells__gap {
  background: none;
}

.cell {
  min-width: 0;
  min-height: 0;
  border-radius: 0;
}

.cell--lived {
  background: var(--lived);
}

.cell--future {
  background: var(--future);
}

.cell--current {
  background: var(--current);
  box-shadow: 0 0 3px rgba(196, 168, 130, 0.7);
  position: relative;
  z-index: 1;
}

/* Quote */
.quote {
  text-align: center;
  padding: 0.75rem 0.25rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: 0.75rem;
  flex-shrink: 0;
}

.quote__text {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  font-style: italic;
  font-weight: 400;
  line-height: 1.45;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.quote__text::before {
  content: '\201C';
  color: var(--accent-dim);
}

.quote__text::after {
  content: '\201D';
  color: var(--accent-dim);
}

.quote__author {
  font-family: var(--font-sans);
  font-size: 0.625rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-dim);
}

/* Fixed quote pinned beneath the rotating one. */
.quote--pinned {
  border-top: none;
  margin-top: 0;
  padding-top: 0.25rem;
}

.quote--pinned .quote__text {
  color: var(--text);
}

/* Edit button */
.edit-btn {
  display: block;
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
}

.edit-btn:active {
  color: var(--text-muted);
}

/* Install hint */
.install-hint {
  display: none;
  text-align: center;
  font-size: 0.625rem;
  color: var(--text-dim);
  line-height: 1.5;
  padding: 0.5rem 0.25rem 0;
  flex-shrink: 0;
}

.setup .install-hint {
  display: block;
}

.setup .install-hint:first-of-type {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.setup .install-hint + .install-hint {
  padding-top: 0.375rem;
}

.install-hint strong {
  color: var(--text-muted);
  font-weight: 500;
}

@media (min-width: 400px) {
  .header__title {
    font-size: 1.75rem;
  }

  .stat__value {
    font-size: 1.375rem;
  }

  .quote__text {
    font-size: 1.0625rem;
  }
}

@media (min-width: 768px) {
  .app {
    max-width: 560px;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}
