:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #191919;
  --line: #e5e7eb;
  --cell-line: #d5d9e3;
  --blue: #3f58e8;
  --red: #f10000;
  --moon-lit-color: #f4c542;
  --moon-lit-stroke-color: #b98600;
  --blue-soft: #dcedff;
  --holy: #fff4cc;
  --holy-line: #f1da8a;
  --feast: #e0f3ff;
  --feast-line: #b9e2ff;
  --blank: #e8e8ee;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  font-family:
    Inter,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  margin: 0 0 8px;
  font-size: 2.15rem;
  line-height: 1.1;
}

.subhead {
  color: #2c4aa8;
  font-style: italic;
  font-weight: 700;
  margin: 0 0 16px;
  max-width: 1100px;
}

button,
select,
input {
  font: inherit;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.btn,
.field {
  border: 1px solid #cfd7e7;
  background: #fff;
  border-radius: 12px;
  min-height: 44px;
}

.btn {
  padding: 0 14px;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn.nav {
  width: 44px;
  padding: 0;
  font-size: 1.4rem;
  color: var(--blue);
}

.action-btn {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
}

.field {
  padding: 0 12px;
}

select.field,
input.field {
  min-width: 140px;
}

.year-control {
  display: inline-flex;
  align-items: stretch;
}

input.year {
  width: 110px;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}

.era-field {
  min-width: 84px !important;
  width: 84px;
  padding-right: 28px;
}

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

.year-step {
  width: 34px;
  min-height: 22px;
  height: 22px;
  padding: 0;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  line-height: 1;
  color: var(--muted);
}

.year-step:first-child {
  border-top-left-radius: 0;
  border-top-right-radius: 12px;
  border-bottom: 0;
}

.year-step:last-child {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.83fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.calendar-card {
  overflow: hidden;
}

.calendar-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px 16px;
}

.calendar-head-main {
  min-width: 0;
}

.calendar-head-side {
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.calendar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.calendar-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
  line-height: 1.15;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.98rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.dot.holy {
  background: var(--holy);
  border-color: var(--holy-line);
}

.dot.feast {
  background: var(--feast);
  border-color: var(--feast-line);
}

.validation-note {
  align-self: flex-end;
  margin-left: auto;
  text-align: right;
  max-width: 420px;
  line-height: 1.35;
}

.grid-wrap {
  padding: 10px 12px 12px;
}

.weekdays,
.days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.weekdays {
  padding: 4px 4px 10px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.cell {
  min-height: 132px;
  border: 1px solid var(--cell-line);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px 10px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.cell.blank {
  background: var(--blank);
  border-color: transparent;
}

.cell.today {
  outline: 3px solid var(--red);
  outline-offset: -1px;
}

.cell.holy,
.cell.feast {
  background: #fff;
}

.cell .roman {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
}

.cell .heb {
  position: absolute;
  top: 8px;
  right: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.2;
  max-width: 100%;
  color: #0b3d91;
}

.badge.passover {
  background: #c6fed6;
  border: 1px solid #4fd575;
  color: #064e2b;
}

.badge.holy-day {
  background: var(--holy);
  border: 1px solid var(--holy-line);
}

.badge.feast {
  background: var(--feast);
  border: 1px solid var(--feast-line);
}

.moon-row {
  margin-top: auto;
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.moon-icon-shell {
  flex: 0 0 auto;
  width: 24px;
  min-width: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.moon-icon-image {
  width: var(--moon-size, 18px);
  height: var(--moon-size, 18px);
  display: block;
  object-fit: contain;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.16);
}

.moon-icon-fallback {
  font-size: var(--moon-size, 18px);
  line-height: 1;
  display: block;
}

.moon-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cell .moon-phase {
  margin-top: 0;
  width: 100%;
  color: #1200c2;
  font-size: 8pt;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.cell .moon-crosscheck {
  width: 100%;
  font-size: 7pt;
  line-height: 1.15;
  font-weight: 600;
  color: var(--muted);
  word-break: break-word;
}

.cell .moon-crosscheck.is-pending {
  color: #64748b;
}

.cell .moon-crosscheck.is-match {
  color: #1d6b2e;
}

.cell .moon-crosscheck.is-mismatch {
  color: #9a6700;
}

.cell .moon-crosscheck.is-unavailable {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 16px;
}

.side {
  padding: 18px 18px 16px;
}

.side h2 {
  margin: 0 0 12px;
  font-size: 1.35rem;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  align-items: start;
  font-size: 1.02rem;
}

.kv b {
  color: var(--muted);
}

.note {
  margin-top: 16px;
  color: var(--muted);
}

.events {
  margin-top: 16px;
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.event {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffdede;
}

.csv-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 10px;
}

.field-wrap label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
}

.field-wrap input {
  width: 100%;
}

.small {
  color: var(--muted);
  font-size: 0.95rem;
}

.footer-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.94rem;
}

.success {
  margin-top: 10px;
  color: #235d2d;
  font-weight: 700;
}

.error {
  margin-top: 10px;
  color: #a02a2a;
  font-weight: 700;
}

.is-exporting .calendar-actions,
.is-exporting .validation-note {
  visibility: hidden;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .wrap {
    padding: 14px;
  }

  .calendar-head {
    grid-template-columns: 1fr;
  }

  .calendar-head-side {
    justify-self: stretch;
    width: 100%;
    align-items: flex-start;
  }

  .validation-note {
    align-self: auto;
    margin-left: 0;
    text-align: left;
    max-width: none;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 1.9rem;
  }

  .calendar-title {
    font-size: 1.05rem;
  }

  .cell {
    min-height: 118px;
    padding: 7px 8px;
  }

  .cell .roman {
    font-size: 1rem;
  }

  .cell .heb {
    font-size: 0.82rem;
    right: 8px;
  }

  .badge {
    font-size: 0.72rem;
    margin-top: 8px;
    padding: 3px 6px;
  }

  .moon-row {
    gap: 6px;
  }

  .moon-icon-shell {
    width: 22px;
    min-width: 22px;
  }

  .cell .moon-crosscheck {
    font-size: 6.5pt;
  }
}

@media print {
  body {
    background: #fff;
  }

  .controls,
  .right-col,
  .calendar-actions,
  .validation-note {
    display: none !important;
  }

  .wrap {
    max-width: none;
    padding: 0;
  }

  .calendar-card {
    box-shadow: none;
    border: none;
  }
}
