/* ---------- Cyvella · Period Tracker ---------- */
/* Ported from prototype/styles.css (SPEC §3, FR-7, FR-8) plus the account
   sheet (SPEC §3.1.2). Tokens are normative: rose #e5567a, strong #d63d66,
   soft #fde0e9, light bg #fdf3f6, dark bg #1c141a, dark card #271c22. */

:root {
  --bg: #fdf3f6;
  --card: #ffffff;
  --text: #3f2e35;
  --muted: #96757f;
  --line: #f3dde4;

  --rose: #e5567a;
  --rose-strong: #d63d66;
  --rose-soft: #fde0e9;

  --radius: 18px;
  --shadow: 0 6px 24px rgba(214, 61, 102, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c141a;
    --card: #271c22;
    --text: #f6e9ee;
    --muted: #b3949f;
    --line: #3a2b33;
    --rose-soft: #4a2431;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* ---------- Header ---------- */

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.2px;
}

.brand-mark { font-size: 24px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---------- Generic ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0; /* UA default (1px 6px) inflates grid min-content width */
}

.btn-primary {
  width: 100%;
  background: var(--rose);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
  border-radius: 14px;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--rose-strong); }

.btn-ghost {
  color: var(--rose-strong);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 10px;
}
.btn-ghost:hover { background: var(--rose-soft); }

.btn-danger {
  width: 100%;
  margin-top: 8px;
  color: #fff;
  background: var(--rose-strong);
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  border-radius: 12px;
}
.btn-danger:hover { background: #b62f54; }

.small-btn { font-size: 12px; padding: 4px 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--rose-strong);
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--rose-soft); }

.text-input {
  width: 100%;
  margin-top: 8px;
  padding: 11px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.error-text {
  margin: 8px 0 0;
  color: var(--rose-strong);
  font-size: 13px;
}

/* ---------- Status card ---------- */

.status-card {
  display: flex;
  align-items: center;
  gap: 20px;
}

.ring {
  --p: 0;
  flex-shrink: 0;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: conic-gradient(var(--rose) calc(var(--p) * 1%), var(--line) 0);
  display: grid;
  place-items: center;
}

.ring-inner {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-day {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
}

.ring-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.status-info { min-width: 0; }

.status-info h2 {
  margin: 0 0 6px;
  font-size: 19px;
}

.status-info p {
  margin: 0 0 4px;
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- Calendar ---------- */

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

.cal-header h3 {
  margin: 0;
  font-size: 16px;
}

.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-weekdays {
  margin-bottom: 4px;
}

.cal-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 0;
}

.day {
  aspect-ratio: 1;
  min-width: 0; /* allow grid tracks to shrink on narrow screens */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  transition: background 0.12s ease;
}

.day:not(.pad):hover { background: var(--rose-soft); }

.day.pad { cursor: default; }

.day-num {
  width: min(32px, 100%); /* shrink instead of overflowing tiny cells */
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
}

/* today */
.day.today .day-num {
  box-shadow: 0 0 0 2px var(--text);
  font-weight: 700;
}

/* logged period */
.day.period .day-num {
  background: var(--rose);
  color: #fff;
  font-weight: 600;
}

/* predicted period */
.day.predicted .day-num {
  border: 2px dashed var(--rose);
  color: var(--rose-strong);
}

/* legend */
.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 14px 2px 0;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.sw-period { background: var(--rose); }
.sw-predicted { border: 2px dashed var(--rose); width: 10px; height: 10px; }

/* ---------- Stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  text-align: center;
  padding: 14px 8px;
  margin-bottom: 0;
  min-width: 0;
}

.stat-value {
  display: block;
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 3px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Empty state & footer ---------- */

.empty {
  text-align: center;
  padding: 8px 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.empty .btn-primary {
  max-width: 240px;
  margin-top: 12px;
}

footer {
  text-align: center;
  padding-top: 8px;
}

footer p { margin: 0 0 4px; }

/* ---------- Account sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(28, 20, 26, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--card);
  color: var(--text);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  padding: 18px 18px 28px;
  animation: sheet-in 0.18s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(12px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-header h2 { margin: 0; font-size: 19px; }

.sheet-section {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.sheet-section:first-child { border-top: none; }

.sheet-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.sheet-section p { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }

.sheet-section .btn-primary { margin-top: 4px; }
.sheet-section .btn-ghost { margin-top: 4px; }

.code-entry { margin-top: 10px; }

/* ---------- Larger screens ---------- */

@media (min-width: 720px) {
  .app { max-width: 560px; padding-top: 32px; }
  .status-card { gap: 28px; }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 22px; max-height: 85vh; }
}
