:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --text: #1a2233;
  --text-muted: #5a6478;
  --border: #e2e7f0;
  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-soft: #eef0fe;
  --accent: #0ea5a4;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 16px;
  --error: #dc2626;
}

:root[data-theme="dark"] {
  --bg: #0e1117;
  --bg-elev: #171b24;
  --text: #e8ecf4;
  --text-muted: #9aa4b8;
  --border: #262c38;
  --brand: #818cf8;
  --brand-strong: #a5b4fc;
  --brand-soft: #1c2030;
  --accent: #2dd4bf;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117;
    --bg-elev: #171b24;
    --text: #e8ecf4;
    --text-muted: #9aa4b8;
    --border: #262c38;
    --brand: #818cf8;
    --brand-strong: #a5b4fc;
    --brand-soft: #1c2030;
    --accent: #2dd4bf;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over any element's own display rule
   (e.g. .results uses display:grid, which would otherwise show it on load). */
[hidden] { display: none !important; }

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

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

.wrap {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}
.brand-mark { font-size: 1.4rem; }
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { border-color: var(--brand); }

/* Headings */
h1 {
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  margin: 32px 0 12px;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.3rem;
  margin: 36px 0 12px;
  letter-spacing: -0.01em;
}
.intro {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 1.02rem;
}

/* Card */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.calculator { padding: 22px; }

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 560px) {
  .fields { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field input {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
/* Ensure native date icon is visible in dark mode */
:root[data-theme="dark"] .field input::-webkit-calendar-picker-indicator {
  filter: invert(1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .field input::-webkit-calendar-picker-indicator {
    filter: invert(1);
  }
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.btn {
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 0.98rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-strong); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { border-color: var(--brand); }

.error {
  margin: 14px 0 0;
  color: var(--error);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Results */
.results { margin-top: 24px; display: grid; gap: 16px; }

.result-hero {
  padding: 26px 22px;
  text-align: center;
  background: linear-gradient(135deg, var(--brand-soft), var(--bg-elev));
}
.result-label {
  margin: 0 0 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--brand);
}
.result-hero-value {
  margin: 0;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.result-sub {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
.stat { padding: 16px; }
.stat-label {
  margin: 0 0 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}
.stat-value {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.birthday-card {
  padding: 20px 22px;
  border-left: 4px solid var(--accent);
}
.birthday-value {
  margin: 4px 0 0;
  font-size: 1.25rem;
  font-weight: 700;
}

/* Content / FAQ */
.content { margin: 8px 0 40px; }
.content p { color: var(--text-muted); }
.faq { display: grid; gap: 10px; margin-top: 8px; }
.faq details {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 16px;
}
.faq summary {
  cursor: pointer;
  font-weight: 600;
  padding: 12px 0;
  list-style: none;
  color: var(--text);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  float: right;
  color: var(--brand);
  font-weight: 700;
}
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: 0 0 14px; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}
.site-footer a { color: var(--brand); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
