/* === FONT FACES (lokal) === */
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/cinzel-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/cinzel-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('/fonts/cinzel-800.woff2') format('woff2');
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/cormorant-garamond-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/cormorant-garamond-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/cormorant-garamond-400-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-400.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-600.woff2') format('woff2');
}

/* === DESIGN TOKENS === */
:root {
  --bg-deep: #0a0a0f;
  --bg-panel: #14141c;
  --bg-elevated: #1c1c28;
  --border-arcane: #2a2a3a;
  --gold-antique: #c9a961;
  --gold-bright: #e8c878;
  --green-eldritch: #7fdab8;
  --green-deep: #3a7a5e;
  --red-blood: #8b2c2c;
  --red-bright: #c44545;
  --text-primary: #e8e3d3;
  --text-secondary: #a8a394;
  --text-muted: #6a6558;
}

* { box-sizing: border-box; }

body {
  background: var(--bg-deep);
  background-image:
    radial-gradient(ellipse at top, rgba(127, 218, 184, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(201, 169, 97, 0.03) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100vh;
  margin: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.display-font { font-family: 'Cinzel', serif; letter-spacing: 0.05em; }
.mono-font { font-family: 'JetBrains Mono', monospace; }

/* === HEADER === */
.header-ornament {
  position: relative;
  text-align: center;
  padding: 2rem 0 1.5rem;
  border-bottom: 1px solid var(--border-arcane);
}

.eldritch-sigil {
  width: 60px;
  height: 60px;
  margin: 0 auto 0.75rem;
  opacity: 0.85;
}

h1.codex-title {
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 2.5rem;
  margin: 0;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold-antique) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.subtitle {
  color: var(--text-muted);
  font-style: italic;
  font-size: 1rem;
  margin-top: 0.25rem;
  letter-spacing: 0.05em;
}

/* === TABS === */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-arcane);
  margin-bottom: 2rem;
  background: var(--bg-panel);
  border-radius: 0;
}

.tab {
  flex: 1;
  padding: 1rem 1.5rem;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
  transition: all 0.25s;
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
}

.tab:hover { color: var(--gold-bright); background: var(--bg-elevated); }
.tab.active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold-antique);
  background: var(--bg-elevated);
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease-out; }

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

/* === PANELS === */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-arcane);
  padding: 1.5rem;
  position: relative;
}

.panel-title {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  color: var(--gold-antique);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-arcane);
}

/* === FORMS === */
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
  font-family: 'Cinzel', serif;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border-arcane);
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold-antique);
  box-shadow: 0 0 0 1px var(--gold-antique);
}

input[type="number"] { font-family: 'JetBrains Mono', monospace; }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: 1px solid var(--border-arcane);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:hover { border-color: var(--gold-antique); color: var(--gold-bright); transform: translateY(-1px); }

.btn-primary { background: var(--green-deep); border-color: var(--green-eldritch); color: var(--text-primary); }
.btn-primary:hover { background: var(--green-eldritch); color: var(--bg-deep); }

.btn-danger { background: transparent; border-color: var(--red-blood); color: var(--red-bright); }
.btn-danger:hover { background: var(--red-blood); color: var(--text-primary); }

.btn-ghost { background: transparent; }

/* === STATBLOCK (D&D 5e style) === */
.statblock {
  background: linear-gradient(180deg, #f4eddc 0%, #e8dfc8 100%);
  color: #1a1410;
  padding: 1.5rem;
  font-family: 'Cormorant Garamond', serif;
  box-shadow: 0 0 0 1px var(--gold-antique), 0 0 30px rgba(0, 0, 0, 0.5);
  position: relative;
  border-radius: 2px;
}

.statblock::before, .statblock::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent 0%, #8b2c2c 20%, #8b2c2c 80%, transparent 100%);
}
.statblock::before { top: -2px; }
.statblock::after { bottom: -2px; }

.sb-name {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  color: #8b2c2c;
  font-weight: 800;
  margin: 0 0 0.15rem;
  line-height: 1.1;
  letter-spacing: 0.02em;
}
.sb-subtitle { font-style: italic; font-size: 0.95rem; color: #4a3828; margin-bottom: 0.5rem; }
.sb-divider {
  height: 4px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 4'%3E%3Cpolygon points='0,0 50,4 100,0' fill='%238b2c2c'/%3E%3C/svg%3E") repeat-x;
  background-size: 30px 4px;
  margin: 0.5rem 0;
}
.sb-meta { font-size: 0.95rem; line-height: 1.4; color: #1a1410; }
.sb-meta strong { color: #8b2c2c; font-weight: 600; }
.sb-stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.5rem; margin: 0.6rem 0; text-align: center; }
.sb-stat-name { font-family: 'Cinzel', serif; font-size: 0.75rem; color: #8b2c2c; text-transform: uppercase; font-weight: 600; }
.sb-stat-val { font-family: 'JetBrains Mono', monospace; font-size: 1rem; color: #1a1410; }
.sb-section-title {
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  color: #8b2c2c;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
  border-bottom: 1px solid #8b2c2c;
  padding-bottom: 0.15rem;
}
.sb-action { margin: 0.4rem 0; font-size: 0.95rem; }
.sb-action-name { font-style: italic; font-weight: 600; color: #1a1410; }

/* === HELPERS === */
.hint { font-size: 0.85rem; color: var(--text-muted); font-style: italic; margin-top: 0.3rem; }

.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 0.6rem; }
.stat-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 0.6rem; }

.difficulty-badge {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: 1px solid;
}
.diff-trivial { color: #6a8a6a; border-color: #6a8a6a; }
.diff-easy { color: #7fdab8; border-color: #7fdab8; }
.diff-medium { color: #c9a961; border-color: #c9a961; }
.diff-hard { color: #d4842c; border-color: #d4842c; }
.diff-deadly { color: #c44545; border-color: #c44545; background: rgba(196, 69, 69, 0.1); }
.diff-tpk { color: #8b2c2c; border-color: #8b2c2c; background: rgba(139, 44, 44, 0.2); animation: pulse 2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.library-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-arcane);
  transition: background 0.15s;
}
.library-row:hover { background: var(--bg-elevated); }
.library-row .name { font-family: 'Cinzel', serif; color: var(--gold-bright); }
.library-row .cr-tag { font-family: 'JetBrains Mono', monospace; color: var(--text-secondary); font-size: 0.85rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-style: italic;
}

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--gold-antique);
  padding: 2rem;
  max-width: 500px;
  width: 90%;
}

.toast {
  position: fixed;
  bottom: 2rem; right: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--green-eldritch);
  color: var(--green-eldritch);
  padding: 1rem 1.5rem;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  z-index: 200;
  animation: slideIn 0.3s ease-out, slideOut 0.3s ease-in 2.7s forwards;
}
.toast.error { border-color: var(--red-bright); color: var(--red-bright); }

@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(120%); opacity: 0; } }

/* === PRINT === */
@media print {
  body { background: white; color: black; }
  body::before { display: none; }
  .no-print { display: none !important; }
  .statblock { box-shadow: none; border: 2px solid #8b2c2c; page-break-inside: avoid; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr !important; }
  h1.codex-title { font-size: 1.8rem; }
  .tab { padding: 0.75rem 0.5rem; font-size: 0.7rem; }
  .sb-stats { grid-template-columns: repeat(3, 1fr); }
}
