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

:root {
  --bg:           #080808;
  --bg2:          #0f0f0f;
  --bg3:          #161616;
  --past:         #5c0000;
  --past-hi:      #7a0000;
  --future:       #181818;
  --future-b:     #262626;
  --text:         #b0a498;
  --text-dim:     #6b5f58;
  --text-bright:  #ddd0c4;
  --accent:       #7a0000;
  --accent-hi:    #a01010;
  --border:       #1e1e1e;
  --ff-serif:     'IM Fell English', Georgia, 'Times New Roman', serif;
  --ff-mono:      'Space Mono', 'Courier New', monospace;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff-serif);
  font-size: 17px;
  line-height: 1.7;
  min-height: 100vh;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--accent); }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

#landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem;
  text-align: center;
  position: relative;
}

#landing::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, #1a000088 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 50% 100%, #0d000066 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

#landing > * { position: relative; z-index: 1; }

.skull {
  font-size: 3rem;
  opacity: 0.15;
  margin-bottom: 1rem;
  letter-spacing: 0.2em;
  animation: breathe 6s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.10; }
  50%       { opacity: 0.20; }
}

h1 {
  font-family: var(--ff-serif);
  font-style: italic;
  font-size: clamp(2.5rem, 7vw, 5rem);
  font-weight: 400;
  color: var(--text-bright);
  letter-spacing: 0.04em;
  line-height: 1.1;
  margin-bottom: 0.4rem;
}

.latin {
  font-family: var(--ff-serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: lowercase;
  margin-bottom: 3.5rem;
}

#inputForm {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

label.field-label {
  font-size: 0.75rem;
  font-family: var(--ff-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.country-wrap { position: relative; }

#countryInput {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-bright);
  font-family: var(--ff-serif);
  font-size: 1rem;
  padding: 0.65rem 1rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
  cursor: pointer;
  caret-color: var(--accent-hi);
}
#countryInput:focus { border-color: var(--accent); }
#countryInput::placeholder { color: var(--text-dim); }
#countryInput:disabled { opacity: 0.4; cursor: not-allowed; }

#countryDropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-top: none;
  max-height: 220px;
  overflow-y: auto;
  z-index: 999;
}
#countryDropdown.open { display: block; }

.dd-option {
  padding: 0.55rem 1rem;
  font-family: var(--ff-serif);
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s, color 0.1s;
}
.dd-option:last-child { border-bottom: none; }
.dd-option:hover, .dd-option.highlighted {
  background: var(--accent);
  color: var(--text-bright);
}
.dd-empty {
  padding: 0.6rem 1rem;
  color: var(--text-dim);
  font-family: var(--ff-mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
}

.radio-group {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
}

.radio-group label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dim);
  border-right: 1px solid var(--border);
  transition: all 0.2s;
  background: var(--bg3);
  text-align: center;
}

.radio-group label:last-child { border-right: none; }
.radio-group input[type="radio"] { display: none; }

.radio-group input[type="radio"]:checked + span,
.radio-group label:has(input:checked) {
  background: var(--accent);
  color: var(--text-bright);
}

.radio-group label:hover { background: var(--bg2); color: var(--text); }
.radio-group label:has(input:checked):hover { background: var(--accent); }

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.toggle-wrap input[type="checkbox"] { display: none; }

.toggle-track {
  width: 32px;
  height: 18px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 9px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-wrap input:checked ~ .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-wrap input:checked ~ .toggle-track .toggle-thumb { transform: translateX(14px); background: var(--text-bright); }

.toggle-text {
  font-family: var(--ff-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

input[type="number"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-bright);
  font-family: var(--ff-mono);
  font-size: 1rem;
  padding: 0.65rem 1rem;
  width: 100%;
  -moz-appearance: textfield;
  outline: none;
  transition: border-color 0.2s;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="number"]:focus { border-color: var(--accent); }

.year-disclaimer {
  font-family: var(--ff-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  line-height: 1.6;
  margin-top: 0.5rem;
  font-style: italic;
}
input[type="date"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-bright);
  font-family: var(--ff-mono);
  font-size: 1rem;
  padding: 0.65rem 1rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
  color-scheme: dark;
  appearance: none;
  -webkit-appearance: none;
}
input[type="date"]:focus { border-color: var(--accent); }
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.4);
  cursor: pointer;
  opacity: 0.5;
}
input[type="date"]::-webkit-datetime-edit-text { color: var(--text-dim); }
input[type="date"]::-webkit-datetime-edit-year-field,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field { color: var(--text-bright); }
input[type="date"]::-webkit-datetime-edit-year-field:focus,
input[type="date"]::-webkit-datetime-edit-month-field:focus,
input[type="date"]::-webkit-datetime-edit-day-field:focus {
  background: var(--accent);
  color: var(--text-bright);
  outline: none;
}

#calculateBtn {
  margin-top: 0.5rem;
  padding: 0.9rem 2rem;
  background: var(--accent);
  color: var(--text-bright);
  border: none;
  border-radius: 0;
  font-family: var(--ff-mono);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s;
}
#calculateBtn:hover { background: var(--accent-hi); }
#calculateBtn:disabled { opacity: 0.4; cursor: not-allowed; }

#loadingMsg {
  text-align: center;
  font-family: var(--ff-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.12em;
}

.loading-dot {
  display: inline-block;
  animation: blink 1.2s infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100%{opacity:0.2} 40%{opacity:1} }

#errorMsg {
  color: #c0392b;
  font-family: var(--ff-mono);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.5rem;
  border: 1px solid #c0392b33;
  display: none;
}

#results {
  display: none;
  padding: 3rem 0 6rem;
}

#results .container { max-width: 960px; }

.pct-banner {
  text-align: center;
  padding: 3rem 1.5rem 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.pct-number {
  font-family: var(--ff-mono);
  font-size: clamp(3rem, 12vw, 7rem);
  font-weight: 700;
  color: var(--accent-hi);
  line-height: 1;
  letter-spacing: -0.02em;
}

.pct-label {
  font-family: var(--ff-mono);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 0.4rem;
}

.pct-context {
  font-style: italic;
  font-size: 1rem;
  color: var(--text-dim);
  margin-top: 1.2rem;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--ff-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 0.9rem 1.4rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text-bright); border-bottom-color: var(--accent-hi); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.grid-meta {
  font-family: var(--ff-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 1.2rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.grid-meta span { display: flex; align-items: center; gap: 0.4rem; }

.legend-dot {
  width: 9px; height: 9px;
  display: inline-block;
}
.legend-dot.past { background: var(--past-hi); }
.legend-dot.future { background: var(--future); border: 1px solid var(--future-b); }

.week-grid {
  display: grid;
  grid-template-columns: repeat(52, 1fr);
  gap: 2px;
  width: 100%;
}

.week-cell {
  aspect-ratio: 1;
  min-width: 0;
}

.week-cell.past {
  background: var(--past);
  transition: background 0.1s;
}
.week-cell.past:hover { background: var(--past-hi); }

.week-cell.future {
  background: var(--future);
  border: 1px solid var(--future-b);
}

.grid-with-labels {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: 0.5rem;
  align-items: start;
}

.year-axis {
  display: flex;
  flex-direction: column;
}

.year-label {
  font-family: var(--ff-mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  line-height: 1;
  display: flex;
  align-items: center;
  opacity: 0;
}

.year-label.visible { opacity: 1; }

.year-grid {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 2px;
  max-width: 100%;
}

.year-cell {
  aspect-ratio: 1;
  position: relative;
  cursor: default;
}

.year-cell.past { background: var(--past); }
.year-cell.past:hover { background: var(--past-hi); }
.year-cell.future { background: var(--future); border: 1px solid var(--future-b); }
.year-cell.partial {
  background: linear-gradient(to right, var(--past) var(--fill), var(--future) var(--fill));
  border: 1px solid var(--future-b);
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  width: 100%;
  min-width: 0;
}

.month-cell {
  aspect-ratio: 1;
  min-width: 0;
}

.month-cell.past { background: var(--past); }
.month-cell.past:hover { background: var(--past-hi); }
.month-cell.future { background: var(--future); border: 1px solid var(--future-b); }
.month-cell.partial {
  background: linear-gradient(to right, var(--past) var(--fill), var(--future) var(--fill));
}

.stat-panel {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.stat-hero {
  text-align: center;
  padding: 2rem 0;
}

.stat-number {
  font-family: var(--ff-mono);
  font-size: clamp(2.5rem, 8vw, 5rem);
  font-weight: 700;
  color: var(--text-bright);
  line-height: 1;
}

.stat-unit {
  font-family: var(--ff-mono);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 0.4rem;
}

.stat-sub {
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.6rem;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--border);
}

.stat-card {
  background: var(--bg2);
  padding: 1.4rem 1.2rem;
}

.stat-card-label {
  font-family: var(--ff-mono);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.stat-card-value {
  font-family: var(--ff-mono);
  font-size: 1.3rem;
  color: var(--text-bright);
}

.stat-card-value.gone { color: var(--accent-hi); }

#results-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.source-line {
  font-family: var(--ff-mono);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  line-height: 1.8;
}

.source-line a { color: var(--accent-hi); text-decoration: none; }
.source-line a:hover { text-decoration: underline; }

.section-heading {
  font-family: var(--ff-mono);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

#backBtn {
  display: inline-block;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--ff-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  cursor: pointer;
  margin-bottom: 2rem;
  transition: all 0.2s;
}
#backBtn:hover { border-color: var(--text-dim); color: var(--text); }

#site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  text-align: center;
}

.footer-text {
  font-family: var(--ff-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  line-height: 2;
}

.footer-text a { color: var(--text-dim); text-decoration: underline; }
.footer-text a:hover { color: var(--text); }

@media (max-width: 600px) {
  h1 { margin-bottom: 0.3rem; }
  .latin { margin-bottom: 2.5rem; }
  .week-grid { gap: 1px; }
  .year-grid { grid-template-columns: repeat(10, 1fr); gap: 1px; }
  .month-grid { grid-template-columns: repeat(12, 1fr); gap: 1px; }
  .grid-with-labels { grid-template-columns: 3rem 1fr; }
  .pct-number { font-size: clamp(2.5rem, 15vw, 4rem); }
  .tab-btn { padding: 0.8rem 0.9rem; font-size: 0.65rem; }
  .stat-number { font-size: clamp(2rem, 12vw, 3.5rem); }
}
