/* =============================================================
   Tokeezy — The Arcane Codex
   A dark fantasy tabletop interface. Burnished iron panels,
   brass and verdigris accents, parchment-fed dropdowns and
   gilded corner ornaments throughout. Cinzel display caps,
   EB Garamond body.
   ============================================================= */

/* --------------------------------------------------------------
   Tokens
   -------------------------------------------------------------- */
:root {
  /* surfaces — pushed darker, near-true-black with a faint green warmth */
  --ink-abyss:     #020303;
  --ink-deep:      #060807;
  --ink:           #0a0d0b;
  --ink-raised:    #10140f;
  --ink-input:     #050706;
  --ink-input-2:   #0a0c0b94;

  /* leather / iron borders */
  --leather:       #1f2622;
  --leather-soft:  #161c19;
  --leather-glow:  #2a3530;

  /* metal accents */
  --brass:         #c19a4e;
  --brass-bright:  #e6c98d;
  --brass-deep:    #7a5a26;
  --brass-shadow:  #4a371a;
  --brass-fade:    rgba(193, 154, 78, 0.32);
  --brass-soft:    rgba(193, 154, 78, 0.14);

  /* arcane (verdigris / oxidized copper) */
  --arcane:        #4ec9a5;
  --arcane-bright: #6ee3bc;
  --arcane-deep:   #1f6d59;
  --arcane-glow:   rgba(78, 201, 165, 0.42);
  --arcane-fade:   rgba(78, 201, 165, 0.18);
  --arcane-soft:   rgba(78, 201, 165, 0.08);

  /* warning / ember (banked coals) */
  --ember:         #d96a4a;
  --ember-bright:  #f08a64;
  --ember-bg:      rgba(217, 106, 74, 0.14);
  --ember-glow:    rgba(217, 106, 74, 0.4);

  /* type tones — brighter cream for legibility on near-black surfaces */
  --parchment:     #f5e8cc;
  --vellum:        #e3cfa8;
  --text:          #f3e8cf;
  --text-soft:     #d6caad;
  --text-muted:    #9a8f73;
  --text-faint:    #6e6651;
  --text-ink:      #1a140c;  /* for use on light surfaces */

  /* geometry */
  --r-sm: 3px;
  --r:    6px;
  --r-lg: 10px;

  /* fonts */
  --font-display: "Cinzel", "Trajan Pro", "Cormorant Garamond", serif;
  --font-body:    "EB Garamond", "Iowan Old Style", Georgia, serif;
  --font-mono:    "JetBrains Mono", "Fira Code", monospace;

  /* shadows */
  --shadow-deep:    0 24px 60px -16px rgba(0,0,0,0.75), 0 4px 20px -4px rgba(0,0,0,0.6);
  --shadow-card:    0 12px 36px -10px rgba(0,0,0,0.7), 0 2px 0 rgba(255,255,255,0.02) inset;
  --shadow-inset:   inset 0 2px 6px rgba(0,0,0,0.55), inset 0 -1px 0 rgba(255,255,255,0.03);
  --shadow-stud:    0 0 0 1px rgba(193,154,78,0.35), 0 0 14px -2px rgba(193,154,78,0.25);
  --shadow-glow-brass: 0 0 0 1px var(--brass-fade), 0 0 24px -6px rgba(230,201,141,0.45);
  --shadow-glow-arcane: 0 0 0 1px var(--arcane-fade), 0 0 18px -4px var(--arcane-glow);
}

/* --------------------------------------------------------------
   Reset & base
   -------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--ink-deep);
  min-height: 100vh;
  /* Layered atmosphere: vignette + faint noise + base ink.
     The noise is a tiny inline SVG turbulence tile.            */
  background-image:
    radial-gradient(ellipse 120% 70% at 50% -10%, rgba(193,154,78,0.07) 0%, transparent 55%),
    radial-gradient(ellipse 80% 60% at 50% 110%, rgba(78,201,165,0.04) 0%, transparent 60%),
    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' seed='3'/><feColorMatrix values='0 0 0 0 0.08  0 0 0 0 0.1  0 0 0 0 0.09  0 0 0 0.35 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    linear-gradient(180deg, var(--ink-deep) 0%, var(--ink-abyss) 100%);
  background-attachment: fixed, fixed, fixed, fixed;
  background-size: auto, auto, 180px 180px, auto;
}

/* --------------------------------------------------------------
   Typography
   -------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--text);
  text-transform: uppercase;
}

h1 { font-size: 1.95rem; letter-spacing: 0.12em; }
h2 { font-size: 1.25rem; letter-spacing: 0.18em; }
h3 { font-size: 1.05rem; letter-spacing: 0.22em; }

p { margin: 0 0 0.75em; }

strong { color: var(--text); font-weight: 600; }

a {
  color: var(--brass-bright);
  text-decoration: none;
  border-bottom: 1px solid var(--brass-fade);
  transition: color 0.2s ease, border-color 0.2s ease;
}
a:hover { color: var(--parchment); border-bottom-color: var(--brass); }

/* --------------------------------------------------------------
   Decorative primitives
   -------------------------------------------------------------- */

/* A reusable gilded corner-ornament set. Apply to any positioned
   container that should look "framed". The ornaments are pure CSS:
   a pair of pseudo-elements each painted with two brass border-edges
   on opposing sides, plus a small brass dot at the inner vertex.   */
.ornate {
  position: relative;
}
.ornate::before,
.ornate::after,
.ornate > .ornate-corner {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  pointer-events: none;
  z-index: 2;
}
.ornate::before {
  top: 6px; left: 6px;
  border-top: 1px solid var(--brass);
  border-left: 1px solid var(--brass);
  box-shadow: -1px -1px 0 rgba(0,0,0,0.35);
}
.ornate::after {
  bottom: 6px; right: 6px;
  border-bottom: 1px solid var(--brass);
  border-right: 1px solid var(--brass);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.35);
}
.ornate-corner.tr {
  top: 6px; right: 6px;
  border-top: 1px solid var(--brass);
  border-right: 1px solid var(--brass);
  box-shadow: 1px -1px 0 rgba(0,0,0,0.35);
}
.ornate-corner.bl {
  bottom: 6px; left: 6px;
  border-bottom: 1px solid var(--brass);
  border-left: 1px solid var(--brass);
  box-shadow: -1px 1px 0 rgba(0,0,0,0.35);
}

/* Engraved horizontal divider with a centered diamond glyph. */
.flourish {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0.85rem 0;
  color: var(--brass);
  font-size: 0.65rem;
}
.flourish::before,
.flourish::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--brass-fade) 30%, var(--brass) 50%, var(--brass-fade) 70%, transparent 100%);
}
.flourish-glyph {
  font-family: var(--font-display);
  letter-spacing: 0.4em;
  text-transform: uppercase;
  font-size: 0.65rem;
  color: var(--brass-bright);
}

/* --------------------------------------------------------------
   Form controls — engraved iron
   -------------------------------------------------------------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
textarea,
select {
  width: 100%;
  padding: 0.75rem 0.95rem;
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--ink-input);
  border: 1px solid var(--leather);
  border-radius: var(--r);
  box-shadow: var(--shadow-inset);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: var(--shadow-inset),
              0 0 0 1px var(--brass-fade),
              0 0 12px -2px rgba(230,201,141,0.45);
  background: var(--ink-input-2);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --------------------------------------------------------------
   Buttons — brass plates & ghost runes
   -------------------------------------------------------------- */
button {
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: var(--r);
  transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.7rem 1.3rem;
  min-height: 44px;
  position: relative;
}

/* Primary — burnished brass plate with rivets at the corners */
.btn-primary {
  color: #1a1207;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0) 35%, rgba(0,0,0,0.18) 100%),
    linear-gradient(180deg, var(--brass-bright) 0%, var(--brass) 55%, var(--brass-deep) 100%);
  border: 1px solid var(--brass-deep);
  box-shadow:
    inset 0 1px 0 rgba(255,236,196,0.6),
    inset 0 -1px 0 rgba(0,0,0,0.3),
    0 1px 0 rgba(0,0,0,0.45),
    0 8px 18px -10px rgba(0,0,0,0.6);
  text-shadow: 0 1px 0 rgba(255,255,255,0.18);
}
.btn-primary::before,
.btn-primary::after {
  content: "";
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 4px; height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff4d2 0%, var(--brass-deep) 70%, var(--brass-shadow) 100%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
  opacity: 0.85;
}
.btn-primary::before { left: 8px; }
.btn-primary::after  { right: 8px; }
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow:
    inset 0 1px 0 rgba(255,236,196,0.75),
    inset 0 -1px 0 rgba(0,0,0,0.3),
    0 1px 0 rgba(0,0,0,0.45),
    0 0 24px -4px rgba(230,201,141,0.55),
    0 10px 22px -10px rgba(0,0,0,0.7);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,0.3),
    0 0 0 1px var(--brass-deep);
}

/* Ghost — text rune with a candleflame underline on hover */
.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid transparent;
  padding-left: 1rem;
  padding-right: 1rem;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--brass-bright);
  background: rgba(193,154,78,0.06);
  border-color: var(--brass-fade);
  box-shadow: 0 0 16px -6px rgba(230,201,141,0.5);
}
.btn-ghost:active:not(:disabled) {
  transform: translateY(1px);
}

/* --------------------------------------------------------------
   Status messages
   -------------------------------------------------------------- */
.error-msg {
  font-family: var(--font-body);
  font-size: 1.025rem;
  font-style: italic;
  color: var(--ember-bright);
  background: var(--ember-bg);
  border: 1px solid rgba(217,106,74,0.4);
  border-left: 3px solid var(--ember);
  padding: 0.55rem 0.85rem;
  border-radius: var(--r);
  margin-top: 0.5rem;
  text-transform: none;
  letter-spacing: 0;
}

.success-msg {
  font-family: var(--font-body);
  font-size: 1.025rem;
  color: var(--arcane-bright);
  padding: 0.55rem 0.85rem;
  border-radius: var(--r);
  margin-top: 0.5rem;
}

/* --------------------------------------------------------------
   Form groups
   -------------------------------------------------------------- */
.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--brass);
  margin-bottom: 0.4rem;
}

.form-group input { margin: 0; }

.form-hint {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 0.3rem;
  display: block;
}

/* --------------------------------------------------------------
   Auth page — Candlelit Codex
   -------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

/* Candle vignette + a faint sigil mark watermark behind the card */
.auth-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 38%, rgba(230,201,141,0.16) 0%, transparent 38%),
    radial-gradient(circle at 50% 38%, rgba(78,201,165,0.04) 0%, transparent 60%);
  pointer-events: none;
}
.auth-page::after {
  /* faint mage-circle behind the card */
  content: "";
  position: absolute;
  width: 520px; height: 520px;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border: 1px dashed rgba(193,154,78,0.12);
  border-radius: 50%;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 24px transparent,
    inset 0 0 0 25px rgba(193,154,78,0.06),
    inset 0 0 0 60px transparent,
    inset 0 0 0 61px rgba(193,154,78,0.04);
  animation: codex-circle 90s linear infinite;
}
@keyframes codex-circle {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background:
    linear-gradient(180deg, rgba(193,154,78,0.04) 0%, transparent 30%),
    linear-gradient(180deg, var(--ink-raised) 0%, var(--ink) 100%);
  border: 1px solid var(--leather);
  border-radius: var(--r-lg);
  padding: 2.4rem 2rem 2rem;
  box-shadow: var(--shadow-deep);
  position: relative;
  z-index: 1;
  animation: card-rise 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes card-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Gilded corner brackets on the auth card */
.auth-card::before,
.auth-card::after {
  content: "";
  position: absolute;
  width: 28px;
  height: 28px;
  pointer-events: none;
}
.auth-card::before {
  top: 10px; left: 10px;
  border-top: 1px solid var(--brass);
  border-left: 1px solid var(--brass);
  background:
    radial-gradient(circle at 0 0, var(--brass) 0 2px, transparent 3px) no-repeat;
}
.auth-card::after {
  bottom: 10px; right: 10px;
  border-bottom: 1px solid var(--brass);
  border-right: 1px solid var(--brass);
  background:
    radial-gradient(circle at 100% 100%, var(--brass) 0 2px, transparent 3px) no-repeat;
}

.auth-title {
  text-align: center;
  font-family: var(--font-display);
  font-size: 2.2rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--brass-bright);
  text-shadow: 0 0 22px rgba(230,201,141,0.25), 0 1px 0 rgba(0,0,0,0.6);
  margin: 0 0 0.35rem;
  /* leading kerning fix because of letter-spacing */
  text-indent: 0.35em;
}

.auth-title:has(.auth-logo) {
  text-indent: 0;
  margin: 0.2rem 0 0.55rem;
  line-height: 1;
}

.auth-logo {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 0 auto;
  filter: drop-shadow(0 0 18px rgba(230,201,141,0.22));
}

.auth-eyebrow {
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}
.auth-eyebrow-glyph {
  font-family: var(--font-display);
  font-size: 0.55rem;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--brass);
  opacity: 0.85;
  padding: 0 0.6rem;
  position: relative;
}

.auth-subtitle {
  text-align: center;
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0 0 1.75rem;
}

.auth-form .form-group:last-of-type { margin-bottom: 0; }
.auth-form .btn-primary { width: 100%; }
.auth-form .btn-ghost   { width: 100%; margin-top: 0.5rem; }

/* --------------------------------------------------------------
   App shell — three‑panel codex layout
   -------------------------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.4rem;
  background:
    linear-gradient(180deg, rgba(193,154,78,0.08) 0%, rgba(193,154,78,0) 60%),
    linear-gradient(180deg, var(--ink-raised) 0%, var(--ink) 100%);
  border-bottom: 1px solid var(--leather);
  position: relative;
  flex-shrink: 0;
}
/* hairline brass rule under the header */
.app-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--brass-fade) 12%,
    var(--brass) 50%,
    var(--brass-fade) 88%,
    transparent 100%);
  opacity: 0.6;
}

.app-logo-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.app-logo {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--brass-bright);
  text-shadow: 0 0 16px rgba(230,201,141,0.25), 0 1px 0 rgba(0,0,0,0.5);
  text-indent: 0.32em;
  margin: 0;
}

.app-logo-die {
  height: 48px;
  width: auto;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 0 8px rgba(230,201,141,0.35));
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-header-actions .btn {
  min-height: 38px;
  padding: 0.5rem 1.05rem;
  font-size: 0.85rem;
}

.app-main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.app-panel {
  border-right: 1px solid var(--leather);
  overflow: auto;
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.012) 0%, transparent 25%, transparent 75%, rgba(0,0,0,0.18) 100%),
    var(--ink);
}
.app-panel:last-of-type {
  border-right: none;
  border-left: 1px solid var(--leather);
}

.app-panel-left {
  width: 420px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(193,154,78,0.03) 0%, transparent 40%),
    var(--ink-raised);
}

.app-panel-center {
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(78,201,165,0.04) 0%, transparent 60%),
    var(--ink);
}

.app-panel-right {
  width: 270px;
  flex-shrink: 0;
  background: var(--ink-raised);
}

/* Custom scrollbars — slim and gilded */
.app-panel::-webkit-scrollbar,
.appearance-sections::-webkit-scrollbar,
.timeline-list-wrap::-webkit-scrollbar,
.admin-user-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.app-panel::-webkit-scrollbar-track,
.appearance-sections::-webkit-scrollbar-track,
.timeline-list-wrap::-webkit-scrollbar-track,
.admin-user-list::-webkit-scrollbar-track {
  background: var(--ink-deep);
}
.app-panel::-webkit-scrollbar-thumb,
.appearance-sections::-webkit-scrollbar-thumb,
.timeline-list-wrap::-webkit-scrollbar-thumb,
.admin-user-list::-webkit-scrollbar-thumb {
  background: var(--leather);
  border-radius: 4px;
}
.app-panel::-webkit-scrollbar-thumb:hover,
.appearance-sections::-webkit-scrollbar-thumb:hover,
.timeline-list-wrap::-webkit-scrollbar-thumb:hover,
.admin-user-list::-webkit-scrollbar-thumb:hover {
  background: var(--brass-deep);
}

.panel-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 2rem;
  color: var(--text-muted);
  font-style: italic;
}

.panel-placeholder-below {
  min-height: 200px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-placeholder { min-height: 400px; }

/* Locked-panel state when no character selected */
.panel-no-character {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* --------------------------------------------------------------
   Characters — selector & dropdown (the codex index)
   -------------------------------------------------------------- */
.characters-container {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--leather);
  background: linear-gradient(180deg, rgba(0,0,0,0.18) 0%, transparent 100%);
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.characters-dropdown-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.characters-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.65rem 1rem;
  font-family: var(--font-display);
  font-size: 0.98rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(193,154,78,0.06) 0%, transparent 60%),
    var(--ink-input);
  border: 1px solid var(--leather);
  border-radius: var(--r);
  box-shadow: var(--shadow-inset);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.characters-trigger:hover,
.characters-trigger[aria-expanded="true"] {
  border-color: var(--brass);
  color: var(--brass-bright);
  box-shadow: var(--shadow-inset),
              0 0 0 1px var(--brass-fade),
              0 0 14px -4px rgba(230,201,141,0.4);
}

.characters-trigger-label {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.characters-trigger-caret {
  flex-shrink: 0;
  margin-left: 0.5rem;
  color: var(--brass);
  font-size: 0.7rem;
  transition: transform 0.2s ease;
}
.characters-trigger[aria-expanded="true"] .characters-trigger-caret {
  transform: rotate(180deg);
}

.characters-add-btn {
  flex-shrink: 0;
  width: 42px;
  min-height: 0;
  height: auto;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1;
  color: #1a1207;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 40%, rgba(0,0,0,0.2) 100%),
    linear-gradient(180deg, var(--brass-bright), var(--brass) 55%, var(--brass-deep));
  border: 1px solid var(--brass-deep);
  border-radius: var(--r);
  cursor: pointer;
  letter-spacing: 0;
  text-transform: none;
  text-shadow: 0 1px 0 rgba(255,255,255,0.2);
  box-shadow:
    inset 0 1px 0 rgba(255,236,196,0.55),
    inset 0 -1px 0 rgba(0,0,0,0.25),
    0 1px 0 rgba(0,0,0,0.4);
}
.characters-add-btn:hover:not(:disabled) {
  filter: brightness(1.1);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 40%, rgba(0,0,0,0.2) 100%),
    linear-gradient(180deg, var(--brass-bright), var(--brass) 55%, var(--brass-deep));
  border-color: var(--brass-deep);
  color: #1a1207;
  box-shadow:
    inset 0 1px 0 rgba(255,236,196,0.7),
    0 0 18px -3px rgba(230,201,141,0.55);
}

/* Dropdown — appears as a hanging brass-edged scroll */
.characters-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background:
    linear-gradient(180deg, rgba(193,154,78,0.04) 0%, transparent 30%),
    var(--ink-raised);
  border: 1px solid var(--leather);
  border-top: 1px solid var(--brass-fade);
  border-radius: var(--r);
  box-shadow: var(--shadow-deep);
  z-index: 50;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: dropdown-in 0.18s ease-out;
}
.characters-dropdown[hidden] { display: none; }
@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.characters-list {
  overflow-y: auto;
  max-height: 280px;
}

.characters-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.95rem;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 1.075rem;
  color: var(--text-soft);
  border-bottom: 1px solid rgba(44,53,47,0.5);
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
}
.characters-item:last-child { border-bottom: none; }
.characters-item::before {
  content: "❧";
  font-size: 0.75rem;
  color: var(--brass-fade);
  margin-right: 0.15rem;
  transition: color 0.15s ease, transform 0.2s ease;
}
.characters-item:hover {
  background: rgba(193,154,78,0.06);
  color: var(--brass-bright);
}
.characters-item:hover::before { color: var(--brass); }

.characters-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.characters-item-menu {
  flex-shrink: 0;
  padding: 0.15rem 0.4rem;
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
  opacity: 0.7;
  background: none;
  border: none;
  min-height: 0;
}
.characters-item-menu:hover:not(:disabled) {
  opacity: 1;
  color: var(--brass-bright);
  background: none;
  border-color: transparent;
  box-shadow: none;
}

/* Context menu — parchment scroll */
.characters-context-menu {
  position: fixed;
  background:
    radial-gradient(ellipse 100% 100% at 0 0, rgba(122,90,38,0.08) 0%, transparent 60%),
    linear-gradient(180deg, var(--parchment) 0%, var(--vellum) 100%);
  color: var(--text-ink);
  border: 1px solid var(--brass-deep);
  border-radius: var(--r);
  box-shadow: var(--shadow-deep), 0 0 0 1px rgba(0,0,0,0.4);
  padding: 0.3rem;
  z-index: 100;
  min-width: 150px;
  animation: dropdown-in 0.15s ease-out;
}

.characters-context-item {
  display: block;
  width: 100%;
  padding: 0.55rem 0.85rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
  text-align: left;
  background: none;
  color: var(--text-ink);
  cursor: pointer;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}
.characters-context-item:hover {
  background: rgba(122,90,38,0.18);
  color: #2a1f12;
  border-color: rgba(122,90,38,0.3);
}
.characters-context-danger { color: #8a2a1a; }
.characters-context-danger:hover {
  background: rgba(217,106,74,0.2);
  border-color: rgba(217,106,74,0.5);
  color: #6e1e10;
}

/* --------------------------------------------------------------
   Create-character dialog
   -------------------------------------------------------------- */
.character-create-dialog-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 60% at 50% 50%, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0.75) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 150;
  backdrop-filter: blur(2px);
  animation: overlay-in 0.2s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.character-create-dialog-overlay[hidden] { display: none !important; }

.character-create-dialog {
  background:
    linear-gradient(180deg, rgba(193,154,78,0.05) 0%, transparent 30%),
    linear-gradient(180deg, var(--ink-raised) 0%, var(--ink) 100%);
  border: 1px solid var(--leather);
  border-radius: var(--r-lg);
  padding: 1.5rem 1.4rem 1.25rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: var(--shadow-deep);
  position: relative;
  animation: card-rise 0.3s ease both;
}
.character-create-dialog::before,
.character-create-dialog::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  pointer-events: none;
}
.character-create-dialog::before {
  top: 8px; left: 8px;
  border-top: 1px solid var(--brass);
  border-left: 1px solid var(--brass);
}
.character-create-dialog::after {
  bottom: 8px; right: 8px;
  border-bottom: 1px solid var(--brass);
  border-right: 1px solid var(--brass);
}
.character-create-dialog::before,
.character-create-dialog::after { z-index: 1; }

.character-create-dialog input { margin: 0; }

.character-create-dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}
.character-create-dialog-actions .btn {
  font-size: 0.72rem;
  padding: 0.5rem 1rem;
  min-height: 38px;
}

/* --------------------------------------------------------------
   Appearance form (left panel) — the character sheet
   -------------------------------------------------------------- */
.appearance-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

.appearance-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  font-size: 1rem;
}
.appearance-empty[hidden] { display: none; }
.appearance-empty p {
  margin: 0;
  position: relative;
  padding: 0 1.5rem;
}
.appearance-empty p::before,
.appearance-empty p::after {
  content: "❦";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--brass-fade);
  font-size: 0.85rem;
}
.appearance-empty p::before { left: 0; }
.appearance-empty p::after  { right: 0; }

.appearance-form-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.appearance-form-body[hidden] { display: none; }

/* Tab bar — engraved chapter dividers */
.appearance-tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0.4rem 0.5rem 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.25) 0%, transparent 100%),
    var(--ink-raised);
  border-bottom: 1px solid var(--leather);
  flex-shrink: 0;
  position: relative;
}
.appearance-tabs::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--brass-fade) 40%, var(--brass-fade) 60%, transparent 100%);
  opacity: 0.45;
}

.appearance-tab {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0;
  background: transparent;
  color: var(--text-faint);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  cursor: pointer;
  position: relative;
  min-height: 0;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.95rem;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.appearance-tab + .appearance-tab::before {
  content: "";
  position: absolute;
  left: 0;
  top: 25%; bottom: 25%;
  width: 1px;
  background: linear-gradient(180deg, transparent 0%, var(--leather) 50%, transparent 100%);
}

.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: "liga";
  -webkit-font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
}

.appearance-tab-icon {
  font-size: 26px;
  line-height: 1;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  display: block;
  transition: filter 0.2s ease;
}

.appearance-tab--active .appearance-tab-icon {
  font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24;
  filter: drop-shadow(0 0 8px rgba(230,201,141,0.55));
}

.appearance-tab:hover {
  color: var(--text-soft);
  background: rgba(193,154,78,0.05);
}

.appearance-tab--active {
  color: var(--brass-bright);
  border-bottom-color: var(--brass);
  background: linear-gradient(180deg, rgba(193,154,78,0.08) 0%, transparent 100%);
}

.appearance-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px var(--brass-fade) inset;
}

.appearance-sections {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.appearance-section-panel {
  padding: 1rem 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  animation: section-in 0.25s ease both;
}
.appearance-section-panel[hidden] { display: none; }
@keyframes section-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.appearance-section-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--brass-bright);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--leather);
  position: relative;
  text-shadow: 0 1px 0 rgba(0,0,0,0.4);
}
.appearance-section-title::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--brass) 0%, transparent 65%);
  opacity: 0.7;
}

.appearance-section-description {
  margin: 0;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.025rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.appearance-section-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.appearance-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.appearance-field[hidden] { display: none; }

.appearance-field-label {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brass);
}

.appearance-required {
  color: var(--ember);
  margin-left: 0.1em;
  text-shadow: 0 0 8px rgba(217,106,74,0.4);
}

.appearance-input {
  font-family: var(--font-body);
  font-size: 1.025rem;
  padding: 0.6rem 0.8rem;
}

.appearance-textarea {
  resize: vertical;
  min-height: 280px;
  font-family: var(--font-body);
  line-height: 1.55;
}

.appearance-select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--brass) 50%),
    linear-gradient(135deg, var(--brass) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 50%,
    calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.appearance-select.appearance-select-empty {
  color: var(--text-faint);
  font-style: italic;
}

.appearance-select option {
  color: var(--text);
  background: var(--ink-input);
}

.appearance-multiselect {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}

.appearance-multiselect-hint {
  font-family: var(--font-body);
  font-size: 1.025rem;
  font-style: italic;
  color: var(--text-faint);
  padding: 0.25rem 0.125rem;
}
.appearance-multiselect-hint[hidden] { display: none; }

.appearance-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.7rem;
  font-family: var(--font-body);
  font-size: 0.975rem;
  background: var(--ink-input);
  border: 1px solid var(--leather);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.appearance-chip input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: var(--brass);
  margin: 0;
}
.appearance-chip:hover {
  color: var(--text-soft);
  border-color: var(--brass-fade);
}
.appearance-chip:has(input:checked) {
  background: rgba(193,154,78,0.14);
  color: var(--brass-bright);
  border-color: var(--brass);
  box-shadow: 0 0 12px -4px rgba(230,201,141,0.5);
}

.appearance-color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.appearance-swatch {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--leather);
  background: var(--ink-input);
  border-radius: var(--r);
  cursor: pointer;
  flex-shrink: 0;
}

.appearance-color-text { flex: 1; }

.appearance-slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.appearance-slider {
  flex: 1;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--ink-input);
  border-radius: 999px;
  outline: none;
  padding: 0;
  border: 1px solid var(--leather);
  box-shadow: var(--shadow-inset);
}

.appearance-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--brass-bright) 0%, var(--brass) 60%, var(--brass-deep) 100%);
  border: 1px solid var(--brass-deep);
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3), 0 0 10px -2px rgba(230,201,141,0.5);
}
.appearance-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--brass-bright) 0%, var(--brass) 60%, var(--brass-deep) 100%);
  border: 1px solid var(--brass-deep);
  cursor: pointer;
}

.appearance-slider-value {
  min-width: 1.8rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--brass);
}

.appearance-toggle {
  display: inline-flex;
  align-items: center;
  width: 40px;
  height: 22px;
  position: relative;
  cursor: pointer;
  background: var(--ink-input);
  border: 1px solid var(--leather);
  border-radius: 999px;
  box-shadow: var(--shadow-inset);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
  flex-shrink: 0;
}
.appearance-toggle input {
  position: absolute;
  width: 0; height: 0;
  opacity: 0;
}
.appearance-toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: radial-gradient(circle at 30% 30%, #4a4a44 0%, #2a2a26 100%);
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.appearance-toggle:has(input:checked) {
  background: rgba(193,154,78,0.18);
  border-color: var(--brass);
  box-shadow: var(--shadow-inset), 0 0 12px -3px rgba(230,201,141,0.5);
}
.appearance-toggle:has(input:checked) .appearance-toggle-knob {
  transform: translateX(18px);
  background: radial-gradient(circle at 30% 30%, var(--brass-bright) 0%, var(--brass) 60%, var(--brass-deep) 100%);
  box-shadow: 0 0 8px -1px rgba(230,201,141,0.7);
}

/* Action bar — sticky footer with primary brass plate */
.appearance-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--leather);
  background:
    linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.25) 100%),
    var(--ink-raised);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
}
.appearance-actions::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--brass-fade) 30%, var(--brass) 50%, var(--brass-fade) 70%, transparent 100%);
  opacity: 0.55;
}

.appearance-token-btn {
  grid-column: 1 / -1;
  min-height: 50px;
  font-size: 1.05rem;
  letter-spacing: 0.24em;
}

/* During generation the primary button gets a slow arcane pulse */
.appearance-token-btn[data-loading="true"] {
  animation: token-pulse 1.6s ease-in-out infinite;
}
@keyframes token-pulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,236,196,0.6), 0 0 0 0 rgba(78,201,165,0.0); }
  50%      { box-shadow: inset 0 1px 0 rgba(255,236,196,0.6), 0 0 20px -2px rgba(78,201,165,0.6); }
}

.appearance-actions .btn {
  font-size: 0.82rem;
  padding: 0.5rem 0.8rem;
  min-height: 40px;
}

.appearance-error {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.025rem;
  color: var(--ember-bright);
  background: var(--ember-bg);
  border: 1px solid rgba(217,106,74,0.4);
  border-left: 3px solid var(--ember);
  padding: 0.55rem 0.85rem;
  margin: 0 1.1rem 0.5rem;
  border-radius: var(--r);
}
.appearance-error[hidden] { display: none; }

/* --------------------------------------------------------------
   Token preview — the Scrying Mirror (center panel)
   -------------------------------------------------------------- */
.viewer-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--leather);
  background: linear-gradient(180deg, rgba(0,0,0,0.18) 0%, transparent 100%);
  position: relative;
}
.viewer-header::after {
  content: "";
  position: absolute;
  left: 1.25rem; right: 1.25rem; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--brass-fade) 50%, transparent 100%);
}

.viewer-header-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--brass);
}

.viewer-download {
  padding: 0.5rem 1.1rem;
  font-size: 0.82rem;
  min-height: 40px;
  letter-spacing: 0.16em;
}

/* The scrying mirror: a deep frame with brass corner studs */
.viewer-image-area {
  flex: 1;
  min-height: 240px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 1.25rem;
  background:
    radial-gradient(ellipse 70% 60% at 50% 50%, rgba(0,0,0,0.0) 0%, rgba(0,0,0,0.4) 100%),
    var(--ink-deep);
  border: 1px solid var(--leather);
  border-radius: var(--r-lg);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.5),
    inset 0 0 40px rgba(0,0,0,0.4),
    0 0 0 1px rgba(193,154,78,0.06),
    0 12px 30px -10px rgba(0,0,0,0.7);
  margin: 1.1rem 1.25rem 1.25rem;
  position: relative;
  overflow: hidden;
}
/* brass studs at the four corners of the scrying mirror */
.viewer-image-area::before,
.viewer-image-area::after,
.viewer-image-area > .viewer-stud {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--brass-bright) 0%, var(--brass) 50%, var(--brass-deep) 100%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 6px rgba(230,201,141,0.4);
  z-index: 3;
}
.viewer-image-area::before { top: 8px;    left: 8px; }
.viewer-image-area::after  { top: 8px;    right: 8px; }
/* The remaining two studs are added in HTML; if absent, the top two carry the framing */

.viewer-image-container {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.viewer-image-container[hidden] { display: none; }

.viewer-image {
  width: 100%;
  max-height: calc(100vh - 200px);
  min-height: 200px;
  object-fit: contain;
  display: block;
  cursor: zoom-in;
  border-radius: var(--r-sm);
  /* faint inner glow on the token itself */
  box-shadow: 0 0 30px -10px rgba(0,0,0,0.8), 0 0 60px -20px rgba(193,154,78,0.18);
}

@keyframes viewer-image-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 0.85; }
}
.viewer-image--generating {
  animation: viewer-image-pulse 1.8s ease-in-out infinite;
  pointer-events: none;
  cursor: default;
}

.viewer-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.05rem;
  padding: 2rem;
}
.viewer-empty[hidden] { display: none; }
.viewer-empty p { margin: 0; max-width: 30ch; }
.viewer-empty strong {
  font-family: var(--font-display);
  font-style: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.85em;
  color: var(--brass-bright);
}

/* Arcane sigil while generating — concentric circles, runic dashes,
   slowly rotating, with a glowing inner ember.                       */
.viewer-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-style: italic;
}
.viewer-loading[hidden] { display: none; }
.viewer-loading p {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
}

.viewer-loading-spinner {
  width: 84px;
  height: 84px;
  position: relative;
}
.viewer-loading-spinner::before,
.viewer-loading-spinner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px dashed var(--brass);
  opacity: 0.7;
  animation: sigil-rotate 6s linear infinite;
}
.viewer-loading-spinner::after {
  inset: 14px;
  border: 1px solid var(--arcane);
  border-top-color: transparent;
  border-bottom-color: transparent;
  opacity: 0.9;
  animation: sigil-rotate-rev 3s linear infinite;
  box-shadow: 0 0 24px -2px var(--arcane-glow), inset 0 0 16px -4px var(--arcane-glow);
}
/* center ember */
.viewer-loading-spinner > span {
  position: absolute;
  left: 50%; top: 50%;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--arcane-bright) 0%, var(--arcane) 50%, transparent 80%);
  filter: blur(0.5px);
  animation: ember-flicker 1.4s ease-in-out infinite;
}
@keyframes sigil-rotate     { to { transform: rotate(360deg); } }
@keyframes sigil-rotate-rev { to { transform: rotate(-360deg); } }
@keyframes ember-flicker {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.2); }
}

.viewer-error-wrap {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.025rem;
  color: var(--ember-bright);
  background: var(--ember-bg);
  border: 1px solid rgba(217,106,74,0.4);
  border-left: 3px solid var(--ember);
  padding: 0.55rem 0.85rem;
  border-radius: var(--r);
  margin: 0 1.25rem 1.25rem;
  flex-shrink: 0;
}
.viewer-error-wrap[hidden] { display: none; }
.viewer-error-msg { flex: 1; }
.viewer-error-dismiss {
  flex-shrink: 0;
  padding: 0 0.25rem;
  font-size: 1.25rem;
  line-height: 1;
  background: none;
  color: inherit;
  opacity: 0.8;
  cursor: pointer;
  border: none;
  letter-spacing: 0;
  text-transform: none;
  font-family: var(--font-body);
}
.viewer-error-dismiss:hover { opacity: 1; }

@keyframes upload-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------
   Token history (right panel) — the Coin Tray
   -------------------------------------------------------------- */
.timeline-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 1rem;
}

.timeline-header {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 1rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--leather);
  flex-shrink: 0;
  position: relative;
}
.timeline-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--brass) 0%, transparent 60%);
  opacity: 0.7;
}

.timeline-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-style: italic;
  text-align: center;
  padding: 1.5rem;
}
.timeline-empty[hidden] { display: none; }

.timeline-list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* pad-right so scrollbar doesn't crowd entries */
  padding-right: 2px;
}
.timeline-list-wrap[hidden] { display: none; }

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.timeline-sentinel {
  height: 1px;
  width: 100%;
  flex-shrink: 0;
}

.timeline-entry {
  background: var(--ink-input);
  border: 1px solid var(--leather);
  border-radius: var(--r);
  overflow: hidden;
  position: relative;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.timeline-entry:hover {
  border-color: var(--brass-fade);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px -8px rgba(0,0,0,0.7), 0 0 14px -4px rgba(230,201,141,0.2);
}
.timeline-entry-selected {
  border-color: var(--brass);
  box-shadow: 0 0 0 1px var(--brass-fade), 0 0 18px -4px rgba(230,201,141,0.5);
}

.timeline-thumb {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0;
  background: var(--ink-deep);
  border: none;
  border-radius: 0;
  cursor: pointer;
  line-height: 0;
  min-height: 0;
}

.timeline-thumb img {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  filter: brightness(0.96) contrast(1.04);
  transition: filter 0.18s ease;
}
.timeline-entry:hover .timeline-thumb img {
  filter: brightness(1.04) contrast(1.06);
}

.timeline-entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--leather);
  background: linear-gradient(180deg, var(--ink-raised) 0%, var(--ink) 100%);
}

.timeline-entry-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: -0.01em;
  color: var(--brass);
}

.timeline-entry-delete {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14,20,17,0.85);
  border: 1px solid rgba(217,106,74,0.45);
  border-radius: var(--r-sm);
  color: var(--ember);
  cursor: pointer;
  opacity: 0;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.8rem;
  min-height: 0;
  transition: opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  z-index: 2;
}
.timeline-entry:hover .timeline-entry-delete { opacity: 1; }
.timeline-entry-delete:hover {
  background: rgba(217,106,74,0.25);
  border-color: var(--ember);
  color: var(--ember-bright);
  box-shadow: 0 0 10px -2px var(--ember-glow);
}
.timeline-entry-delete:focus-visible {
  outline: none;
  opacity: 1;
  box-shadow: 0 0 0 1px var(--ember-bright);
}

/* --------------------------------------------------------------
   Admin modal — Master of Adventurers
   -------------------------------------------------------------- */
.admin-overlay[hidden] { display: none !important; }
.admin-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 60% at 50% 50%, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0.78) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
  backdrop-filter: blur(3px);
  animation: overlay-in 0.25s ease;
}

.admin-modal {
  background:
    linear-gradient(180deg, rgba(193,154,78,0.04) 0%, transparent 30%),
    linear-gradient(180deg, var(--ink-raised) 0%, var(--ink) 100%);
  border: 1px solid var(--leather);
  border-radius: var(--r-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-deep);
  display: flex;
  flex-direction: column;
  position: relative;
  animation: card-rise 0.32s ease both;
}
.admin-modal::before,
.admin-modal::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  pointer-events: none;
}
.admin-modal::before {
  top: 10px; left: 10px;
  border-top: 1px solid var(--brass);
  border-left: 1px solid var(--brass);
}
.admin-modal::after {
  bottom: 10px; right: 10px;
  border-bottom: 1px solid var(--brass);
  border-right: 1px solid var(--brass);
}

.admin-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem 0.9rem;
  border-bottom: 1px solid var(--leather);
  position: relative;
}
.admin-modal-header::after {
  content: "";
  position: absolute;
  left: 1.4rem; right: 1.4rem; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--brass) 0%, transparent 70%);
  opacity: 0.6;
}

.admin-modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--brass-bright);
}

.admin-modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 1.5rem;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--r);
  padding: 0;
  min-height: 0;
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.admin-modal-close:hover {
  color: var(--brass-bright);
  background: rgba(193,154,78,0.06);
  border-color: var(--brass-fade);
}

.admin-modal-body {
  padding: 1.4rem 1.4rem 1rem;
}

.admin-form-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.admin-form-row input {
  flex: 1;
  min-width: 0;
  margin: 0;
}
.admin-form-row .btn { flex-shrink: 0; }

.admin-helper {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.025rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
  line-height: 1.5;
}
.admin-helper:last-of-type { margin-bottom: 0; }

.admin-modal-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--leather);
  display: flex;
  justify-content: flex-end;
  position: relative;
}

.admin-user-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--leather);
  border-radius: var(--r);
  padding: 0.4rem;
  background: var(--ink-input);
  box-shadow: var(--shadow-inset);
}

.admin-user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.admin-user-row:hover {
  background: rgba(193,154,78,0.05);
  border-color: var(--brass-fade);
}

.admin-user-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.admin-user-info strong {
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.95rem;
  color: var(--text);
}

.admin-user-meta {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.admin-user-actions { flex-shrink: 0; }
.admin-user-actions .btn {
  min-height: 34px;
  padding: 0.35rem 0.95rem;
  font-size: 0.8rem;
}

/* --------------------------------------------------------------
   Toasts — gilded ribbons
   -------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.8rem 1.6rem;
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  border-radius: var(--r);
  box-shadow: var(--shadow-deep);
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.3s ease, transform 0.3s ease;
  border: 1px solid var(--brass-deep);
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.toast--success {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.15) 100%),
    linear-gradient(180deg, var(--arcane-bright), var(--arcane-deep));
  color: #07221b;
  border-color: var(--arcane-deep);
}

.toast--error {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.15) 100%),
    linear-gradient(180deg, var(--ember-bright), #8a3422);
  color: #2a0d05;
  border-color: #6e1e10;
}

/* --------------------------------------------------------------
   Auth loading splash
   -------------------------------------------------------------- */
.auth-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  position: relative;
}
.auth-loading[hidden] { display: none; }
.auth-loading p {
  margin: 0;
  padding: 0 2rem;
  position: relative;
}
.auth-loading p::before,
.auth-loading p::after {
  content: "✦";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--brass-fade);
}
.auth-loading p::before { left: 0; }
.auth-loading p::after  { right: 0; }

/* --------------------------------------------------------------
   Responsive niceties
   -------------------------------------------------------------- */
@media (max-width: 980px) {
  .app-panel-left  { width: 360px; }
  .app-panel-right { width: 240px; }
}

@media (max-width: 760px) {
  .app-main { flex-direction: column; }
  .app-panel-left,
  .app-panel-right,
  .app-panel-center {
    width: 100%;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--leather);
  }
  .auth-card { padding: 1.75rem 1.3rem 1.4rem; }
  .auth-title { font-size: 1.7rem; letter-spacing: 0.28em; }
  .auth-logo { max-width: 240px; }
}

/* Reduce motion for sensitive users */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
