:root {
  --bg: #020308;
  --panel: #070a12ef;
  --border: #ffffff26;
  --text: #e9e5dc;
  --muted: #9a9488;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: "Spectral", serif; }
#app { min-height: 100%; position: relative; overflow: hidden; }
#ambient-canvas { position: fixed; inset: 0; z-index: 0; }
.fog { position: fixed; inset: -25%; pointer-events: none; z-index: 1; opacity: 0.2; mix-blend-mode: screen; filter: blur(50px); }
.fog-a { background: radial-gradient(circle at 20% 30%, #3f4f9c33, transparent 40%); animation: drift 26s ease-in-out infinite alternate; }
.fog-b { background: radial-gradient(circle at 72% 70%, #8f222233, transparent 36%); animation: drift 32s ease-in-out infinite alternate-reverse; }
@keyframes drift { from { transform: translate3d(-2%, -1%, 0) scale(1); } to { transform: translate3d(3%, 2%, 0) scale(1.1); } }

.shell { position: relative; z-index: 2; padding: 1.2rem; max-width: 1360px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
h1 { font-family: "Cinzel", serif; letter-spacing: 0.14em; font-size: clamp(1.2rem, 2.6vw, 2.25rem); margin: 0; animation: shimmer 3.2s ease-in-out infinite alternate; }
@keyframes shimmer { from { opacity: 0.9; } to { opacity: 1; filter: drop-shadow(0 0 14px #ffffff44); } }
.audio-controls { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .9rem; }
button, input, textarea, select { background: #0a0f18; color: var(--text); border: 1px solid var(--border); border-radius: 9px; padding: .56rem .75rem; }
button { cursor: pointer; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
button:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px #ffffff23 inset; border-color: #ffffff56; }
.card { background: linear-gradient(170deg, #080c14f2, #05070ef2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: 0 18px 44px #000c; backdrop-filter: blur(10px); }

.welcome-panel { margin-top: 1rem; text-align: center; }
#rotating-phrase { font-family: "Cinzel", serif; font-size: 1.3rem; margin: .2rem 0; transition: opacity .3s ease; }
.subline { color: var(--muted); margin: 0; }
.page-nav { margin-top: .85rem; display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.page-tab.active { border-color: color-mix(in oklab, var(--glow), #fff 58%); box-shadow: 0 0 15px color-mix(in oklab, var(--glow), #000 82%); }

.auth-card { max-width: 460px; margin: 1rem auto; display: grid; gap: .6rem; }
.auth-card form { display: grid; gap: .6rem; }
.hidden { display: none !important; }

.dashboard { display: grid; gap: 1rem; margin-top: 1rem; }
.section-title { margin: 0; font-family: "Cinzel", serif; letter-spacing: .06em; }
.section-copy { margin: .35rem 0 1rem; color: #c0baad; }

.emblem-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.emblem-card {
  min-height: 420px;
  text-align: center;
  border: 1px solid color-mix(in oklab, var(--realm), #fff 74%);
  background: radial-gradient(circle at 50% 8%, color-mix(in oklab, var(--realm), #000 78%), #060910 62%);
  padding: .7rem .7rem 1rem;
}
.emblem-image {
  width: 100%;
  height: 320px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #ffffff32;
  box-shadow: 0 0 26px #000 inset, 0 0 24px color-mix(in oklab, var(--realm), #000 65%);
}
.emblem-card h3 { margin: .7rem 0 .2rem; font-family: "Cinzel", serif; color: var(--accent); }
.emblem-card p { margin: 0; color: #cbc6bb; font-size: .92rem; }

.realm-console-head h3 { margin: 0; font-family: "Cinzel", serif; font-size: 1.42rem; color: color-mix(in oklab, var(--glow), #fff 35%); }
.realm-console-head p { margin: .35rem 0 .8rem; color: #bbb6aa; }
.realm-console-body { display: grid; grid-template-columns: 340px 1fr; gap: .9rem; }
.tool-list { display: grid; gap: .5rem; max-height: 620px; overflow: auto; padding-right: .2rem; }
.tool-pill { text-align: left; width: 100%; }
.tool-pill.active { border-color: color-mix(in oklab, var(--glow), #fff 56%); box-shadow: 0 0 14px color-mix(in oklab, var(--glow), #000 76%); }
#tool-title, #global-tool-title { margin: 0; font-family: "Cinzel", serif; color: color-mix(in oklab, var(--glow), #fff 33%); }
#tool-description, #global-tool-note { color: #c7c2b5; margin: .4rem 0 .9rem; }
.tool-form { display: grid; grid-template-columns: 1fr 1fr; gap: .62rem; }
.tool-form label { display: grid; gap: .3rem; color: #d8d4c9; font-size: .91rem; }
.tool-actions { display: flex; gap: .56rem; margin-top: .75rem; flex-wrap: wrap; }
.accent-btn { border-color: color-mix(in oklab, var(--glow), #fff 48%); }
.tool-output {
  margin-top: .8rem;
  border: 1px solid #ffffff24;
  background: #02050cd6;
  border-radius: 11px;
  padding: .85rem;
  white-space: pre-wrap;
  min-height: 265px;
  line-height: 1.45;
  color: #e0ddd3;
}
#rune-image-wrap { margin-top: .6rem; }
.rune-image { width: min(390px, 100%); border-radius: 10px; border: 1px solid #ffffff31; box-shadow: 0 0 18px #000; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.map-layout { display: grid; grid-template-columns: 320px 1fr; gap: .9rem; }
.map-controls { display: grid; gap: .6rem; align-content: start; }
.map-controls label { display: grid; gap: .3rem; }
.map-controls label input[type="checkbox"] { width: auto; margin-right: .4rem; }
#map-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid #ffffff2c;
  background: #070a12;
  box-shadow: inset 0 0 30px #000;
}
.history-results { margin-top: .8rem; display: grid; gap: .8rem; max-height: 70vh; overflow: auto; }
.history-item { border: 1px solid #ffffff23; border-radius: 10px; padding: .72rem; background: #040813cb; }
.history-item h4 { margin: 0 0 .2rem; font-family: "Cinzel", serif; }
.history-item small { color: #a79f91; }
.history-item pre { white-space: pre-wrap; color: #dbd6ca; }
.muted { color: #8f887a; }

.realm-arcane { --glow: #d4a54b; }
.realm-sangrith { --glow: #af162c; }
.realm-anathema { --glow: #6d36a8; }
.realm-elemental { --glow: #25a5ae; }
.shell[class*="realm-"] .card { box-shadow: 0 0 0 1px color-mix(in oklab, var(--glow), #000 74%), 0 16px 46px color-mix(in oklab, var(--glow), #000 88%); }

@media (max-width: 1200px) {
  .emblem-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .realm-console-body { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .grid-2, .emblem-grid, .tool-form { grid-template-columns: 1fr; }
  .emblem-card { min-height: 340px; }
  .emblem-image { height: 220px; }
}
