:root {
  --bg: #faf8f7;
  --card: #ffffff;
  --ink: #262020;
  --muted: #928683;
  --faint: #b9afac;
  --accent: #a8456d;
  --accent-soft: #f4dde7;
  --border: #ece5e2;
  --menstrual: #a8456d;
  --follicular: #b8863c;
  --ovulation: #3e8f6e;
  --luteal: #6a68b8;
  --radius: 14px;
  --danger: #a8453d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171313;
    --card: #1d1818;
    --ink: #f0e9e7;
    --muted: #948885;
    --faint: #635a58;
    --accent: #e78bab;
    --accent-soft: #3a2530;
    --border: #322928;
    --menstrual: #e78bab;
    --follicular: #d9a561;
    --ovulation: #67c199;
    --luteal: #a4a2e8;
    --danger: #e08078;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  justify-content: center;
  padding: 48px 16px;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}

.app-header h1 {
  font-size: 1.35rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card-header h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.status-pill {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status-pill.connected {
  color: var(--ovulation);
  border-color: var(--ovulation);
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.55;
}

.setup-steps {
  margin: 0;
  padding-left: 16px;
  font-size: 0.78rem;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setup-steps a {
  color: var(--accent);
  font-weight: 600;
}

.setup-steps code {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.73rem;
  word-break: break-all;
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form input {
  flex: 1;
  min-width: 140px;
  border: 1.5px solid var(--accent-soft);
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.88rem;
  font-family: inherit;
}

.inline-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: opacity 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:active { opacity: 0.75; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 0.86rem;
}

.btn.small {
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 0.8rem;
}

.btn.tiny {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.68rem;
}

.btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent-soft);
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 0.8rem;
}

.btn.ghost:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.error-text {
  font-size: 0.78rem;
  color: var(--danger);
  margin: 0;
}

.settings-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.settings-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.settings-row input {
  border: none;
  border-bottom: 2px solid var(--accent-soft);
  background: transparent;
  color: var(--ink);
  padding: 4px 2px;
  font-size: 0.85rem;
  width: 80px;
  font-family: inherit;
}

.settings-row input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.period-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 160px;
  overflow-y: auto;
}

.period-list:empty::after {
  content: "No periods logged yet.";
  font-size: 0.78rem;
  color: var(--muted);
}

.period-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.83rem;
}

.period-item .period-date {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
}

.period-item .remove-btn {
  background: none;
  border: none;
  color: var(--danger);
  opacity: 0.65;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 2px 4px;
}

.period-item .remove-btn:hover {
  opacity: 1;
}

.dashboard-card {
  align-items: center;
  text-align: center;
}

.ring-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 4px 0;
}

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

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 20px;
}

.phase-name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.cycle-day {
  font-size: 0.76rem;
  color: var(--muted);
}

.dashboard-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
}

.dashboard-stats .stat {
  padding: 10px 4px;
  text-align: left;
  border-top: 1px solid var(--border);
}

.dashboard-stats .stat-label {
  font-size: 0.66rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dashboard-stats .stat-value {
  font-size: 0.92rem;
  font-weight: 700;
  margin-top: 2px;
}

.thermal-note {
  font-size: 0.76rem;
  color: var(--ink);
  border-top: 1px solid var(--border);
  padding: 10px 2px 0;
  margin: 0;
  width: 100%;
  text-align: left;
  line-height: 1.5;
}

.phase-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.phase-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 2px;
  font-size: 0.79rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.phase-legend .legend-item.active {
  color: var(--ink);
  font-weight: 700;
}

.phase-legend .legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.phase-legend .legend-label {
  flex: 1;
  text-align: left;
}

.phase-legend .legend-range {
  color: var(--faint);
  font-size: 0.72rem;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 0.83rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.stat-grid .stat {
  padding: 10px 4px;
  border-top: 1px solid var(--border);
}

.stat-grid .stat-label {
  font-size: 0.66rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-grid .stat-value {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 2px;
}

.stat-grid .stat-sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

.recs-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rec-block {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.rec-block:first-child {
  border-top: none;
  padding-top: 0;
}

.rec-block h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rec-block ul {
  margin: 0;
  padding-left: 16px;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--ink);
}

.rec-block p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.6;
}

.disclaimer {
  font-size: 0.68rem;
  color: var(--faint);
  text-align: center;
  line-height: 1.5;
  padding: 0 8px;
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .ring-wrap { width: 180px; height: 180px; }
}
