/* ============================================================
   SCRIPTORIUM
   A study chamber. Warm dark. Gilt accents. Manuscript ornaments.
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

:root {
  /* Palette — aged parchment under candlelight */
  --ink:        #ede6d3;
  --ink-soft:   #b8af96;
  --ink-faint:  #6f6757;
  --ink-ghost:  #3a342a;
  --paper:      #14110b;
  --paper-deep: #0b0907;
  --paper-raised: #1d180f;
  --gilt:        #d4a155;
  --gilt-bright: #ecbf76;
  --ember:       #c66432;
  --moss:        #889a5e;
  --rust:        #b04830;

  /* Type */
  --display: "Fraunces", "Cormorant Garamond", Georgia, serif;
  --italic:  "Instrument Serif", "Cormorant Garamond", Georgia, serif;
  --mono:    "JetBrains Mono", "IBM Plex Mono", "Courier New", monospace;

  --ease:    cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

body {
  font-family: var(--display);
  font-variation-settings: "opsz" 24, "wght" 400, "SOFT" 30;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Atmospheric layers
   ============================================================ */

.grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 0.95 0 0 0 0 0.85 0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.vignette {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 50% 30%, transparent 0%, transparent 40%, rgba(0,0,0,0.55) 100%),
    radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.4) 0%, transparent 60%);
}

.ember-glow {
  position: fixed;
  bottom: -28vh;
  left: 50%;
  transform: translateX(-50%);
  width: 90vw;
  height: 60vh;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(212, 161, 85, 0.10) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 0%, rgba(198, 100, 50, 0.07) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  filter: blur(30px);
  transition: opacity 0.8s var(--ease), filter 0.8s var(--ease);
}

/* ============================================================
   Masthead
   ============================================================ */

.masthead {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 30px 60px 22px;
  border-bottom: 1px solid var(--ink-ghost);
  animation: fade-in 1s var(--ease-out) both;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.fleuron {
  font-size: 28px;
  color: var(--gilt);
  transform: translateY(4px);
  display: inline-block;
}

.brand-name {
  font-family: var(--display);
  font-variation-settings: "opsz" 144, "wght" 380, "SOFT" 80, "WONK" 1;
  font-size: 36px;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.brand-tag {
  font-family: var(--italic);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 17px;
  letter-spacing: 0.005em;
}

.masthead-clock {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  font-feature-settings: "tnum";
}

/* ============================================================
   Main grid
   ============================================================ */

.study-hall {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 80px;
  padding: 56px 60px 36px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  transition: padding 0.8s var(--ease), gap 0.8s var(--ease);
}

/* ============================================================
   Timer stage
   ============================================================ */

.timer-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  animation: fade-up 1s 0.1s var(--ease-out) both;
}

.subject-wrap { text-align: center; }

.micro-label {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
  padding-left: 0.4em;
}

.subject-input {
  background: transparent;
  border: none;
  outline: none;
  text-align: center;
  font-family: var(--italic);
  font-style: italic;
  font-size: 28px;
  color: var(--gilt-bright);
  width: min(440px, 80vw);
  padding: 4px 0 8px;
  border-bottom: 1px dashed var(--ink-ghost);
  transition: border-color 0.3s var(--ease);
}
.subject-input:focus { border-bottom-color: var(--gilt); }
.subject-input::placeholder {
  color: var(--ink-faint);
  font-style: italic;
  opacity: 0.7;
}

.timer-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 12px 0 18px;
  position: relative;
}

.phase-mark {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.55em;
  font-weight: 500;
  color: var(--gilt);
  padding-left: 0.55em;
  transition: color 0.4s var(--ease);
}
.phase-mark.break { color: var(--moss); }
.phase-mark.paused { color: var(--ink-faint); }

.timer-numerals {
  font-family: var(--mono);
  font-feature-settings: "tnum", "ss02", "zero";
  font-size: clamp(108px, 17vw, 220px);
  font-weight: 250;
  letter-spacing: -0.045em;
  color: var(--ink);
  line-height: 0.95;
  display: flex;
  align-items: baseline;
  user-select: none;
  transition: font-size 0.8s var(--ease), color 0.4s var(--ease);
}

.colon {
  color: var(--gilt);
  margin: 0 0.04em;
  animation: blink 2.2s ease-in-out infinite;
  position: relative;
  top: -0.05em;
}
.timer-numerals.paused .colon {
  animation: none;
  opacity: 0.35;
}
.timer-numerals.idle .colon {
  animation: none;
  opacity: 0.55;
}

@keyframes blink {
  0%, 50%   { opacity: 1; }
  60%, 100% { opacity: 0.45; }
}

.progress-rail {
  width: min(440px, 65vw);
  height: 1px;
  background: var(--ink-ghost);
  position: relative;
  margin-top: 4px;
}
.progress-fill {
  position: absolute;
  top: -1px; left: 0;
  height: 3px;
  background: linear-gradient(to right, var(--ember), var(--gilt));
  width: 0%;
  transition: width 0.5s linear;
  box-shadow: 0 0 8px rgba(212, 161, 85, 0.4);
}

.session-dots {
  display: flex;
  gap: 24px;
  margin-top: 14px;
  align-items: center;
}
.session-dots .dot {
  width: 7px;
  height: 7px;
  border: 1px solid var(--ink-faint);
  border-radius: 50%;
  transition: all 0.4s var(--ease);
}
.session-dots .dot.done {
  background: var(--gilt);
  border-color: var(--gilt);
  box-shadow: 0 0 14px rgba(212, 161, 85, 0.6);
  transform: scale(1.05);
}
.session-dots .dot.active {
  border-color: var(--gilt);
  background: rgba(212, 161, 85, 0.25);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(212,161,85,0.5); }
  50%      { transform: scale(1.25); box-shadow: 0 0 12px rgba(212,161,85,0.4); }
}

.presets {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 6px;
}
.presets-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 4px;
}
.preset {
  background: transparent;
  border: none;
  font-family: var(--display);
  font-variation-settings: "opsz" 24, "wght" 500;
  font-size: 14px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 2px 6px;
  transition: color 0.25s var(--ease);
}
.preset:hover { color: var(--ink); }
.preset.active {
  color: var(--gilt-bright);
  font-variation-settings: "opsz" 24, "wght" 600;
  text-shadow: 0 0 14px rgba(236, 191, 118, 0.3);
}
.preset-sep {
  color: var(--ink-ghost);
  font-size: 12px;
}

/* Controls bar */
.controls {
  display: flex;
  margin-top: 8px;
  border: 1px solid var(--ink-ghost);
  background: rgba(20, 17, 11, 0.4);
  backdrop-filter: blur(2px);
  position: relative;
}
.controls::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid var(--ink-ghost);
  pointer-events: none;
  opacity: 0.35;
}

.ctrl {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  padding: 14px 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: uppercase;
  font-weight: 500;
  transition: all 0.25s var(--ease);
  border-right: 1px solid var(--ink-ghost);
  position: relative;
  z-index: 1;
}
.ctrl:last-child { border-right: none; }
.ctrl:hover {
  color: var(--gilt-bright);
  background: rgba(212, 161, 85, 0.06);
}

.ctrl-symbol {
  font-size: 13px;
  color: var(--gilt);
  line-height: 1;
}
.ctrl:hover .ctrl-symbol { color: var(--gilt-bright); }


.ctrl.playing {
  color: var(--gilt-bright);
  background: rgba(212, 161, 85, 0.07);
}
.ctrl.playing .ctrl-symbol {
  color: var(--gilt-bright);
  filter: drop-shadow(0 0 8px rgba(236, 191, 118, 0.45));
}

.ctrl.primary { color: var(--ink); }
.ctrl.primary:hover { background: rgba(212, 161, 85, 0.12); }

.ctrl.lock {
  color: var(--gilt-bright);
}
.ctrl.lock:hover {
  background: rgba(198, 100, 50, 0.12);
}

/* ============================================================
   Ledger panel
   ============================================================ */

.ledger {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-self: start;
}

.ledger-card {
  background: linear-gradient(180deg, var(--paper-raised) 0%, rgba(20, 17, 11, 0.7) 100%);
  border: 1px solid var(--ink-ghost);
  padding: 28px 30px;
  position: relative;
  animation: fade-up 1s var(--ease-out) both;
}
.ledger-card:nth-child(1) { animation-delay: 0.4s; }
.ledger-card:nth-child(2) { animation-delay: 0.55s; }
.ledger-card:nth-child(3) { animation-delay: 0.7s; }

.ledger-card::before {
  content: '';
  position: absolute;
  top: 5px; left: 5px; right: 5px; bottom: 5px;
  border: 1px solid var(--ink-ghost);
  pointer-events: none;
  opacity: 0.35;
}

/* corner ornaments */
.ledger-card::after {
  content: '';
  position: absolute;
  top: -1px; right: -1px;
  width: 14px; height: 14px;
  border-top: 1px solid var(--gilt);
  border-right: 1px solid var(--gilt);
  opacity: 0.6;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
}

.card-label {
  font-family: var(--display);
  font-variation-settings: "opsz" 14, "wght" 500, "SOFT" 50;
  font-size: 14.5px;
  letter-spacing: 0.04em;
  color: var(--gilt);
}

.card-date, .card-count {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.22em;
  color: var(--ink-faint);
  text-transform: uppercase;
  font-feature-settings: "tnum";
}

/* Stats card */
.stats-row {
  display: flex;
  gap: 36px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px dashed var(--ink-ghost);
}
.stat-num {
  font-family: var(--mono);
  font-feature-settings: "tnum";
  font-size: 32px;
  font-weight: 300;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat-cap {
  font-family: var(--italic);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 6px;
}

.streak-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 14px;
  color: var(--ink-soft);
  font-variation-settings: "opsz" 14, "wght" 400;
}
.streak-row strong {
  color: var(--gilt-bright);
  font-variation-settings: "opsz" 14, "wght" 600;
  font-size: 16px;
}
.streak-flame {
  font-size: 17px;
  color: var(--ember);
  filter: drop-shadow(0 0 6px rgba(198, 100, 50, 0.4));
}

/* Tasks */
.task-list {
  list-style: none;
  margin-bottom: 14px;
  max-height: 240px;
  overflow-y: auto;
}
.task-list::-webkit-scrollbar { width: 4px; }
.task-list::-webkit-scrollbar-thumb { background: var(--ink-ghost); }

.task-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--ink-ghost);
  font-family: var(--display);
  font-variation-settings: "opsz" 16, "wght" 400;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.2s var(--ease);
}
.task-list li:last-child { border-bottom: none; }
.task-list li:hover { color: var(--gilt-bright); }
.task-list li.done {
  color: var(--ink-faint);
  font-style: italic;
  text-decoration: line-through;
  text-decoration-color: var(--gilt);
  text-decoration-thickness: 1px;
}
.task-list li .check {
  width: 14px;
  height: 14px;
  border: 1px solid var(--ink-faint);
  border-radius: 1px;
  flex-shrink: 0;
  position: relative;
  transition: all 0.2s var(--ease);
}
.task-list li:hover .check { border-color: var(--gilt); }
.task-list li.done .check {
  background: var(--gilt);
  border-color: var(--gilt);
}
.task-list li.done .check::after {
  content: '\2713';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--paper);
  font-weight: 700;
}
.task-list li .task-text { flex: 1; }
.task-list li .x-btn {
  margin-left: auto;
  opacity: 0;
  background: none;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 16px;
  padding: 2px 4px;
  transition: opacity 0.2s, color 0.2s;
}
.task-list li:hover .x-btn { opacity: 1; }
.task-list li .x-btn:hover { color: var(--rust); }

.task-empty {
  font-family: var(--italic);
  font-style: italic;
  color: var(--ink-faint);
  padding: 8px 0;
  cursor: default;
  border-bottom: none !important;
  font-size: 14px;
}
.task-empty:hover { color: var(--ink-faint) !important; }

.task-form {
  display: flex;
  border: 1px solid var(--ink-ghost);
  background: rgba(11, 9, 7, 0.5);
}
.task-form input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 11px 14px;
  color: var(--ink);
  font-family: var(--display);
  font-variation-settings: "opsz" 16, "wght" 400;
  font-size: 14px;
}
.task-form input::placeholder {
  color: var(--ink-faint);
  font-style: italic;
  opacity: 0.6;
}
.task-form button {
  background: transparent;
  border: none;
  border-left: 1px solid var(--ink-ghost);
  color: var(--gilt);
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 300;
  padding: 0 18px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.task-form button:hover {
  background: rgba(212, 161, 85, 0.08);
  color: var(--gilt-bright);
}

/* Distraction card */
.distract-blurb {
  font-family: var(--italic);
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin-bottom: 16px;
}

.urge-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--ember);
  color: var(--ember);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 14px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
}
.urge-btn:hover {
  background: var(--ember);
  color: var(--paper);
  letter-spacing: 0.4em;
}
.urge-btn.tapped {
  animation: shake 0.4s var(--ease);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ============================================================
   Colophon
   ============================================================ */

.colophon {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 60px 24px;
  border-top: 1px solid var(--ink-ghost);
  font-family: var(--italic);
  color: var(--ink-faint);
  font-size: 14px;
  font-style: italic;
  animation: fade-in 1.4s 0.8s var(--ease-out) both;
}
.colophon-keys {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  font-style: normal;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ============================================================
   Lock-in mode
   ============================================================ */

body.locked .masthead,
body.locked .colophon,
body.locked .ledger,
body.locked .presets,
body.locked .progress-rail {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease);
}

body.locked .study-hall {
  grid-template-columns: 1fr;
  padding: 0;
  min-height: 100vh;
  align-items: center;
  justify-items: center;
}
body.locked .timer-stage {
  width: 100%;
  justify-content: center;
  min-height: 100vh;
  gap: 40px;
}
body.locked .timer-numerals {
  font-size: clamp(160px, 28vw, 380px);
  font-weight: 200;
}
body.locked .subject-input {
  border-bottom-color: transparent;
  font-size: 22px;
  pointer-events: none;
}
body.locked .micro-label { opacity: 0; transition: opacity 0.3s; }

body.locked .ember-glow {
  opacity: 1.4;
  filter: blur(50px);
  animation: candle-flicker 5s ease-in-out infinite alternate;
}

body.locked .controls {
  background: transparent;
  border-color: rgba(58, 52, 42, 0.4);
}
body.locked .controls::before { display: none; }
body.locked .ctrl-label { display: none; }
body.locked .ctrl { padding: 12px 18px; gap: 0; }

body.locked .session-dots .dot { opacity: 0.7; }

body.locked::before {
  content: '\276E';
  position: fixed;
  top: 30px; left: 30px;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.2em;
  opacity: 0;
  animation: hint-fade 6s 1.5s var(--ease) forwards;
  z-index: 10;
}
body.locked::after {
  content: 'press esc to release';
  position: fixed;
  top: 30px; left: 60px;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  opacity: 0;
  animation: hint-fade 6s 1.5s var(--ease) forwards;
  z-index: 10;
}

@keyframes hint-fade {
  0%   { opacity: 0; }
  20%  { opacity: 0.6; }
  80%  { opacity: 0.6; }
  100% { opacity: 0; }
}

@keyframes candle-flicker {
  0%   { opacity: 1.2; transform: translateX(-50%) scale(1); }
  30%  { opacity: 1.4; transform: translateX(-50%) scale(1.04); }
  60%  { opacity: 1.1; transform: translateX(-50%) scale(0.98); }
  100% { opacity: 1.3; transform: translateX(-50%) scale(1.02); }
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Session — masthead button, peer presence, modal, toasts
   ============================================================ */

.masthead-right {
  display: flex;
  align-items: center;
  gap: 26px;
}

.session-btn {
  background: transparent;
  border: 1px solid var(--ink-ghost);
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 9px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s var(--ease);
  position: relative;
}
.session-btn:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
  background: rgba(212, 161, 85, 0.04);
}
.session-btn .session-icon {
  font-size: 13px;
  line-height: 1;
}

.session-btn.connected {
  color: var(--gilt-bright);
  border-color: var(--gilt);
  background: rgba(212, 161, 85, 0.08);
}
.session-btn.connected:hover { background: rgba(212, 161, 85, 0.14); }
.session-btn.connected .session-icon {
  color: var(--gilt-bright);
  filter: drop-shadow(0 0 6px rgba(236, 191, 118, 0.6));
}

.session-btn.hosting {
  color: var(--gilt);
  border-color: var(--gilt);
  animation: hosting-pulse 2.4s ease-in-out infinite;
}
.session-btn.hosting .session-icon {
  animation: spin-slow 4s linear infinite;
  display: inline-block;
}
.session-btn.error {
  color: var(--rust);
  border-color: var(--rust);
}

@keyframes hosting-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(212, 161, 85, 0); }
  50%      { box-shadow: 0 0 18px rgba(212, 161, 85, 0.3); }
}
@keyframes spin-slow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Peer presence under subject */

.peer-presence {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  padding: 6px 14px;
  font-family: var(--display);
  font-variation-settings: "opsz" 16, "wght" 400;
  font-size: 14px;
  color: var(--ink-soft);
  animation: fade-up 0.5s var(--ease-out);
  border-radius: 1px;
  transition: background 0.6s ease;
}
.peer-presence[hidden] { display: none; }
.peer-fleuron {
  color: var(--gilt);
  font-size: 13px;
  filter: drop-shadow(0 0 6px rgba(212, 161, 85, 0.4));
}
.peer-text strong {
  color: var(--gilt-bright);
  font-variation-settings: "opsz" 16, "wght" 540;
}
.peer-sep { color: var(--ink-ghost); margin: 0 6px; }
.peer-text em {
  font-family: var(--italic);
  font-style: italic;
  color: var(--ink);
}
.peer-presence.peer-tap-flash {
  background: rgba(198, 100, 50, 0.15);
}

/* ============================================================
   Modal overlay & card
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(7, 5, 3, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in 0.3s var(--ease-out);
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: linear-gradient(180deg, var(--paper-raised) 0%, rgba(20, 17, 11, 0.9) 100%);
  border: 1px solid var(--ink-ghost);
  width: 100%;
  max-width: 480px;
  padding: 44px 44px 36px;
  position: relative;
  text-align: center;
  animation: fade-up 0.5s var(--ease-out);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-card::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 1px solid var(--ink-ghost);
  pointer-events: none;
  opacity: 0.45;
}

/* gilt corner ornaments */
.modal-card::after {
  content: '';
  position: absolute;
  top: -1px; right: -1px;
  width: 22px; height: 22px;
  border-top: 1px solid var(--gilt);
  border-right: 1px solid var(--gilt);
  opacity: 0.85;
}

.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  font-family: var(--mono);
  font-weight: 300;
  z-index: 2;
  transition: color 0.2s;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--ink); }

.modal-ornament {
  font-size: 28px;
  color: var(--gilt);
  margin-bottom: 4px;
  filter: drop-shadow(0 0 12px rgba(212, 161, 85, 0.3));
}

.modal-title {
  font-family: var(--display);
  font-variation-settings: "opsz" 144, "wght" 380, "SOFT" 80, "WONK" 1;
  font-size: 30px;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 16px;
}

.modal-blurb {
  font-family: var(--italic);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 auto 28px;
  max-width: 380px;
}

.modal-tabs {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 28px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.modal-tab {
  background: transparent;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
  font-size: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: all 0.25s var(--ease);
}
.modal-tab:hover { color: var(--ink-soft); }
.modal-tab.active {
  color: var(--gilt);
  border-bottom-color: var(--gilt);
}
.modal-tab-sep { color: var(--ink-ghost); font-size: 11px; }

.modal-pane[hidden] { display: none; }
.modal-pane { animation: fade-in 0.35s var(--ease); }

.modal-step[hidden] { display: none; }

.modal-micro {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 12px;
  padding-left: 0.42em;
}

.modal-action {
  display: inline-block;
  background: transparent;
  border: 1px solid var(--gilt);
  color: var(--gilt-bright);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: 14px 30px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s var(--ease);
  margin-top: 8px;
}
.modal-action:hover {
  background: rgba(212, 161, 85, 0.12);
  letter-spacing: 0.36em;
  color: var(--ink);
}
.modal-action.ghost {
  border-color: var(--ink-ghost);
  color: var(--ink-soft);
  font-size: 10px;
  padding: 10px 22px;
  margin-top: 14px;
}
.modal-action.ghost:hover {
  border-color: var(--ink-faint);
  color: var(--ink);
  background: transparent;
}

.code-display {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--gilt-bright);
  background: rgba(11, 9, 7, 0.55);
  border: 1px dashed var(--ink-faint);
  padding: 22px 16px;
  margin-bottom: 10px;
  user-select: all;
  text-shadow: 0 0 18px rgba(236, 191, 118, 0.3);
  position: relative;
}
.code-display::before,
.code-display::after {
  content: '\2767';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--gilt);
  opacity: 0.5;
}
.code-display::before { left: 12px; }
.code-display::after { right: 12px; }

.copy-btn {
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 4px 8px;
  margin-bottom: 14px;
  transition: color 0.2s;
}
.copy-btn:hover { color: var(--gilt); }
.copy-btn.copied { color: var(--moss); }

#joinCodeInput {
  display: block;
  width: 100%;
  background: rgba(11, 9, 7, 0.5);
  border: 1px solid var(--ink-ghost);
  color: var(--gilt-bright);
  font-family: var(--mono);
  font-size: 18px;
  text-align: center;
  padding: 16px;
  outline: none;
  margin-bottom: 18px;
  letter-spacing: 0.04em;
  transition: border-color 0.25s, background 0.25s;
}
#joinCodeInput:focus {
  border-color: var(--gilt);
  background: rgba(20, 17, 11, 0.7);
}
#joinCodeInput::placeholder {
  color: var(--ink-faint);
  font-family: var(--italic);
  font-style: italic;
  letter-spacing: 0;
  font-size: 15px;
}

.status-line {
  font-family: var(--italic);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 14px;
  margin: 14px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.status-line.big {
  font-size: 18px;
  color: var(--ink);
  margin-top: 4px;
  margin-bottom: 8px;
}
.status-line.big strong {
  font-family: var(--display);
  font-style: normal;
  color: var(--gilt-bright);
  font-variation-settings: "opsz" 24, "wght" 540, "SOFT" 50;
  letter-spacing: 0.005em;
}
.status-line.err { color: var(--rust); }

.dots-loader {
  display: inline-flex;
  gap: 4px;
}
.dots-loader span {
  width: 4px; height: 4px;
  background: var(--gilt);
  border-radius: 50%;
  animation: dot-fade 1.2s ease-in-out infinite;
}
.dots-loader span:nth-child(2) { animation-delay: 0.2s; }
.dots-loader span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-fade {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.connected-mark {
  font-size: 38px;
  color: var(--gilt);
  margin-bottom: 6px;
  filter: drop-shadow(0 0 22px rgba(236, 191, 118, 0.5));
  animation: connect-pulse 2.4s ease-in-out infinite;
}
@keyframes connect-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.error-mark {
  font-size: 28px;
  color: var(--rust);
  margin-bottom: 6px;
}

.modal-sub {
  font-family: var(--italic);
  font-style: italic;
  color: var(--ink-faint);
  font-size: 13px;
  margin: 4px auto 14px;
  max-width: 320px;
  line-height: 1.5;
}

/* ============================================================
   Toasts
   ============================================================ */

.toast-stack {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  background: rgba(20, 17, 11, 0.94);
  border: 1px solid var(--gilt);
  color: var(--ink);
  padding: 11px 22px;
  font-family: var(--display);
  font-size: 14px;
  font-variation-settings: "opsz" 16, "wght" 420, "SOFT" 50;
  letter-spacing: 0.005em;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  position: relative;
}
.toast::before {
  content: '\10086';
  margin-right: 10px;
  color: var(--gilt);
  font-size: 12px;
}
.toast em {
  font-family: var(--italic);
  font-style: italic;
  color: var(--gilt-bright);
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1100px) {
  .study-hall {
    grid-template-columns: 1fr;
    gap: 50px;
    padding: 40px 36px 32px;
  }
  .ledger { max-width: 540px; width: 100%; margin: 0 auto; }
  .masthead { padding: 22px 36px 18px; }
  .colophon { padding: 14px 36px 20px; }
}

@media (max-width: 640px) {
  .masthead { padding: 18px 22px 14px; flex-wrap: wrap; gap: 12px; }
  .brand { gap: 12px; }
  .brand-name { font-size: 26px; }
  .brand-tag { display: none; }
  .masthead-right { gap: 14px; }
  .session-label { display: none; }
  .session-btn { padding: 9px; }
  .study-hall { padding: 32px 22px 24px; gap: 38px; }
  .colophon {
    padding: 14px 22px 20px;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }
  .controls { flex-wrap: wrap; }
  .ctrl { padding: 12px 16px; flex: 1; justify-content: center; }
  .ledger-card { padding: 22px 22px; }
  .modal-card { padding: 32px 24px 26px; }
  .modal-title { font-size: 24px; }
  .code-display { font-size: 22px; padding: 16px 12px; }
  .toast { font-size: 13px; padding: 9px 16px; }
}

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