:root {
  --ink: #2c1c15;
  --muted: #6e5143;
  --rust: #8d4935;
  --rust-deep: #693425;
  --brown: #8a5b43;
  --paper: #e8d9b5;
  --paper-light: #f5ead1;
  --line: rgba(103, 65, 45, 0.26);
  --blue: #46627a;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.42), transparent 28%),
    radial-gradient(circle at 86% 38%, rgba(155,111,69,.12), transparent 34%),
    repeating-linear-gradient(7deg, rgba(103,76,45,.025) 0 1px, transparent 1px 5px),
    var(--paper);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: .28;
  background-image:
    repeating-radial-gradient(circle at 30% 20%, rgba(94,67,39,.12) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
}

.converter-shell { width: min(1180px, calc(100% - 20px)); margin: 0 auto; padding: 22px 0 34px; }
.converter-card { position: relative; z-index: 1; }
.converter-intro { text-align: center; }
.eyebrow { margin: 0 0 5px; color: var(--rust); font-size: .62rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font: 700 clamp(1.65rem, 3.4vw, 2.55rem)/1.04 Georgia, serif; }
.converter-intro > p:last-child { margin: 8px 0 0; color: var(--muted); font-size: .82rem; }

.date-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: center;
  gap: 9px;
  margin: 18px auto 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(245, 234, 209, .72);
  box-shadow: 0 18px 50px rgba(76, 49, 33, .12);
}

.date-form label { display: grid; gap: 5px; color: var(--muted); font-family: Georgia, serif; font-size: .78rem; }
.date-form input,
.date-form select {
  height: 42px;
  padding: 0 10px;
  color: var(--ink);
  font: 500 1.05rem Georgia, serif;
  background: #fffdf7;
  border: 2px solid var(--blue);
  border-radius: 12px;
  outline: 0;
}
.date-form input:focus,
.date-form select:focus { border-color: var(--rust); box-shadow: 0 0 0 3px rgba(141,73,53,.16); }
.date-form input { width: 66px; }
.date-form .year-field input { width: 108px; }
.date-form select { min-width: 94px; }
.date-form button {
  min-height: 42px;
  padding: 0 21px;
  color: #fff;
  font-size: .82rem;
  font-weight: 800;
  background: var(--rust-deep);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease;
}
.date-form button:hover { background: var(--rust); transform: translateY(-2px); }

.converter-error { max-width: 720px; margin: 12px auto 0; padding: 10px 12px; color: #762d22; text-align: center; background: #f8d9cb; border-radius: 10px; }
.converter-result { display: grid; gap: 14px; margin-top: 17px; opacity: 0; transform: translateY(8px); transition: opacity .35s ease, transform .35s ease; }
.converter-result.is-visible { opacity: 1; transform: none; }
.result-section { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: rgba(250,244,226,.76); box-shadow: 0 11px 26px rgba(69,43,29,.1); }
.result-section h2 { margin: 0; font: 700 clamp(1.2rem, 2vw, 1.5rem)/1.08 Georgia, serif; }

.section-heading { display: flex; align-items: end; gap: 11px; padding: 12px 16px; color: #fff; background: linear-gradient(120deg, var(--rust-deep), var(--rust)); }
.section-heading p { margin: 0 0 3px; color: #f2cf77; font-size: .54rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.section-heading strong { margin-left: auto; font: 700 clamp(1.05rem, 2vw, 1.35rem) ui-monospace, SFMono-Regular, monospace; white-space: nowrap; }

.long-count-expression { padding: 10px 14px 12px; }
.long-count-row { display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; justify-items: center; gap: 10px; }
.long-count-period-row { min-height: 78px; }
.long-count-numeral-row { min-height: 92px; margin-top: 3px; }
.long-count-period,
.long-count-numeral,
.date-numeral,
.date-sign,
.lord-glyph { display: block; object-fit: contain; }
.long-count-period { width: min(84px, 100%); height: 76px; }
.long-count-numeral { width: 57px; height: 90px; }

.calendar-round-section { padding: 10px; }
.calendar-round-section > h2,
.lord-section > h2 { text-align: center; }
.calendar-round-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 570px; margin: 9px auto 0; }
.calendar-date { padding: 7px; text-align: center; background: rgba(255,253,247,.62); border: 1px solid var(--line); border-radius: 13px; }
.calendar-date h3 { margin: 0; color: var(--rust); font-size: .58rem; letter-spacing: .13em; text-transform: uppercase; }
.date-written { margin: 4px 0 5px; font: 700 .92rem Georgia, serif; }
.date-glyph-pair { display: flex; min-height: 62px; align-items: center; justify-content: center; gap: 2px; }
.date-numeral { width: 38px; height: 57px; }
.date-sign { width: 60px; height: 60px; }

.closing-cycle-section { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.lord-section { padding: 10px 14px; text-align: center; }
.lord-name { margin: 5px 0 0; color: var(--rust-deep); font: 700 1rem Georgia, serif; }
.lord-glyph { width: 70px; height: 70px; margin: 0 auto; }
.year-bearer { display: grid; place-items: center; margin: 0; padding: 21px; color: #fff; font: 600 clamp(.82rem, 1.35vw, .95rem)/1.5 Georgia, serif; text-align: center; background: linear-gradient(145deg, var(--rust-deep), var(--rust)); border-left: 1px solid rgba(255,255,255,.18); }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@media (max-width: 720px) {
  .converter-shell { width: min(100% - 16px, 640px); padding-top: 22px; }
  .date-form { padding: 18px 12px; }
  .date-form button { width: 100%; }
  .section-heading { align-items: start; flex-direction: column; }
  .section-heading strong { margin-left: 0; }
  .long-count-expression { overflow-x: auto; padding-inline: 10px; }
  .long-count-row { min-width: 610px; }
  .calendar-round-grid { grid-template-columns: 1fr; }
  .closing-cycle-section { grid-template-columns: 1fr; }
  .year-bearer { min-height: 180px; border-top: 1px solid rgba(255,255,255,.18); border-left: 0; }
}
