:root {
  --bg: #0b0d12;
  --bg-elev: #141821;
  --bg-chat: #10141c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f5f8;
  --muted: #9aa3b2;
  --owner: #f0b429;
  --associate: #3dcdc0;
  --bot: #9b8cff;
  --accent: #7c5cff;
  --danger: #ff6b7a;
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, 0.18), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(61, 205, 192, 0.1), transparent 45%),
    var(--bg);
  color: var(--text);
  letter-spacing: 0.01em;
}

#app {
  min-height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 780px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 650; }
.presence { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }
.mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #9b8cff, #5b3dff);
  font-weight: 700;
  font-size: 1.2rem;
  flex: none;
}

.you-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  white-space: nowrap;
}

.log {
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, transparent, rgba(16, 20, 28, 0.35));
}

.day-rule {
  align-self: center;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 6px 0;
}

.bubble {
  max-width: min(92%, 560px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 11px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}
.bubble.mine { align-self: flex-end; background: #1a2030; }
.bubble.theirs { align-self: flex-start; }

.meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.meta .name { font-weight: 650; font-size: 0.86rem; }
.meta .time { margin-left: auto; color: var(--muted); font-size: 0.72rem; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }

.badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 7px;
  border: 1px solid currentColor;
}
.role-owner, .badge.owner { color: var(--owner); }
.role-associate, .badge.associate { color: var(--associate); }
.role-bot, .badge.bot { color: var(--bot); }

.composer {
  display: flex;
  gap: 10px;
  padding: 10px 16px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.92);
  backdrop-filter: blur(16px);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 12px;
  font: inherit;
  line-height: 1.35;
}
.composer textarea:focus, .card input:focus {
  outline: 2px solid rgba(124, 92, 255, 0.65);
  outline-offset: 1px;
}
.composer button, .card button {
  border: 0;
  background: linear-gradient(180deg, #8f74ff, #6a49ff);
  color: white;
  font: inherit;
  font-weight: 650;
  border-radius: 14px;
  padding: 0 16px;
  min-width: 76px;
  cursor: pointer;
}
.composer button:disabled, .card button:disabled { opacity: 0.5; cursor: not-allowed; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 7, 12, 0.72);
  z-index: 5;
}
.card {
  width: min(100%, 420px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 8px; font-size: 1.25rem; }
.card p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }
.card input {
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: var(--bg-chat);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
}
.card button { width: 100%; height: 44px; }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 280px;
  padding: 40px 12px;
}
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

.chat-img { display:block; max-width:100%; max-height:420px; border-radius:10px; margin-top:6px; }

/* character hover bubble */
.name[data-tip] { position: relative; cursor: help; }
.name[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 20;
  white-space: nowrap; padding: 6px 10px; border-radius: 8px;
  background: #0b0f17; color: #e8ecf4; border: 1px solid rgba(255,255,255,0.18);
  font-size: 12px; font-weight: 500; box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  pointer-events: none;
}

/* Spelljammer wildspace theme */
body {
  background:
    linear-gradient(rgba(5, 3, 14, 0.35), rgba(5, 3, 14, 0.55)),
    url('/wildspace-bg.jpg') center / cover fixed no-repeat,
    #07040f;
}
.topbar { background: rgba(10, 6, 22, 0.72); border-bottom-color: rgba(155, 140, 255, 0.22); }
.log { background: transparent; }
.bubble {
  background: rgba(16, 12, 32, 0.78);
  border-color: rgba(155, 140, 255, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255,255,255,0.02) inset;
}
.bubble.mine { background: rgba(30, 22, 58, 0.82); }
.day-rule { color: #c9bfff; text-shadow: 0 1px 4px rgba(0,0,0,0.8); }

/* ===== Spelljammer ship + gold dragon theme ===== */
:root {
  --gold: #d4a64a;
  --gold-hi: #f6d98a;
  --gold-lo: #8a6420;
  --wood: #2a1a10;
  --wood-dk: #170d07;
  --rune: #a77bff;
}
/* Top bar: dark wood with brass trim */
.topbar {
  background:
    linear-gradient(180deg, rgba(255,220,150,0.06), transparent 40%),
    repeating-linear-gradient(92deg, rgba(0,0,0,0.18) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, #3a2414, var(--wood-dk));
  border-bottom: 2px solid var(--gold);
  box-shadow: 0 1px 0 var(--gold-lo), 0 6px 22px rgba(0,0,0,0.55), inset 0 -1px 0 rgba(255,230,160,0.25);
}
.topbar::after {
  content: "ᚱ ✦ ᛟ ✦ ᚦ ✦ ᛉ ✦ ᚹ ✦ ᛞ ✦ ᚷ ✦ ᛗ ✦ ᚱ ✦ ᛟ ✦ ᚦ ✦ ᛉ";
  position: absolute; left: 0; right: 0; bottom: -17px;
  text-align: center; font-size: 10px; letter-spacing: 0.35em;
  color: var(--rune); text-shadow: 0 0 6px rgba(167,123,255,0.9);
  pointer-events: none; opacity: 0.75; white-space: nowrap; overflow: hidden;
}
.brand h1 {
  font-family: "Cinzel", "Trajan Pro", Georgia, "Times New Roman", serif;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, var(--gold-lo));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 1px 0 rgba(0,0,0,0.35);
}
.presence { color: #c9b27a; }
.mark {
  width: 46px; height: 46px; border-radius: 50%; overflow: hidden; padding: 0;
  background: #000;
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 2px var(--gold-lo), 0 0 14px rgba(212,166,74,0.55), 0 0 22px rgba(167,123,255,0.35);
}
.mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.you-chip {
  background: linear-gradient(180deg, #2b1b0f, #160d06);
  border: 1px solid var(--gold);
  color: var(--gold-hi);
  box-shadow: inset 0 1px 0 rgba(255,230,160,0.2);
}
/* Chat log: faint gold dragon watermark */
.log { position: relative; padding-top: 26px; }
#app::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: url('/dragon-512.jpg') center 55% / min(70vh, 520px) no-repeat;
  opacity: 0.07; mix-blend-mode: screen;
}
#app > * { position: relative; z-index: 1; }
.topbar { z-index: 3; }
.bubble { border-color: rgba(212,166,74,0.22); }
.bubble.mine { border-color: rgba(212,166,74,0.4); }
/* Scrollbar: brass rail with a gold thumb */
.log { scrollbar-width: thin; scrollbar-color: var(--gold) rgba(23,13,7,0.6); }
.log::-webkit-scrollbar { width: 10px; }
.log::-webkit-scrollbar-track {
  background: linear-gradient(90deg, #170d07, #2a1a10, #170d07);
  border-left: 1px solid var(--gold-lo);
}
.log::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, var(--gold-lo), var(--gold-hi), var(--gold-lo));
  border-radius: 10px; border: 2px solid #170d07;
  box-shadow: 0 0 6px rgba(212,166,74,0.6);
}
.log::-webkit-scrollbar-button { display: none; height: 0; }
/* Composer: wood deck with brass */
.composer {
  background:
    repeating-linear-gradient(92deg, rgba(0,0,0,0.18) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, var(--wood), var(--wood-dk));
  border-top: 2px solid var(--gold);
  box-shadow: 0 -1px 0 var(--gold-lo), 0 -6px 22px rgba(0,0,0,0.5);
}
.composer textarea {
  background: rgba(10,6,3,0.75);
  border: 1px solid var(--gold-lo);
  color: #f3ead6;
}
.composer textarea::placeholder { color: #9c8458; font-style: italic; }
.composer textarea:focus { outline: 2px solid rgba(212,166,74,0.6); }
.composer button {
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 50%, var(--gold-lo));
  color: #2a1606;
  font-family: "Cinzel", Georgia, serif; letter-spacing: 0.08em; font-weight: 800;
  border: 1px solid #f9e2a0;
  box-shadow: 0 0 0 1px var(--gold-lo), 0 0 14px rgba(212,166,74,0.45), inset 0 1px 0 rgba(255,255,255,0.5);
  text-shadow: 0 1px 0 rgba(255,240,200,0.6);
}
.composer button:hover { box-shadow: 0 0 0 1px var(--gold-lo), 0 0 20px rgba(167,123,255,0.6), 0 0 14px rgba(212,166,74,0.6), inset 0 1px 0 rgba(255,255,255,0.5); }
/* Dungeon Master badge in gold */
.badge.bot, .role-bot { color: var(--gold-hi); }
.brand h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 700; letter-spacing: 0.04em; }
.topbar { padding-bottom: 20px; }
.topbar::after { bottom: 3px; z-index: 4; opacity: 0.85; }
.maker {
  margin: 1px 0 0; font-family: Georgia, serif; font-size: 0.72rem; letter-spacing: 0.08em;
  color: var(--gold); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.maker sup { font-size: 0.6em; }
.maker span { text-transform: none; letter-spacing: 0.02em; color: #9c8458; margin-left: 8px; font-size: 0.92em; }
@media (max-width: 560px) { .maker span { display: none; } }
.topbar::after { content: "✦ ◇ ✧ ◇ ✦ ◇ ✧ ◇ ✦ ◇ ✧ ◇ ✦ ◇ ✧ ◇ ✦ ◇ ✧ ◇ ✦"; letter-spacing: 0.5em; color: var(--rune); }

/* ===== Large centered Blackthorn rune logo ===== */
.topbar { position: relative; justify-content: center; }
.brand.brand-center { flex-direction: column; align-items: center; text-align: center; gap: 6px; width: 100%; }
.brand-text { display: flex; flex-direction: column; align-items: center; }
.big-logo { width: clamp(96px, 16vw, 170px); height: auto; aspect-ratio: 1; border-radius: 50%; display: block;
  box-shadow: 0 0 0 3px #c9a24a, 0 0 22px rgba(170, 40, 255, 0.55), 0 6px 18px rgba(0,0,0,0.6); }
.topbar .you-chip { position: absolute; top: 12px; right: 14px; }
.brand .mark { display: none; }
@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: center; }
  .topbar .you-chip { position: static; margin-top: 4px; }
}
/* ===== Logo on the left, compact header (overrides centered layout) ===== */
.topbar { justify-content: space-between; flex-direction: row; align-items: center; }
.brand.brand-center { flex-direction: row; align-items: center; text-align: left; gap: 12px; width: auto; }
.brand-text { align-items: flex-start; }
.big-logo { width: 64px; box-shadow: 0 0 0 2px #c9a24a, 0 0 12px rgba(170, 40, 255, 0.5); }
.topbar .you-chip { position: static; }
@media (max-width: 560px) {
  .topbar { flex-direction: row; }
  .big-logo { width: 48px; }
  .brand.brand-center { gap: 8px; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .brand.brand-center { flex: 1 1 200px; min-width: 0; }
  .brand h1 { font-size: 0.95rem; }
  .topbar .you-chip { font-size: 0.72rem; padding: 4px 8px; margin-left: auto; }
}
/* Big logo on the left */
.big-logo { width: clamp(96px, 16vw, 170px); box-shadow: 0 0 0 3px #c9a24a, 0 0 22px rgba(170, 40, 255, 0.55), 0 6px 18px rgba(0,0,0,0.6); }
.brand.brand-center { gap: 18px; }
.brand h1 { font-size: 1.35rem; }
@media (max-width: 560px) { .big-logo { width: 96px; } .brand h1 { font-size: 0.95rem; } .brand.brand-center { gap: 10px; } }

/* ===== Tavern Portal login / claim screens ===== */
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.logout-btn {
  font: inherit; font-size: 0.74rem; font-family: "Cinzel", Georgia, serif; letter-spacing: 0.06em; font-weight: 700;
  padding: 6px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  background: linear-gradient(180deg, #2b1b0f, #160d06); color: var(--gold-hi);
  border: 1px solid var(--rune); box-shadow: 0 0 10px rgba(167,123,255,0.35), inset 0 1px 0 rgba(255,230,160,0.15);
}
.logout-btn:hover { box-shadow: 0 0 16px rgba(167,123,255,0.7), inset 0 1px 0 rgba(255,230,160,0.2); }
@media (max-width: 560px) {
  .top-actions { margin-left: auto; gap: 6px; }
  .topbar .top-actions .you-chip { margin-left: 0; }
  .logout-btn { font-size: 0.66rem; padding: 4px 9px; }
}

.auth-screen {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 4px;
  padding: calc(20px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
  background:
    radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0.05) 0%, rgba(0,0,0,0.35) 55%, rgba(0,0,0,0.85) 100%),
    linear-gradient(180deg, rgba(5,3,10,0.35), rgba(5,3,10,0.15) 40%, rgba(5,3,10,0.55)),
    url('/login-tavern-door-bg.jpg') center / cover no-repeat,
    #07040a;
}
.auth-screen.tall { justify-content: flex-start; }
.auth-logo {
  width: min(400px, 70vw); max-height: 46vh; height: auto; aspect-ratio: 1; object-fit: contain; display: block; flex: none;
  border-radius: 50%;
  filter: drop-shadow(0 0 18px rgba(170, 40, 255, 0.75)) drop-shadow(0 0 42px rgba(140, 30, 255, 0.45)) drop-shadow(0 8px 20px rgba(0,0,0,0.8));
}
.auth-card {
  width: min(100%, 400px); text-align: center; flex: none;
  padding: 18px 22px 16px; border-radius: 18px;
  background: linear-gradient(180deg, rgba(14,9,6,0.80), rgba(8,5,12,0.86));
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 1px #3d2a0c, inset 0 0 0 1px rgba(246,217,138,0.18), 0 0 30px rgba(167,123,255,0.28), 0 22px 60px rgba(0,0,0,0.75);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.auth-title {
  margin: 0; font-family: "Cinzel", "Trajan Pro", Georgia, serif; font-weight: 800; font-size: 1.9rem; text-shadow: none; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.9)); letter-spacing: 0.08em;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, var(--gold-lo));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.auth-tag { margin: 4px 0 14px; color: var(--rune); text-shadow: 0 0 8px rgba(167,123,255,0.6); font-style: italic; font-family: Georgia, serif; font-size: 0.9rem; }
.auth-form { text-align: left; border-top: 1px solid rgba(212,166,74,0.35); padding-top: 14px; }
.auth-form h2 { margin: 0 0 8px; font-family: "Cinzel", Georgia, serif; color: var(--gold-hi); font-size: 1.15rem; letter-spacing: 0.06em; text-align: center; }
.auth-form label { display: block; margin: 10px 0 5px; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); font-family: Georgia, serif; }
.auth-form label .hint { text-transform: none; letter-spacing: 0; color: #9c8458; font-size: 0.95em; }
.auth-form input {
  width: 100%; font: inherit; color: #f3ead6; padding: 11px 12px; border-radius: 12px;
  background: rgba(10,6,3,0.8); border: 1px solid var(--gold-lo);
}
.auth-form input:focus { outline: 2px solid rgba(167,123,255,0.7); outline-offset: 1px; border-color: var(--gold); }
.auth-form button {
  width: 100%; height: 46px; margin-top: 16px; cursor: pointer; border-radius: 10px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.06) 0 2px, transparent 2px 6px),
    linear-gradient(180deg, var(--gold-hi), var(--gold) 48%, #a9782a 52%, var(--gold-lo));
  outline: 2px solid #2b2b30; outline-offset: 0;
  color: #2a1606; font-family: "Cinzel", Georgia, serif; letter-spacing: 0.08em; font-weight: 800; font-size: 0.95rem;
  border: 1px solid #f9e2a0;
  box-shadow: 0 0 0 1px var(--gold-lo), 0 0 14px rgba(212,166,74,0.45), inset 0 1px 0 rgba(255,255,255,0.5);
}
.auth-form button:hover { box-shadow: 0 0 0 1px var(--gold-lo), 0 0 20px rgba(167,123,255,0.6), 0 0 14px rgba(212,166,74,0.6), inset 0 1px 0 rgba(255,255,255,0.5); }
.auth-form button:disabled { opacity: 0.6; cursor: wait; }
.auth-note { margin: 0 0 4px; color: #d9c9a0; font-size: 0.88rem; line-height: 1.45; text-align: center; }
.auth-error { margin: 12px 0 0; padding: 8px 10px; border-radius: 10px; background: rgba(255,107,122,0.12); border: 1px solid rgba(255,107,122,0.45); color: #ffb3bc; font-size: 0.86rem; }
.auth-help { margin: 12px 0 0; color: #9c8458; font-size: 0.78rem; line-height: 1.4; text-align: center; }
.auth-maker { margin: 16px 0 0; color: var(--gold-lo); font-family: Georgia, serif; font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; }
.auth-maker sup { font-size: 0.6em; }

.auth-form input:focus { box-shadow: 0 0 0 3px rgba(167,123,255,0.35), 0 0 16px rgba(167,123,255,0.55); }
@media (max-width: 560px) {
  .auth-screen { justify-content: flex-start; padding-top: calc(14px + var(--safe-top)); }
  .auth-logo { width: min(400px, 62vw); }
  .auth-title { font-size: 1.6rem; }
  .auth-card { padding: 14px 16px 12px; }
}
@media (min-width: 561px) and (max-height: 860px) {
  .auth-logo { width: min(320px, 40vh); }
}
@media (min-width: 561px) and (max-height: 860px) {
  .auth-screen.claiming .auth-logo { width: min(260px, 30vh); }
  .auth-screen.claiming .auth-form label { margin-top: 8px; }
}
