/* =====================================================================
   GRIMOIRE OF PUZZLES — shared theming & components
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=MedievalSharp&display=swap');

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

:root {
  --gold: #c9954a;
  --gold-light: #f0c87a;
  --gold-bright: #ffd98a;
  --gold-dim: #7a5a2a;
  --gold-deep: #5a4020;
  --gold-faint: #3a2810;

  --ember: #ff7a2a;
  --blood: #8b1e1e;
  --moss: #4a6840;
  --moonstone: #b8d4ff;
  --violet: #5a3a8a;

  --bg: #0a0805;
  --bg-2: #120d08;
  --surface: #1a130a;
  --surface-2: #221810;
  --surface-3: #2a1f12;

  --text: #e8d5b0;
  --text-bright: #fff5dd;
  --text-dim: #8a7055;
  --text-faint: #5a4838;

  --border: #3a2810;
  --border-bright: #5a4020;

  --shadow-glow: 0 0 40px rgba(200, 140, 40, 0.25);
  --shadow-deep: 0 12px 40px rgba(0, 0, 0, 0.6);

  --font-display: 'Cinzel', serif;
  --font-body: 'Crimson Text', Georgia, serif;
  --font-rune: 'MedievalSharp', 'Cinzel', serif;
}

html {
  scroll-behavior: smooth;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

body {
  min-height: 100vh;
  line-height: 1.6;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(200, 150, 50, 0.4); color: var(--text-bright); }

/* ---------- AMBIENT BACKGROUND ---------- */
.bg-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(200, 110, 30, 0.10) 0%, transparent 70%),
    radial-gradient(ellipse 50% 70% at 0% 60%, rgba(100, 50, 10, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 50% 70% at 100% 60%, rgba(100, 50, 10, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(160, 90, 20, 0.08) 0%, transparent 70%);
}

.bg-noise {
  position: fixed;
  inset: 0;
  opacity: 0.035;
  z-index: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px;
  mix-blend-mode: overlay;
}

/* Floating embers — purely decorative */
.embers {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.ember {
  position: absolute;
  bottom: -10px;
  width: 3px;
  height: 3px;
  background: radial-gradient(circle, rgba(255, 180, 80, 0.9) 0%, rgba(255, 100, 30, 0.4) 50%, transparent 100%);
  border-radius: 50%;
  filter: blur(0.5px);
  opacity: 0;
  animation: ember-rise linear infinite;
}
@keyframes ember-rise {
  0%   { transform: translate(0, 0) scale(1);    opacity: 0; }
  10%  {                                          opacity: 0.9; }
  100% { transform: translate(var(--drift, 30px), -110vh) scale(0.4); opacity: 0; }
}

/* ---------- TYPOGRAPHY UTILS ---------- */
.h-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--gold-light);
  text-transform: uppercase;
}
.text-flavor {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-dim);
}

/* ---------- BUTTONS ---------- */
.btn, button {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  color: var(--gold);
  background: transparent;
  border: 1px solid var(--border);
  padding: 10px 22px;
  border-radius: 2px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.1s, box-shadow 0.2s;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  font-weight: 500;
}
.btn:hover, button:hover {
  color: var(--gold-light);
  border-color: var(--gold-dim);
  background: rgba(180, 120, 40, 0.07);
}
.btn:active, button:active { transform: scale(0.97); }
.btn:focus-visible, button:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 2px;
}

.btn.primary, button.primary {
  color: var(--bg);
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(200, 140, 40, 0.2);
}
.btn.primary:hover, button.primary:hover {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold-bright) 100%);
  border-color: var(--gold-light);
  color: var(--bg);
  box-shadow: 0 0 30px rgba(240, 180, 80, 0.4);
}
.btn.ghost { border-color: transparent; color: var(--gold-dim); }
.btn.ghost:hover { color: var(--gold-light); border-color: var(--border); }

button.hidden, .hidden { display: none !important; }

/* ---------- DIVIDER ---------- */
.divider {
  display: block;
  width: 200px;
  height: 1px;
  margin: 2.5rem auto;
  background: linear-gradient(to right, transparent, var(--gold-dim), transparent);
  opacity: 0.5;
  border: 0;
  position: relative;
}
.divider.ornate {
  width: 280px;
  background: none;
  height: 14px;
  opacity: 0.6;
  background-image:
    linear-gradient(to right, transparent, var(--gold-dim) 30%, var(--gold-dim) 70%, transparent),
    radial-gradient(circle at 50% 50%, var(--gold) 1px, transparent 2px);
  background-position: center 7px, center;
  background-size: 100% 1px, 8px 8px;
  background-repeat: no-repeat, no-repeat;
}
.divider.ornate::before, .divider.ornate::after {
  content: '◆';
  position: absolute;
  top: 0;
  font-size: 10px;
  color: var(--gold);
  background: var(--bg);
  padding: 0 6px;
}
.divider.ornate::before { left: 50%; transform: translateX(-50%); }

/* ---------- MODE BADGE ---------- */
.mode-badge {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-dim);
  border: 1px solid var(--gold-deep);
  padding: 4px 12px;
  border-radius: 2px;
  margin-bottom: 1rem;
}
.mode-badge.dm {
  color: var(--gold-light);
  border-color: var(--gold-dim);
  background: rgba(180, 120, 40, 0.08);
  box-shadow: 0 0 12px rgba(200, 140, 40, 0.1);
}

/* ---------- DM EDITOR ---------- */
.dm-editor {
  width: 100%;
  max-width: 740px;
  margin: 0 auto 2.5rem;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem 1.5rem 1.2rem;
  box-shadow: var(--shadow-deep);
  position: relative;
}
.dm-editor::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 4px;
  padding: 1px;
  background: linear-gradient(135deg, var(--gold-dim), transparent 40%, transparent 60%, var(--gold-dim));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  opacity: 0.4;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.editor-header h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--gold-light);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.editor-header a {
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: var(--gold-dim);
  text-decoration: none;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.editor-header a:hover { color: var(--gold-light); }

.editor-section { margin-bottom: 1.2rem; }
.editor-section-title {
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: var(--gold-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.editor-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--border), transparent);
}

.editor-field { margin-bottom: 0.7rem; }
.editor-field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}
.editor-field input[type="text"],
.editor-field input[type="number"],
.editor-field textarea,
.editor-field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 8px 10px;
  border-radius: 2px;
  transition: border-color 0.2s, background 0.2s;
}
.editor-field textarea { min-height: 60px; resize: vertical; }
.editor-field input:focus,
.editor-field textarea:focus,
.editor-field select:focus {
  outline: none;
  border-color: var(--gold-dim);
  background: rgba(180, 120, 40, 0.05);
}
.editor-field .small-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 0.2rem;
}
.editor-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1.5rem;
}
.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.checkbox-row input[type="checkbox"] {
  accent-color: var(--gold);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.editor-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}
.editor-actions button { flex: 1 1 auto; min-width: 140px; padding: 12px 18px; }

.copy-feedback {
  text-align: center;
  font-size: 0.85rem;
  color: var(--gold-light);
  font-style: italic;
  margin-top: 0.6rem;
  min-height: 1.2em;
  transition: opacity 0.4s;
  opacity: 0;
}
.copy-feedback.show { opacity: 1; }

/* DM-specific: state token toggle (used by some puzzles) */
.state-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.state-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 2px;
  font-family: var(--font-display);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.05em;
}
.state-toggle.lit, .state-toggle.active {
  background: rgba(240, 180, 60, 0.12);
  border-color: var(--gold-dim);
  color: var(--gold-light);
}
.state-toggle:hover { border-color: var(--gold-dim); }

/* ---------- BACK LINK ---------- */
.back-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: var(--gold-dim);
  text-decoration: none;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 7px 12px;
  background: rgba(13, 10, 7, 0.7);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: 2px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.back-link:hover {
  color: var(--gold-light);
  border-color: var(--gold-dim);
  background: rgba(20, 15, 8, 0.8);
}

/* ---------- STATUS BAR ---------- */
.status-bar {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.5rem 0 1.2rem;
  font-style: italic;
  font-size: 1rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  transition: color 0.3s;
  text-align: center;
  padding: 0 1rem;
}
.status-bar.success {
  color: var(--gold-light);
  text-shadow: 0 0 20px rgba(200, 150, 50, 0.5);
  font-size: 1.1rem;
}
.status-bar.fail {
  color: #c84040;
  text-shadow: 0 0 12px rgba(200, 50, 50, 0.4);
}

/* ---------- META ROW ---------- */
.meta {
  font-size: 0.78rem;
  color: var(--gold-dim);
  letter-spacing: 0.1em;
  text-align: center;
}

/* ---------- PUZZLE FOOTER ---------- */
.puzzle-footer {
  width: 100%;
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--font-body);
}
.puzzle-footer a {
  color: var(--gold-dim);
  text-decoration: none;
  margin: 0 0.5rem;
  transition: color 0.2s;
}
.puzzle-footer a:hover { color: var(--gold-light); }

/* ---------- AD SLOT ---------- */
.ad-slot {
  max-width: 728px;
  min-height: 90px;
  margin: 0 auto 3rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-dim);
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.4;
}

/* ---------- COMMON LAYOUT ---------- */
.layout {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.layout.has-editor { justify-content: flex-start; padding-top: 4rem; }

.puzzle-shell {
  position: relative;
  text-align: center;
  padding: 2rem 1.5rem 2rem;
  max-width: 760px;
  width: 100%;
  animation: fadeIn 0.8s ease;
}
.puzzle-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--gold-light);
  text-shadow: 0 0 40px rgba(200, 140, 40, 0.4);
  margin-bottom: 0.4rem;
}
.puzzle-subtitle {
  font-style: italic;
  font-size: 1rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.puzzle-subtitle:empty { display: none; }
.puzzle-rule {
  font-size: 0.85rem;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
  margin-bottom: 2rem;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}
.puzzle-rule:empty { display: none; }

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* ---------- AMBIENT GLOW ---------- */
.ambient-glow {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 700px;
  height: 220px;
  background: radial-gradient(ellipse at bottom, rgba(160, 90, 20, 0.12) 0%, transparent 70%);
  pointer-events: none;
  transition: opacity 0.5s;
  z-index: 0;
}

/* ---------- ANIMATIONS ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(200, 140, 40, 0.2); }
  50%      { box-shadow: 0 0 35px rgba(240, 180, 80, 0.45); }
}
@keyframes float-up {
  0%   { opacity: 0; transform: translateY(15px); }
  100% { opacity: 1; transform: none; }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 640px) {
  .editor-field-row { grid-template-columns: 1fr; }
  .editor-actions button { min-width: 100%; }
  .back-link { font-size: 0.6rem; padding: 5px 10px; }
}
