:root {
  color-scheme: light;
  --ink: #211507;
  --muted: #6b5737;
  --paper: #e9d6a6;
  --paper-deep: #c7a665;
  --line: rgba(82, 48, 12, 0.18);
  --violet: #4d2b75;
  --teal: #1c6760;
  --rose: #7d1e27;
  --gold: #c68a2c;
  --ember: #f0ba57;
  --shadow: 0 36px 90px rgba(2, 1, 0, 0.56);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 14%, rgba(236, 154, 52, 0.34), transparent 22%),
    radial-gradient(circle at 80% 16%, rgba(111, 44, 122, 0.34), transparent 26%),
    linear-gradient(120deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(145deg, #060403 0%, #17100b 38%, #2c1b0e 68%, #070504 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 28%, rgba(0, 0, 0, 0.46) 100%),
    linear-gradient(90deg, rgba(198, 138, 44, 0.05), transparent 30%, rgba(100, 34, 46, 0.08));
}

button,
textarea {
  font: inherit;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  overflow: hidden;
}

.book-shell {
  width: min(1180px, 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin: 0 12px 18px;
  color: #fff4d2;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.55);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ember);
}

h1 {
  margin: 0;
  max-width: 760px;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.08;
  letter-spacing: 0;
}

.status-pill {
  flex: none;
  padding: 9px 13px;
  border: 1px solid rgba(240, 186, 87, 0.42);
  border-radius: 999px;
  color: #ffe7a9;
  background: rgba(30, 12, 4, 0.58);
  backdrop-filter: blur(14px);
  font-size: 13px;
  box-shadow: 0 0 28px rgba(240, 186, 87, 0.12);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  align-items: center;
  gap: 10px;
}

.status-link {
  flex: none;
  padding: 9px 13px;
  border: 1px solid rgba(240, 186, 87, 0.42);
  border-radius: 999px;
  color: #ffe7a9;
  background: rgba(125, 30, 39, 0.38);
  font-size: 13px;
  text-decoration: none;
  box-shadow: 0 0 28px rgba(125, 30, 39, 0.14);
}

.status-link:hover {
  background: rgba(125, 30, 39, 0.56);
}

.book {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 680px;
  border: 10px solid #1f1208;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background:
    linear-gradient(90deg, #36200f 0, #b68643 2.8%, #dfc690 4.5%, #e9d6a6 48%, #4d2d11 50%, #dfc690 53%, #e4cf9c 96%, #9b692d 98.4%, #271609 100%);
}

.book::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 47%, rgba(24, 12, 3, 0.72) 50%, transparent 53%),
    radial-gradient(circle at 50% 50%, rgba(255, 234, 162, 0.18), transparent 28%),
    repeating-linear-gradient(90deg, transparent 0 13px, rgba(78, 43, 13, 0.04) 13px 14px);
  mix-blend-mode: multiply;
  z-index: 5;
}

.book::after {
  content: "ARS SCRIBENDI · VERBA VIVUNT · MARGO RESPONDET";
  position: absolute;
  left: 50%;
  top: 18px;
  z-index: 6;
  width: 20px;
  height: calc(100% - 36px);
  transform: translateX(-50%);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  display: grid;
  place-items: center;
  color: rgba(255, 219, 138, 0.68);
  font-family: "Noto Serif SC", serif;
  font-size: 10px;
  letter-spacing: 0.18em;
  pointer-events: none;
}

.book-corner {
  position: absolute;
  z-index: 8;
  width: 74px;
  height: 74px;
  pointer-events: none;
  border-color: rgba(241, 190, 95, 0.82);
}

.corner-tl {
  top: 0;
  left: 0;
  border-top: 3px solid;
  border-left: 3px solid;
  border-radius: 9px 0 0 0;
}

.corner-tr {
  top: 0;
  right: 0;
  border-top: 3px solid;
  border-right: 3px solid;
  border-radius: 0 9px 0 0;
}

.corner-bl {
  bottom: 0;
  left: 0;
  border-bottom: 3px solid;
  border-left: 3px solid;
  border-radius: 0 0 0 9px;
}

.corner-br {
  right: 0;
  bottom: 0;
  border-right: 3px solid;
  border-bottom: 3px solid;
  border-radius: 0 0 9px 0;
}

.page {
  position: relative;
  padding: 34px;
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 96px / 100% 34px,
    radial-gradient(circle at 20% 10%, rgba(255, 238, 176, 0.52), transparent 32%),
    radial-gradient(circle at 92% 92%, rgba(88, 40, 12, 0.16), transparent 34%),
    var(--paper);
  box-shadow: inset 0 0 46px rgba(79, 43, 10, 0.22);
}

.page-left {
  border-right: 1px solid rgba(76, 54, 27, 0.2);
  padding-right: 46px;
}

.page-right {
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 96px / 100% 34px,
    radial-gradient(circle at 82% 18%, rgba(125, 30, 39, 0.18), transparent 34%),
    radial-gradient(circle at 8% 92%, rgba(198, 138, 44, 0.16), transparent 30%),
    #dfc690;
  padding-left: 46px;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  margin-bottom: 24px;
  font-weight: 760;
  color: #4b250d;
  font-family: "Noto Serif SC", serif;
  letter-spacing: 0;
}

.tool-pair {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.small-note {
  color: var(--rose);
  font-size: 13px;
  font-family: Inter, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.icon-button {
  border: 1px solid rgba(79, 36, 9, 0.28);
  border-radius: 999px;
  padding: 8px 11px;
  background: rgba(91, 48, 15, 0.12);
  color: #4a250d;
  cursor: pointer;
  box-shadow: inset 0 1px rgba(255, 247, 220, 0.42);
}

.icon-button.active {
  color: #fff8e8;
  background: #7d1e27;
  border-color: rgba(255, 224, 145, 0.45);
}

.paper-field {
  position: relative;
  min-height: 440px;
  border: 1px solid rgba(70, 31, 8, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(125, 30, 39, 0.08) 1px, transparent 1px) 34px 0 / 34px 100%,
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(104, 58, 16, 0.12) 31px 32px),
    rgba(255, 236, 183, 0.36);
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(69, 33, 6, 0.16);
}

#inkCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  z-index: 2;
  touch-action: none;
  pointer-events: none;
}

.paper-field.ink-enabled #inkCanvas {
  pointer-events: auto;
}

#writingInput {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 34px 32px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: #2a1608;
  font-family: Caveat, "Noto Serif SC", serif;
  font-size: clamp(25px, 2.5vw, 36px);
  line-height: 1.42;
  letter-spacing: 0;
}

.spell-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.spell {
  min-height: 44px;
  border: 1px solid rgba(83, 41, 12, 0.28);
  border-radius: 999px;
  color: #3f210c;
  background:
    linear-gradient(180deg, rgba(255, 239, 196, 0.46), rgba(112, 57, 18, 0.08));
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, color 180ms ease;
  box-shadow: inset 0 1px rgba(255, 248, 222, 0.66);
}

.spell:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.72);
}

.spell.active {
  color: #fff8e8;
  background:
    radial-gradient(circle at 50% 10%, rgba(255, 234, 174, 0.28), transparent 45%),
    linear-gradient(135deg, #7d1e27, #402052 58%, #1c6760);
  border-color: rgba(240, 186, 87, 0.42);
  box-shadow: 0 0 22px rgba(125, 30, 39, 0.22), inset 0 1px rgba(255, 248, 222, 0.25);
}

.margin-thread {
  display: grid;
  gap: 24px;
}

.source-card,
.reply-card {
  border-radius: 8px;
  border: 1px solid rgba(79, 31, 7, 0.2);
  background:
    linear-gradient(135deg, rgba(255, 242, 202, 0.42), rgba(137, 77, 24, 0.12));
  box-shadow: 0 12px 28px rgba(66, 42, 15, 0.13), inset 0 1px rgba(255, 248, 224, 0.38);
}

.source-card {
  padding: 18px 20px;
}

.source-label,
.reply-label {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7d1e27;
}

.source-card p {
  margin: 0;
  color: #4f260c;
  font-family: Caveat, "Noto Serif SC", serif;
  font-size: 27px;
  line-height: 1.25;
}

.annotation {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: start;
}

.annotation-line {
  width: 2px;
  height: 0;
  margin: 15px auto 0;
  border-radius: 999px;
  background: linear-gradient(#7d1e27, #c68a2c, #4d2b75);
  box-shadow: 0 0 14px rgba(125, 30, 39, 0.32);
  transition: height 600ms ease;
}

.reply-card {
  position: relative;
  padding: 24px;
  min-height: 210px;
  overflow: hidden;
}

.reply-card::before {
  content: "";
  position: absolute;
  inset: -40% -20%;
  opacity: 0;
  background: conic-gradient(from 180deg, transparent, rgba(125, 30, 39, 0.18), transparent, rgba(240, 186, 87, 0.18), transparent, rgba(76, 32, 82, 0.16), transparent);
  transition: opacity 450ms ease;
  animation: drift 8s linear infinite;
}

.reply-card.casting::before {
  opacity: 1;
}

#replyText {
  position: relative;
  margin: 0;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(21px, 2.1vw, 30px);
  line-height: 1.58;
  color: #2d1608;
  text-shadow: 0 0 14px rgba(240, 186, 87, 0.12);
}

#replyText span {
  display: inline-block;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  filter: blur(5px);
  animation: inkIn 520ms ease forwards;
}

.keyword-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 42px;
}

.keyword {
  padding: 8px 11px;
  border-radius: 999px;
  color: #fff2cf;
  background:
    linear-gradient(135deg, #7d1e27, #4d2b75);
  border: 1px solid rgba(240, 186, 87, 0.34);
  box-shadow: 0 8px 18px rgba(74, 32, 82, 0.24);
  font-size: 13px;
  opacity: 0;
  transform: translateY(12px);
  animation: floatIn 420ms ease forwards;
}

.manuscript-panel {
  overflow: hidden;
  border: 1px solid rgba(79, 31, 7, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 237, 184, 0.46), rgba(96, 45, 12, 0.1));
  box-shadow: inset 0 0 28px rgba(74, 32, 7, 0.14), 0 16px 32px rgba(66, 42, 15, 0.12);
}

.manuscript-caption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border-bottom: 1px solid rgba(79, 31, 7, 0.18);
  color: #5b2b0e;
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#manuscriptCanvas {
  display: block;
  width: 100%;
  height: 260px;
  cursor: crosshair;
  touch-action: none;
}

.floating-sigil {
  position: absolute;
  z-index: 0;
  color: rgba(255, 220, 134, 0.34);
  font-family: "Noto Serif SC", serif;
  font-size: clamp(42px, 7vw, 96px);
  filter: blur(0.2px);
  pointer-events: none;
  animation: hoverSigil 7s ease-in-out infinite;
}

.sigil-a {
  left: 6vw;
  top: 14vh;
}

.sigil-b {
  right: 8vw;
  top: 12vh;
  animation-delay: -2s;
}

.sigil-c {
  right: 14vw;
  bottom: 9vh;
  animation-delay: -4s;
}

.casting .annotation-line {
  height: 190px;
}

@keyframes inkIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes floatIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  to {
    transform: rotate(360deg);
  }
}

@keyframes hoverSigil {
  50% {
    transform: translateY(-18px) rotate(7deg);
    opacity: 0.64;
  }
}

@media (max-width: 820px) {
  .stage {
    padding: 18px;
    place-items: start center;
  }

  .topbar {
    display: grid;
    margin: 0 4px 14px;
  }

  .book {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .book::before {
    display: none;
  }

  .book::after,
  .book-corner {
    display: none;
  }

  .page,
  .page-left,
  .page-right {
    padding: 24px;
  }

  .paper-field {
    min-height: 360px;
  }

  .spell-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .annotation {
    grid-template-columns: 24px minmax(0, 1fr);
  }
}
