:root {
  color-scheme: light;
  --ink: #13251d;
  --ink-soft: #526158;
  --paper: #f7f4e9;
  --surface: #fffdf6;
  --line: #dad8ca;
  --forest: #173f31;
  --forest-2: #275a47;
  --gold: #f5c65d;
  --accent-ink: #13251d;
  --rust: #d96845;
  --blue: #40749b;
  --shadow: 0 20px 60px rgba(30, 48, 38, 0.12);
  --topbar: rgba(247, 244, 233, .92);
  --soft-surface: rgba(255, 255, 255, .52);
  --focus-ring: rgba(39, 90, 71, .1);
  --user-avatar: #e5e0d0;
  --stamp-bg: #e1ece5;
  --stamp-ink: #295442;
  --ruling-bg: #fff9e5;
  --community-bg: #f5e8e2;
  --community-ink: #704536;
  --community-strong: #5e3023;
  --modal-backdrop: rgba(10, 25, 18, .62);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #eef4ef;
  --ink-soft: #a8b7ae;
  --paper: #0f1713;
  --surface: #17231d;
  --line: #34453b;
  --forest: #102d23;
  --forest-2: #5fac88;
  --gold: #f1c35a;
  --accent-ink: #13251d;
  --rust: #ef8a68;
  --blue: #75a9ce;
  --shadow: 0 20px 60px rgba(0, 0, 0, .34);
  --topbar: rgba(15, 23, 19, .92);
  --soft-surface: rgba(255, 255, 255, .035);
  --focus-ring: rgba(95, 172, 136, .18);
  --user-avatar: #313c35;
  --stamp-bg: #20372c;
  --stamp-ink: #9dd3b6;
  --ruling-bg: #292719;
  --community-bg: #31231f;
  --community-ink: #e4b3a4;
  --community-strong: #f2c4b6;
  --modal-backdrop: rgba(0, 0, 0, .72);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  color: var(--ink);
  background: var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body.app-loading { overflow: hidden; }
body.app-loading .app-shell,
body.app-loading > dialog,
body.app-loading > .toast { visibility: hidden; }
.app-loading-screen {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; gap: 16px;
  color: #f8f5e8; background: var(--forest); opacity: 1; visibility: visible;
  transition: opacity .18s ease, visibility .18s ease;
}
body:not(.app-loading) .app-loading-screen { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-brand-mark {
  display: grid; place-items: center; width: 54px; aspect-ratio: 1; border-radius: 14px;
  color: var(--accent-ink); background: var(--gold); font-family: Fraunces, serif; font-size: 1.15rem; font-weight: 750;
  transform: rotate(-2deg); box-shadow: 5px 5px 0 rgba(0,0,0,.2);
}
.loading-eyebrow { margin: 0 0 3px; color: #f1c35a; font-size: .7rem; font-weight: 700; letter-spacing: .12em; }
.loading-copy { margin: 0; color: #d5e1da; font-family: Fraunces, serif; font-size: 1.2rem; font-weight: 650; }

button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 292px minmax(0, 1fr); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 292px;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  color: #f8f5e8;
  background: var(--forest);
  overflow-y: auto;
  z-index: 20;
}

.brand-row, .game-identity { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; aspect-ratio: 1; border-radius: 11px;
  background: var(--gold); color: var(--accent-ink); font-family: Fraunces, serif; font-weight: 750;
  transform: rotate(-2deg); box-shadow: 4px 4px 0 rgba(0,0,0,.18);
}
.brand-name { font-family: Fraunces, serif; font-size: 1.25rem; font-weight: 750; }
.brand-note { color: #b8c9bf; font-size: .78rem; }

.new-game {
  margin: 28px 0 8px; padding: 11px 14px; border: 1px solid var(--gold); border-radius: 10px;
  color: var(--accent-ink); background: var(--gold); text-align: left; font-weight: 700; cursor: pointer;
}
.new-game:hover, .new-game:focus-visible { filter: brightness(1.05); outline: 2px solid rgba(245,198,93,.32); outline-offset: 2px; }
.add-game-button {
  margin: 0 0 17px; padding: 8px 12px; border: 0; color: #c8d8cf; background: transparent;
  text-align: left; font-size: .83rem; cursor: pointer;
}
.add-game-button:hover, .add-game-button:focus-visible { color: white; text-decoration: underline; outline: none; }

.game-list { display: grid; gap: 5px; }
.game-row { position: relative; }
.game-item {
  width: 100%; display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  padding: 9px 42px 9px 9px; border: 0; border-radius: 11px; color: #dbe7df; background: transparent;
  text-align: left; cursor: pointer;
}
.game-item:hover { background: rgba(255,255,255,.07); }
.game-item.active { color: white; background: rgba(255,255,255,.13); }
.game-remove {
  position: absolute; top: 50%; right: 8px; translate: 0 -50%; width: 28px; height: 28px;
  border: 0; border-radius: 8px; color: #9bb0a4; background: transparent; font-size: 1.2rem;
  line-height: 1; cursor: pointer; opacity: 0; transition: opacity .15s ease, color .15s ease, background .15s ease;
}
.game-row:hover .game-remove, .game-remove:focus-visible { opacity: 1; }
.game-remove:hover, .game-remove:focus-visible { color: white; background: rgba(221,135,109,.2); outline: none; }
.mini-token, .game-token { display: grid; place-items: center; font-family: Fraunces, serif; font-weight: 750; }
.mini-token { width: 34px; height: 34px; border-radius: 9px; color: var(--accent-ink); }
.game-item small { display: block; color: #9bb0a4; font-size: .72rem; margin-top: 1px; }
.game-item.active small { color: #c8d8cf; }
.admin-link { display: block; width: fit-content; margin-top: 12px; text-decoration: none; }
.admin-link[hidden] { display: none; }
.chev { opacity: 0; }
.game-item.active .chev { opacity: .8; }

@media (hover: none) {
  .game-remove { opacity: 1; }
}

.source-key { margin-top: auto; padding: 18px 10px 0; color: #b8c9bf; font-size: .76rem; }
.source-key > div { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.key-title { color: white; font-size: .78rem; font-weight: 700; margin: 0 0 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.official { background: var(--gold); }
.dot.publisher { background: #71b592; }
.dot.community { background: #dd876d; }

.workspace { grid-column: 2; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  min-height: 80px; padding: 14px 34px; border-bottom: 1px solid var(--line);
  background: var(--topbar); backdrop-filter: blur(12px);
}
.game-token { width: 46px; height: 46px; border-radius: 13px; color: var(--accent-ink); background: var(--gold); font-size: 1.35rem; }
.eyebrow { margin: 0 0 2px; color: var(--rust); font-size: .69rem; letter-spacing: .13em; font-weight: 700; }
h1, h2 { font-family: Fraunces, serif; line-height: 1.1; }
h1 { margin: 0; font-size: 1.7rem; }
h2 { margin: 7px 0 10px; font-size: 1.8rem; }
.mobile-library { display: none; border: 0; background: transparent; font-size: 1.35rem; }
.sources-button { padding: 9px 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; }
.sources-button:hover { border-color: #9b9d90; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.auth-button {
  max-width: 190px; padding: 9px 13px; overflow: hidden; border: 1px solid var(--forest); border-radius: 9px;
  color: white; background: var(--forest); font-size: .82rem; font-weight: 700; text-overflow: ellipsis;
  white-space: nowrap; cursor: pointer;
}
.auth-button.signed-in { border-color: var(--line); color: var(--ink); background: var(--surface); font-weight: 600; }
.auth-button:hover, .auth-button:focus-visible { border-color: var(--rust); outline: none; }
.theme-button {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); background: var(--surface); cursor: pointer;
}
.theme-button:hover, .theme-button:focus-visible { border-color: var(--rust); outline: none; }
.theme-icon { font-size: 1.15rem; line-height: 1; transform: translateY(-1px); }

.conversation { width: min(800px, calc(100% - 44px)); margin: 0 auto; padding: 42px 0 245px; }
.conversation.empty-mode { display: flex; flex-direction: column; justify-content: center; min-height: calc(100vh - 80px); padding-top: 30px; }
.welcome { padding: 0 0 28px; border-bottom: 1px solid var(--line); }
.welcome.new-chat-welcome { padding-bottom: 0; border-bottom: 0; text-align: center; }
.welcome.new-chat-welcome h2 { max-width: none; }
.welcome.new-chat-welcome p { max-width: 560px; margin-left: auto; margin-right: auto; }
.new-chat-mark {
  display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 18px; border-radius: 16px;
  color: var(--accent-ink); background: var(--gold); font-family: Fraunces, serif; font-size: 1.25rem; font-weight: 750;
  box-shadow: 5px 5px 0 color-mix(in srgb, var(--ink) 14%, transparent); transform: rotate(-2deg);
}
.welcome h2 { max-width: 580px; margin-top: 5px; font-size: clamp(2rem, 5vw, 3.4rem); }
.welcome p { max-width: 620px; color: var(--ink-soft); margin-bottom: 0; }
.stamp { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border-radius: 7px; background: var(--stamp-bg); color: var(--stamp-ink); font-size: .76rem; font-weight: 700; }

.message { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 14px; padding: 28px 0; }
.message + .message { border-top: 1px solid var(--line); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; font-weight: 700; }
.user .avatar { background: var(--user-avatar); }
.assistant .avatar { color: white; background: var(--forest); font-family: Fraunces, serif; }
.message-label { margin-bottom: 8px; font-size: .76rem; letter-spacing: .08em; font-weight: 700; color: var(--ink-soft); }
.message p { margin: 0 0 13px; }
.answer-lead { font-family: Fraunces, serif; font-size: 1.4rem; line-height: 1.35; }
.inline-citation {
  display: inline-grid; place-items: center; min-width: 1.3rem; height: 1.3rem; margin-left: .22rem;
  border-radius: 50%; color: white; background: var(--forest-2); font-family: "DM Sans", sans-serif;
  font-size: .7rem; font-style: normal; font-weight: 700; line-height: 1; text-decoration: none;
  vertical-align: super;
}
:root[data-theme="dark"] .inline-citation { color: var(--accent-ink); }
.inline-citation:hover, .inline-citation:focus-visible { background: var(--rust); outline: none; }

.ruling {
  margin: 18px 0; padding: 16px 17px; border-left: 4px solid var(--gold); border-radius: 0 10px 10px 0;
  background: var(--ruling-bg);
}
.ruling strong { display: block; margin-bottom: 3px; }
.community-note { display: flex; gap: 10px; margin: 18px 0; padding: 13px 15px; border-radius: 10px; background: var(--community-bg); color: var(--community-ink); font-size: .9rem; }
.community-note strong { color: var(--community-strong); }
.game-choice-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.game-choice {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink);
  background: var(--surface); cursor: pointer;
}
.game-choice:hover, .game-choice:focus-visible { border-color: var(--rust); outline: none; }
.game-choice.route-primary { border-color: var(--forest); color: white; background: var(--forest); font-weight: 700; }
.route-confirmation { border-top-color: var(--gold) !important; }

.sources-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 22px; }
.variant-note { display: inline-flex; margin: 2px 0 12px !important; padding: 5px 9px; border-radius: 999px; color: var(--ink-soft); background: var(--soft-surface); font-size: .78rem; }
.move-answer-button {
  margin-top: 14px; padding: 7px 0; border: 0; color: var(--ink-soft); background: transparent;
  font-size: .78rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.move-answer-button:hover, .move-answer-button:focus-visible { color: var(--rust); outline: none; }
.sources-heading span { color: var(--ink-soft); font-size: .75rem; text-align: right; }
.citations { display: grid; gap: 8px; margin-top: 9px; }
.citation {
  display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; color: inherit; background: var(--soft-surface); text-decoration: none;
}
.citation:hover { border-color: var(--rust); background: var(--surface); }
.source-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--accent-ink); font-size: .8rem; font-weight: 700; }
.source-icon.official { background: #fff0bb; }
.source-icon.publisher { background: #dceee4; }
.source-icon.community { background: #f2dcd4; }
.source-icon.reference { background: #dce7ef; }
.citation-title { font-size: .88rem; font-weight: 700; }
.page-reference { display: inline-flex; margin-left: 6px; padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--rust); font-family: var(--sans); font-size: .68rem; font-weight: 800; white-space: nowrap; }
.citation-meta { color: var(--ink-soft); font-size: .73rem; }
.confidence { display: inline-flex; align-items: center; gap: 6px; color: #2d5b48; font-size: .78rem; font-weight: 700; }

.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #7d8b82; animation: pulse 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 70%, 100% { opacity: .3; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.composer-wrap {
  position: fixed; left: 292px; right: 0; bottom: 0; z-index: 9; padding: 14px 22px 18px;
  background: linear-gradient(0deg, var(--paper) 74%, rgba(247,244,233,0));
}
.composer-wrap > * { width: min(800px, 100%); margin-left: auto; margin-right: auto; }
.suggestions { display: flex; gap: 8px; padding-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.suggestion { flex: none; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .79rem; cursor: pointer; }
.suggestion:hover { border-color: var(--rust); }
.composer {
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; padding: 10px 10px 10px 16px;
  border: 1px solid #b6b8aa; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--forest-2); box-shadow: 0 0 0 3px var(--focus-ring), var(--shadow); }
.composer textarea { resize: none; max-height: 140px; min-height: 29px; padding: 4px 0; border: 0; outline: 0; background: transparent; color: var(--ink); }
.send-button { display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--forest); cursor: pointer; }
.send-button svg { width: 22px; fill: none; stroke: white; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.composer-note { margin-top: 7px; margin-bottom: 0; color: #6f756f; font-size: .72rem; text-align: center; }

.modal { width: min(520px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 18px; background: transparent; box-shadow: var(--shadow); }
.modal::backdrop { background: var(--modal-backdrop); backdrop-filter: blur(3px); }
.modal-card { position: relative; display: flex; flex-direction: column; padding: 30px; border-radius: 18px; background: var(--surface); }
.modal-copy { color: var(--ink-soft); margin: 0 0 22px; }
.modal-close { position: absolute; top: 15px; right: 16px; border: 0; background: transparent; font-size: 1.6rem; cursor: pointer; }
.modal label { margin: 12px 0 6px; font-size: .85rem; font-weight: 700; }
.modal label span { color: var(--ink-soft); font-weight: 400; }
.modal input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: var(--paper); }
.auth-modal { width: min(450px, calc(100% - 28px)); }
.google-button {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 12px 15px;
  border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface);
  font-weight: 700; cursor: pointer;
}
.google-button:hover, .google-button:focus-visible { border-color: var(--rust); outline: none; }
.google-mark { display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; color: white; background: #4285f4; font-weight: 700; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 4px; color: var(--ink-soft); font-size: .76rem; text-transform: uppercase; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.auth-submit { width: 100%; margin-top: 16px; }
.auth-status { min-height: 1.4em; margin: 14px 0 0; color: var(--ink-soft); font-size: .82rem; }
.auth-status.error { color: var(--rust); }
.account-plan { display: grid; gap: 3px; margin: 0 0 22px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft-surface); }
.account-plan strong { font-family: Fraunces, serif; font-size: 1.05rem; }
.account-plan span { color: var(--ink-soft); font-size: .82rem; }
.billing-button { width: 100%; margin: 0 0 10px; }
.billing-button[hidden] { display: none; }
#billingStatus { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.move-game-choices { margin: 0 0 14px; }
#moveGameForm { display: block; }
.primary-button, .secondary-button { padding: 12px 15px; border-radius: 10px; font-weight: 700; cursor: pointer; }
.primary-button { border: 0; color: white; background: var(--forest); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.secondary-button:hover { border-color: var(--rust); }
.sources-modal { width: min(650px, calc(100% - 28px)); }
.source-library { display: grid; gap: 10px; margin-top: 14px; }
.library-card { padding: 14px; border: 1px solid var(--line); border-radius: 11px; }
.library-card p { color: var(--ink-soft); font-size: .82rem; margin: 5px 0 0; }
.library-card a { color: var(--forest-2); font-weight: 700; }
.reference-library-title { margin: 24px 2px 10px; font-family: Fraunces, serif; font-size: 1.05rem; }
.toast { position: fixed; left: 50%; bottom: 154px; z-index: 50; padding: 10px 14px; border-radius: 9px; color: white; background: #15281f; opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.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; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { width: min(310px, 86vw); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  body.library-open .sidebar { transform: translateX(0); }
  body.library-open::after { content: ""; position: fixed; inset: 0; z-index: 15; background: rgba(10,25,18,.44); }
  .workspace { min-height: 100dvh; }
  .topbar { min-height: 68px; padding: 10px 14px; }
  .mobile-library { display: block; padding: 8px; }
  .game-identity { margin-right: auto; }
  .game-token { width: 39px; height: 39px; border-radius: 11px; font-size: 1.1rem; }
  h1 { font-size: 1.35rem; }
  .sources-button { padding: 8px 9px; font-size: .8rem; }
  .auth-button { max-width: 90px; padding: 8px 9px; }
  .theme-button { width: 36px; height: 36px; }
  .conversation { width: calc(100% - 30px); padding: 30px 0 235px; }
  .conversation.empty-mode { min-height: calc(100dvh - 68px); padding-top: 20px; }
  .welcome h2 { font-size: 2.25rem; }
  .message { grid-template-columns: 34px minmax(0,1fr); gap: 10px; padding: 24px 0; }
  .avatar { width: 32px; height: 32px; border-radius: 9px; font-size: .8rem; }
  .answer-lead { font-size: 1.25rem; }
  .citation { grid-template-columns: auto 1fr; }
  .confidence { grid-column: 2; }
  .composer-wrap { left: 0; padding: 12px 14px 13px; }
  .composer-note { font-size: .68rem; }
  .modal-card { padding: 26px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
