:root {
  --ledger-bg: #050504;
  --ledger-ink: #21190f;
  --ledger-paper: #efe2c0;
  --ledger-paper-deep: #d8bf88;
  --ledger-paper-shadow: rgba(52, 35, 14, 0.42);
  --ledger-gold: #d2ad62;
  --ledger-gold-strong: #f0d487;
  --ledger-blue: #9bbccc;
  --ledger-green: #a9b77c;
  --ledger-red: #c5897d;
  --ledger-line: rgba(82, 58, 25, 0.24);
  --ledger-night: #071014;
  --ledger-night-soft: rgba(7, 16, 20, 0.74);
  --ledger-focus: rgba(210, 173, 98, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(155, 188, 204, 0.18), transparent 28rem),
    radial-gradient(circle at 80% 86%, rgba(169, 183, 124, 0.13), transparent 24rem),
    linear-gradient(180deg, #030303 0%, #071014 45%, #050504 100%);
  color: var(--ledger-paper);
  font-family: Georgia, "Times New Roman", serif;
}

button,
textarea,
a {
  font: inherit;
}

.ledger-page {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  padding: 28px 0 34px;
  isolation: isolate;
}

.ledger-page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 50% 8%, rgba(240, 212, 135, 0.14), transparent 28rem),
    linear-gradient(90deg, rgba(0, 0, 0, 0.68), transparent 24%, transparent 76%, rgba(0, 0, 0, 0.68));
  opacity: 0.72;
}

.ledger-page::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 50% 18%, rgba(240, 212, 135, 0.18), transparent 24rem),
    linear-gradient(180deg, rgba(0, 0, 0, 0.52), rgba(0, 0, 0, 0.78));
  pointer-events: none;
}

.ledger-main {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0;
  width: min(1220px, calc(100% - 32px));
  min-height: 760px;
  margin: 0 auto;
  border: 1px solid rgba(240, 212, 135, 0.34);
  border-radius: 18px;
  background:
    linear-gradient(90deg,
      rgba(61, 42, 16, 0.22) 0%,
      rgba(239, 226, 192, 0.98) 47%,
      rgba(95, 69, 30, 0.42) 49.5%,
      rgba(56, 40, 18, 0.66) 50%,
      rgba(95, 69, 30, 0.42) 50.5%,
      rgba(235, 220, 184, 0.96) 100%);
  color: var(--ledger-ink);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.56),
    inset 0 0 0 1px rgba(255, 255, 255, 0.26),
    inset 0 32px 80px rgba(255, 255, 255, 0.18);
}

.ledger-main::before {
  content: "";
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background:
    linear-gradient(180deg, transparent, rgba(43, 30, 12, 0.46), transparent),
    linear-gradient(90deg, rgba(255, 255, 255, 0.34), rgba(0, 0, 0, 0.18));
  box-shadow:
    -18px 0 32px rgba(60, 38, 13, 0.16),
    18px 0 32px rgba(60, 38, 13, 0.18);
  pointer-events: none;
}

.ledger-leaf {
  position: relative;
  min-height: 760px;
  padding: 42px;
}

.ledger-leaf--question {
  direction: rtl;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), transparent 18%),
    radial-gradient(circle at 20% 18%, rgba(155, 188, 204, 0.18), transparent 17rem);
}

.ledger-leaf--context {
  direction: rtl;
  display: flex;
  background:
    linear-gradient(270deg, rgba(255, 255, 255, 0.20), transparent 20%),
    radial-gradient(circle at 72% 16%, rgba(169, 183, 124, 0.18), transparent 17rem);
}

.ledger-hero {
  margin: 0 0 22px;
}

.ledger-panel-kicker,
.ledger-long-label,
.ledger-result-label {
  margin: 0 0 10px;
  color: #8d6321;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.88rem;
  font-weight: 700;
}

.ledger-current-type {
  display: inline-flex;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(141, 99, 33, 0.26);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.26);
  color: #614518;
  font-size: 0.95rem;
}

.ledger-ordinance-banner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  margin: 0 0 22px;
  padding: 14px 16px;
  border: 1px solid rgba(141, 99, 33, 0.22);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.30);
}

.ledger-ordinance-title,
.ledger-ordinance-copy,
.ledger-ordinance-until-line {
  margin: 0;
}

.ledger-ordinance-title {
  color: #2e210f;
  font-size: 1rem;
  font-weight: 700;
}

.ledger-ordinance-copy,
.ledger-ordinance-until-line {
  color: rgba(33, 25, 15, 0.72);
  line-height: 1.7;
}

.ledger-question-card {
  position: relative;
  min-height: 430px;
  padding: 26px 24px 30px;
  border-top: 1px solid rgba(141, 99, 33, 0.22);
  border-bottom: 1px solid rgba(141, 99, 33, 0.20);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.06)),
    repeating-linear-gradient(180deg, transparent 0, transparent 2.35rem, rgba(141, 99, 33, 0.12) 2.39rem);
}

.ledger-question-card::after {
  content: "";
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(141, 99, 33, 0.10);
  pointer-events: none;
}

.ledger-question-title {
  margin: 0 0 18px;
  color: #21190f;
  line-height: 1.35;
  font-size: 1.8rem;
}

.ledger-question-text {
  min-height: 20rem;
  margin: 0;
  color: rgba(33, 25, 15, 0.86);
  line-height: 2.05;
  font-size: 1.18rem;
  white-space: pre-wrap;
}

.ledger-question-text[data-writing="true"] {
  animation: ledgerWrittenBreath 2.8s ease-in-out infinite alternate;
}

.ledger-question-text[data-writing="true"]::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1.1em;
  margin-inline-start: 4px;
  border-inline-end: 2px solid #8d6321;
  animation: ledgerCursor 0.9s steps(2, start) infinite;
  vertical-align: text-bottom;
}

@keyframes ledgerCursor {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes ledgerWrittenBreath {
  from {
    text-shadow: 0 0 0 rgba(141, 99, 33, 0);
    transform: translateY(0);
  }
  to {
    text-shadow: 0 6px 18px rgba(141, 99, 33, 0.12);
    transform: translateY(-2px);
  }
}

.clear-context-sequence {
  position: relative;
  flex: 1;
  min-height: 676px;
  height: auto;
  overflow: hidden;
  border: 1px solid rgba(33, 25, 15, 0.22);
  border-radius: 14px;
  background: #07090a;
  box-shadow: 0 24px 46px rgba(52, 35, 14, 0.24);
}

.clear-context-step {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr;
  margin: 0;
  overflow: hidden;
  background: #1b1710;
  opacity: 0;
  transform: scale(1.035);
  transition: opacity 0.75s ease, transform 1.1s ease;
  pointer-events: none;
}

.clear-context-step.is-active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.clear-context-step img {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  object-fit: cover;
  filter: saturate(0.92) contrast(1.05);
  transform: scale(1.08);
  animation: ledgerSceneCamera 10s ease-in-out var(--scene-delay, 0ms) infinite alternate;
}

.clear-context-art {
  display: block;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 50% 46%, rgba(240, 212, 135, 0.25), transparent 36%),
    linear-gradient(135deg, #1c2020, #4d3b1b);
}

.clear-context-empty {
  display: block;
  width: 100%;
  height: 100%;
  background: #07090a;
}

@keyframes ledgerSceneCamera {
  from {
    transform: scale(1.08) translate3d(1.8%, -1.4%, 0);
  }
  to {
    transform: scale(1.16) translate3d(-1.6%, 1.2%, 0);
  }
}

.ledger-answer-wrap {
  width: min(1220px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 18px;
  border: 1px solid rgba(240, 212, 135, 0.22);
  border-radius: 16px;
  background:
    linear-gradient(90deg, rgba(7, 16, 20, 0.92), rgba(32, 27, 17, 0.88)),
    rgba(0, 0, 0, 0.54);
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.38);
}

.ledger-answer-heading {
  margin: 0 0 14px;
  color: var(--ledger-paper);
  font-size: 1.35rem;
  line-height: 1.4;
}

.ledger-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.ledger-choice-card {
  min-height: 142px;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 14px;
  align-items: start;
  width: 100%;
  padding: 18px;
  border: 1px solid rgba(240, 212, 135, 0.22);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    rgba(0, 0, 0, 0.24);
  color: var(--ledger-paper);
  cursor: pointer;
  text-align: start;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.ledger-choice-card:hover,
.ledger-choice-card.selected {
  border-color: rgba(240, 212, 135, 0.58);
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
}

.ledger-choice-card.selected {
  background:
    linear-gradient(180deg, rgba(210, 173, 98, 0.18), rgba(255, 255, 255, 0.03)),
    rgba(0, 0, 0, 0.24);
}

.ledger-choice-badge {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ledger-gold-strong);
  color: #141008;
  font-weight: 700;
}

.ledger-choice-title {
  display: block;
  margin-bottom: 9px;
  color: var(--ledger-gold-strong);
  font-size: 1.05rem;
}

.ledger-choice-text {
  display: block;
  color: rgba(239, 226, 192, 0.84);
  line-height: 1.75;
  font-size: 1rem;
}

.ledger-answer-label {
  display: block;
  margin: 4px 0 10px;
  color: var(--ledger-gold-strong);
  font-weight: 700;
}

.ledger-answer-input {
  width: 100%;
  min-height: 116px;
  resize: vertical;
  padding: 16px;
  border: 1px solid rgba(240, 212, 135, 0.24);
  border-radius: 12px;
  outline: none;
  background: rgba(239, 226, 192, 0.96);
  color: var(--ledger-ink);
  line-height: 1.8;
}

.ledger-answer-input:focus {
  border-color: rgba(240, 212, 135, 0.82);
  box-shadow: 0 0 0 3px rgba(240, 212, 135, 0.15);
}

.ledger-primary-btn,
.ledger-secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin-top: 14px;
  padding: 12px 22px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}

.ledger-primary-btn {
  border: 1px solid rgba(255, 244, 214, 0.4);
  background: linear-gradient(180deg, #f0d487, #c99e49);
  color: #151008;
}

.ledger-secondary-btn {
  border: 1px solid rgba(240, 212, 135, 0.32);
  background: rgba(0, 0, 0, 0.22);
  color: var(--ledger-gold-strong);
}

.ledger-primary-btn:hover,
.ledger-secondary-btn:hover {
  transform: translateY(-1px);
}

.ledger-primary-btn:disabled,
.ledger-secondary-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.ledger-result-card {
  width: min(1220px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 22px;
  border: 1px solid rgba(240, 212, 135, 0.24);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(239, 226, 192, 0.96), rgba(216, 191, 136, 0.92));
  color: var(--ledger-ink);
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.38);
}

.ledger-result-title {
  margin: 0 0 18px;
  font-size: 1.7rem;
  color: #21190f;
}

.ledger-result-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.ledger-result-box,
.ledger-long-result {
  padding: 14px;
  border: 1px solid rgba(33, 25, 15, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.28);
}

.ledger-result-box span,
.ledger-long-label {
  display: block;
  color: rgba(33, 25, 15, 0.62);
  font-size: 0.92rem;
}

.ledger-result-value {
  display: block;
  margin-top: 8px;
  color: #21190f;
  line-height: 1.45;
}

.ledger-long-result {
  margin-top: 12px;
}

.ledger-long-copy {
  margin: 8px 0 0;
  color: rgba(33, 25, 15, 0.78);
  line-height: 1.85;
}

.ledger-result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.ledger-choice-card:focus-visible,
.ledger-answer-input:focus-visible,
.ledger-primary-btn:focus-visible,
.ledger-secondary-btn:focus-visible {
  outline: 3px solid var(--ledger-focus);
  outline-offset: 3px;
}

.clear-owner-sample-choices {
  display: none;
}

.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  .ledger-page {
    padding: 18px 0 24px;
    overflow: hidden;
  }

  .ledger-main {
    display: block;
    min-height: auto;
    width: min(100%, calc(100% - 22px));
  }

  .ledger-main::before {
    display: none;
  }

  .ledger-leaf {
    min-height: auto;
    padding: 26px;
  }

  .ledger-leaf + .ledger-leaf {
    border-top: 1px solid rgba(33, 25, 15, 0.20);
  }

  .ledger-choices,
  .clear-owner-sample-choices,
  .ledger-result-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .ledger-main,
  .ledger-answer-wrap,
  .ledger-result-card {
    width: min(100%, calc(100% - 18px));
  }

  .ledger-leaf,
  .ledger-answer-wrap,
  .ledger-result-card {
    padding: 18px;
  }

  .ledger-question-title {
    font-size: 1.45rem;
  }

  .ledger-question-text {
    min-height: 10rem;
    font-size: 1.05rem;
  }

  .clear-context-sequence,
  .clear-owner-sample-choices article {
    grid-template-columns: 1fr;
  }

  .clear-context-sequence {
    min-height: 470px;
  }

  .ledger-ordinance-banner {
    grid-template-columns: 1fr;
  }
}
