:root {
  --ink-950: #090d16;
  --ink-900: #111827;
  --ink-850: #1a2230;
  --ink-800: #233043;
  --parchment-300: #e5cfa1;
  --parchment-200: #f2dec1;
  --amber-400: #d9a658;
  --emerald-400: #3ec58f;
  --crimson-500: #c54d5c;
  --muted-300: #b5bfce;
  --panel-border: rgba(229, 207, 161, 0.22);
  --panel-bg: rgba(17, 24, 39, 0.78);
  --shadow-deep: 0 22px 50px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #f4f0e6;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  background:
    radial-gradient(
      circle at 80% 15%,
      rgba(217, 166, 88, 0.14),
      transparent 30%
    ),
    radial-gradient(
      circle at 10% 80%,
      rgba(62, 197, 143, 0.08),
      transparent 25%
    ),
    linear-gradient(
      160deg,
      var(--ink-950) 0%,
      var(--ink-900) 55%,
      var(--ink-850) 100%
    );
  overflow-x: hidden;
}

.background-glow {
  position: fixed;
  inset: -15vh -10vw;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(229, 207, 161, 0.03) 0,
      rgba(229, 207, 161, 0.03) 1px,
      transparent 1px,
      transparent 18px
    ),
    radial-gradient(
      circle at 50% 50%,
      rgba(217, 166, 88, 0.08),
      transparent 65%
    );
  animation: drift 16s ease-in-out infinite alternate;
}

@keyframes drift {
  from {
    transform: translateY(0px);
  }
  to {
    transform: translateY(12px);
  }
}

.page {
  width: min(1120px, 92vw);
  margin: 2.5rem auto 3rem;
  display: grid;
  gap: 1.4rem;
}

.hero,
.editorial-panel,
.result-card,
.status-card {
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-deep);
  border-radius: 14px;
}

.hero {
  padding: 2rem 1.6rem 1.8rem;
  position: relative;
  overflow: hidden;
  animation: rise 700ms ease-out both;
}

.hero::after {
  content: '';
  position: absolute;
  inset: auto -20% -45% auto;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(217, 166, 88, 0.24),
    transparent 68%
  );
  pointer-events: none;
}

.kicker {
  margin: 0;
  color: var(--parchment-300);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.brand {
  margin: 0.35rem 0 0.45rem;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(2.4rem, 7vw, 4.8rem);
  line-height: 1;
  color: var(--parchment-200);
  text-shadow:
    0 0 0.5px rgba(242, 222, 193, 0.4),
    0 0 26px rgba(217, 166, 88, 0.25);
  letter-spacing: 0.07em;
}

.lead {
  margin: 0;
  color: var(--muted-300);
  max-width: 74ch;
  font-size: 0.95rem;
  line-height: 1.6;
}

.editorial-panel {
  padding: 1.25rem;
  animation: rise 900ms 100ms ease-out both;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.2s ease;
}

.editorial-panel.drag-active {
  border-color: rgba(62, 197, 143, 0.72);
  box-shadow:
    0 0 0 1px rgba(62, 197, 143, 0.34),
    var(--shadow-deep);
  background: rgba(17, 24, 39, 0.88);
}

.panel-heading h2 {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--parchment-200);
}

.panel-heading p {
  margin: 0.2rem 0 0.85rem;
  color: var(--muted-300);
  font-size: 0.9rem;
}

.charta-editor {
  width: 100%;
}

.CodeMirror {
  width: 100%;
  min-height: 280px;
  border-radius: 10px;
  border: 1px solid rgba(229, 207, 161, 0.28);
  background: rgba(7, 12, 22, 0.82);
  color: #f7f3eb;
  font-size: 1rem;
  line-height: 1.58;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
}

.CodeMirror-scroll {
  min-height: 280px;
}

.CodeMirror-gutters {
  border-right: 1px solid rgba(229, 207, 161, 0.22);
  background: rgba(7, 12, 22, 0.82);
}

.CodeMirror-cursor {
  border-left: 1px solid rgba(242, 222, 193, 0.95);
}

.CodeMirror-focused {
  outline: 2px solid rgba(217, 166, 88, 0.45);
  border-color: rgba(217, 166, 88, 0.6);
}

.CodeMirror .cm-charta-page {
  color: #f0c178;
  font-weight: 600;
}

.CodeMirror .cm-charta-column {
  color: #76dfb5;
  font-weight: 600;
}

.CodeMirror .cm-charta-line {
  color: #7cb9ff;
}

.CodeMirror .cm-charta-square-bracket {
  color: #9aa8bb;
}

.CodeMirror .cm-charta-square-location {
  color: #e8bf82;
  font-weight: 600;
}

.CodeMirror .cm-charta-square-deletion {
  color: #ef8f9d;
  font-weight: 600;
}

.CodeMirror .cm-charta-square-reading {
  color: #84d6c2;
  font-weight: 600;
}

.CodeMirror .cm-charta-square-correction {
  color: #ffd38f;
  font-weight: 700;
}

.CodeMirror .cm-charta-square-editorial {
  color: #c8dd87;
  font-weight: 600;
}

.CodeMirror .cm-charta-square-hand {
  color: #f4c9a6;
  font-weight: 600;
}

.CodeMirror .cm-charta-square-lang {
  color: #9cc7ff;
  font-weight: 600;
}

.CodeMirror .cm-charta-square-separator {
  color: #a8b5c6;
}

.CodeMirror .cm-charta-square-plus {
  color: #e6f085;
  font-weight: 700;
}

.CodeMirror .cm-charta-square-gap {
  color: #f0a7af;
  font-weight: 700;
}

.CodeMirror .cm-charta-square-content {
  color: #d9e1ed;
}

.CodeMirror .cm-charta-angle {
  color: #e9d6b2;
  font-style: italic;
}

.CodeMirror .cm-charta-curly {
  color: #dfbf8e;
}

.CodeMirror .cm-charta-delimiter {
  color: #b3bdcb;
}

.actions {
  margin-top: 0.95rem;
  display: flex;
  gap: 0.62rem;
  flex-wrap: wrap;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-hint {
  margin: 0.65rem 0 0;
  color: var(--muted-300);
  font-size: 0.8rem;
  line-height: 1.45;
}

.btn {
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 0.58rem 0.9rem;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    transform 120ms ease,
    filter 120ms ease,
    border-color 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.07);
}

.btn:focus-visible {
  outline: 2px solid rgba(217, 166, 88, 0.72);
  outline-offset: 2px;
  border-color: rgba(217, 166, 88, 0.72);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.btn-primary {
  background: linear-gradient(130deg, #d8a152, #b77c34);
  color: #120f09;
}

.btn-secondary {
  background: rgba(217, 166, 88, 0.14);
  border-color: rgba(217, 166, 88, 0.45);
  color: var(--parchment-200);
}

.btn-ghost {
  background: rgba(181, 191, 206, 0.08);
  border-color: rgba(181, 191, 206, 0.35);
  color: #d6deea;
}

.status-card {
  padding: 1rem 1.1rem;
  animation: rise 1s 180ms ease-out both;
}

.status-card h2 {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.status-icon {
  font-size: 1rem;
  line-height: 1;
}

.status-card.valid .status-icon::after {
  content: '✓';
  color: var(--emerald-400);
}

.status-card.invalid .status-icon::after {
  content: '✗';
  color: var(--crimson-500);
}

.status-card p {
  margin: 0.28rem 0 0;
}

.status-meta {
  color: var(--muted-300);
  font-size: 0.84rem;
}

.status-card.pending {
  border-color: rgba(181, 191, 206, 0.4);
}

.status-card.valid {
  border-color: rgba(62, 197, 143, 0.68);
  box-shadow:
    0 0 0 1px rgba(62, 197, 143, 0.34),
    var(--shadow-deep);
}

.status-card.invalid {
  border-color: rgba(197, 77, 92, 0.74);
  box-shadow:
    0 0 0 1px rgba(197, 77, 92, 0.36),
    var(--shadow-deep);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.result-card {
  padding: 1rem 1.1rem;
  animation: rise 1.1s 230ms ease-out both;
}

.result-card h3 {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.14rem;
}

.result-list {
  margin: 0.8rem 0 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.44rem;
  list-style: none;
}

.result-list li {
  color: #e7e8ed;
  line-height: 1.48;
}

.result-list li.ok {
  color: var(--emerald-400);
}

.result-list li.ok:before {
  content: '✓';
  margin-right: 0.5em;
}

.result-list li.error {
  color: #f2a9b2;
}

.result-list li.error:before {
  content: '✗';
  margin-right: 0.5em;
}

.error-location {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-style: dotted;
  text-decoration-color: #f2a9b2;
  transition:
    color 0.15s,
    text-decoration-color 0.15s;
}

.error-location:hover,
.error-location:focus-visible {
  color: #fff;
  text-decoration-style: solid;
  outline: none;
}

.result-list li.empty {
  color: var(--muted-300);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .background-glow,
  .hero,
  .editorial-panel,
  .status-card,
  .result-card {
    animation: none;
  }

  .btn {
    transition: none;
  }

  .editorial-panel {
    transition: none;
  }

  .btn:hover {
    transform: none;
    filter: none;
  }
}

@media (max-width: 840px) {
  .page {
    width: min(920px, 94vw);
    margin-top: 1.35rem;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .CodeMirror,
  .CodeMirror-scroll {
    min-height: 240px;
  }
}
