:root {
    color-scheme: dark;
    --bg: #17140f;
    --sidebar: #12100d;
    --panel: #201b15;
    --panel-raised: #282117;
    --line: #3b3023;
    --text: #f5ede0;
    --muted: #bcb0a0;
    --quiet: #aa9d8c;
    --gold: #e7b778;
    --gold-light: #f9d6a0;
    --danger: #f3a6a0;
    --success: #add1ac;
    --sans: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    --serif: "Songti SC", STSong, SimSun, Georgia, serif;
    font: 16px/1.6 var(--sans);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.6; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; z-index: 20; inset: 0 auto auto 0; transform: translateY(-110%); padding: 0.5rem 1rem; background: var(--gold); color: var(--sidebar); }
.skip-link:focus { transform: none; }

.shell { display: grid; grid-template-columns: 14.5rem minmax(0, 1fr); min-height: 100dvh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100dvh; padding: 1.85rem 1.1rem 1.3rem; background: var(--sidebar); border-right: 1px solid #2e251c; }
.brand { display: flex; align-items: center; gap: 0.7rem; width: fit-content; min-height: 2.4rem; padding-inline: 0.48rem; }
.brand strong { font-family: var(--serif); font-size: 1.39rem; letter-spacing: 0.06em; font-weight: 700; white-space: nowrap; }
.brand-symbol { display: grid; flex: 0 0 2.15rem; width: 2.15rem; height: 2.15rem; place-items: center; border: 1px solid #745437; border-radius: 0.62rem; color: var(--gold-light); background: linear-gradient(145deg, #3d2a1b, #231912); }
.brand-symbol span { position: relative; width: 0.8rem; height: 0.62rem; margin: -0.11rem 0.12rem 0 0; border: 1px solid currentColor; border-bottom-left-radius: 0.25rem; border-bottom-right-radius: 0.25rem; }
.brand-symbol span::before { content: ''; position: absolute; top: 0.08rem; right: -0.24rem; width: 0.23rem; height: 0.31rem; border: 1px solid currentColor; border-left: 0; border-radius: 0 0.22rem 0.22rem 0; }
.brand-symbol span::after { content: ''; position: absolute; left: -0.13rem; bottom: -0.23rem; width: 1.14rem; border-bottom: 1px solid currentColor; border-radius: 50%; }
.navigation { display: grid; gap: 0.28rem; margin-top: 2.85rem; }
.nav-link { min-height: 2.75rem; display: flex; align-items: center; gap: 0.7rem; padding: 0.47rem 0.7rem; border: 1px solid transparent; border-radius: 0.62rem; font-size: 0.93rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.nav-link:hover, .nav-link:focus-visible { color: var(--text); background: #251d14; }
.nav-link[aria-current="page"] { color: var(--gold-light); background: #342719; border-color: #4e3925; }
.nav-icon { display: inline-block; position: relative; flex: 0 0 1.05rem; width: 1.05rem; height: 1.05rem; }
.icon-compass { border: 1px solid currentColor; border-radius: 50%; }
.icon-compass::after { content: ''; position: absolute; inset: 0.26rem; border: 1px solid currentColor; transform: rotate(45deg); }
.icon-chat { border: 1px solid currentColor; border-radius: 0.26rem; height: 0.8rem; }
.icon-chat::after { content: ''; position: absolute; left: 0.16rem; bottom: -0.18rem; width: 0.3rem; height: 0.27rem; border-left: 1px solid currentColor; transform: skewY(-39deg); }
.icon-credit { border: 1px solid currentColor; border-radius: 50%; }
.icon-credit::after { content: ''; position: absolute; left: 0.27rem; right: 0.27rem; top: 0.43rem; border-top: 1px solid currentColor; }
.icon-admin { border: 1px solid currentColor; border-radius: 0.16rem; }
.icon-admin::after { content: ''; position: absolute; left: 0.22rem; right: 0.22rem; top: 0.25rem; height: 0.46rem; border-top: 1px solid currentColor; border-bottom: 1px solid currentColor; }
.sidebar-end { margin-top: auto; padding: 0.65rem 0.5rem 0; color: var(--quiet); font-size: 0.875rem; }
.sidebar-end:empty { display: none; }

.workspace { min-width: 0; }
.topbar { min-height: 4.35rem; display: flex; align-items: center; gap: 1rem; justify-content: space-between; padding: 0.66rem clamp(1rem, 3vw, 3.2rem); border-bottom: 1px solid #32291f; }
.topbar-location { color: var(--muted); font-size: 0.93rem; font-weight: 650; white-space: nowrap; }
.account-bar { display: flex; align-items: center; gap: 0.65rem; justify-content: flex-end; min-width: 0; }
.account-name { max-width: min(10rem, 22vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.875rem; }
.balance-chip { display: inline-flex; align-items: center; gap: 0.28rem; min-height: 2.13rem; padding: 0.12rem 0.65rem; font-size: 0.88rem; color: var(--gold-light); border: 1px solid #5a432b; background: #302416; border-radius: 2rem; white-space: nowrap; }
.balance-chip:hover { background: #40301e; }
main { max-width: 90rem; margin-inline: auto; padding: 2rem clamp(1rem, 3vw, 3.2rem) 3.5rem; }
.button { display: inline-flex; min-height: 2.55rem; align-items: center; justify-content: center; gap: 0.4rem; border: 1px solid var(--line); padding: 0.46rem 0.87rem; border-radius: 0.57rem; color: var(--text); background: #2a231a; font-size: 0.9rem; font-weight: 700; white-space: nowrap; }
.button:hover { background: #392e21; }
.button-primary { border-color: #dca668; color: #25170e; background: var(--gold); }
.button-primary:hover { background: var(--gold-light); }
.button-quiet { border-color: transparent; color: var(--muted); background: transparent; }
.button-quiet:hover { border-color: var(--line); color: var(--text); }
.button-small { min-height: 2.15rem; font-size: 0.86rem; padding-inline: 0.63rem; }
.text-button { color: var(--gold-light); background: transparent; border: 0; font-weight: 600; font-size: 0.88rem; }
.text-button:hover { color: var(--text); }

.hero { min-height: clamp(17rem, 29vw, 24rem); display: flex; align-items: center; border: 1px solid #59422c; border-radius: 1.05rem; isolation: isolate; background: linear-gradient(90deg, rgba(22, 16, 11, .96), rgba(26, 18, 12, .77) 44%, rgba(25, 16, 10, .22) 73%), url('/assets/tavern-hero.png') center 47%/cover no-repeat, radial-gradient(ellipse at 77% 43%, #92633a, #352519 42%, #1c140f 75%); }
.hero-copy { max-width: 38rem; padding: clamp(1.45rem, 4vw, 3.5rem); }
.hero h1 { font-family: var(--serif); font-size: clamp(2.25rem, 4.6vw, 4.65rem); font-weight: 700; line-height: 1.12; color: #fff2db; text-wrap: balance; letter-spacing: -.045em; }
.hero h1 span { white-space: nowrap; }
.hero p { margin-top: 0.95rem; max-width: 24rem; color: #e3d0b9; text-wrap: pretty; }
.hero .button { margin-top: 1.4rem; }
.section-heading { display: flex; flex-wrap: wrap; gap: 0.6rem 1.1rem; align-items: baseline; justify-content: space-between; margin: 2.3rem 0 1rem; }
.section-heading h2, .page-head h1 { font-family: var(--serif); letter-spacing: .025em; line-height: 1.25; font-size: 1.66rem; }
.page-head { margin-bottom: 1.32rem; }
.page-head h1 { font-size: 2.1rem; }
.page-head p, .muted { color: var(--muted); }
.page-head p { margin-top: 0.45rem; }
.role-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.role-card { min-width: 0; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: .82rem; overflow: hidden; }
.role-art, .chat-emblem { --role-light:#bb845b; --role-dark:#3e271e; }
.role-art { position: relative; display: grid; align-items: end; justify-items: start; overflow: hidden; min-height: 8.55rem; padding: 0.8rem 1rem; background: radial-gradient(ellipse at 80% 34%, var(--role-light), transparent 67%), linear-gradient(145deg, var(--role-dark), #211913); border-bottom: 1px solid #4a392a; }
.role-art::before { content: ''; position: absolute; right: -1.15rem; top: -3.6rem; width: 13.2rem; height: 10.2rem; border: 1px solid rgba(255,247,224,.22); border-radius: 100% 100% 0 0; transform: rotate(-20deg); box-shadow: 0 0 0 1.2rem rgba(255,245,220,.045), 0 0 0 2.45rem rgba(255,245,220,.028); }
.role-art::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 27%, #180e0a77); }
.role-art .role-monogram { position: relative; z-index: 1; font: 4.5rem/.95 var(--serif); color: #fff0d5; opacity: .84; }
.role-picture { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 39%; }
.has-role-picture .role-monogram { visibility: hidden; }
.has-role-picture::after { background: linear-gradient(180deg, transparent 72%, #180e0a35); }
.palette-jade { --role-light: #799284; --role-dark: #273a33; }
.palette-ink { --role-light: #737f9b; --role-dark: #2d344b; }
.palette-plum { --role-light: #8b698a; --role-dark: #432b40; }
.palette-gold { --role-light: #a68e59; --role-dark: #463b20; }
.palette-blue { --role-light: #697e8b; --role-dark: #293b45; }
.role-card-content { display: grid; align-content: start; gap: 0.52rem; flex: 1; padding: .95rem 1rem 1rem; }
.role-card-content h3 { font: 700 1.4rem/1.25 var(--serif); overflow-wrap: anywhere; }
.role-tagline { color: var(--muted); font-size: .89rem; }
.role-description { color: var(--muted); overflow-wrap: anywhere; min-height: 2.8em; font-size: .94rem; }
.tag-row { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.06rem; }
.tag { padding: .07rem .44rem; border: 1px solid #59432d; color: #e5c79e; background: #302417; border-radius: .35rem; font-size: .8125rem; }
.role-card-content .button { justify-self: start; margin-top: .4rem; }

.empty-panel, .error-panel, .loading-panel { display: grid; gap: .7rem; padding: 1.3rem; justify-items: start; border: 1px solid var(--line); background: var(--panel); border-radius: .72rem; color: var(--muted); }
.error-panel, .inline-error { color: var(--danger); }
.loading-panel { color: var(--muted); }
.profile-line { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
.history-list { display: grid; gap: .65rem; }
.history-row { display: flex; justify-content: space-between; align-items: center; gap: .9rem; padding: .92rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: .63rem; }
.history-row:hover { border-color: #775838; }
.history-row strong { overflow-wrap: anywhere; }
.history-row p { color: var(--muted); font-size: .88rem; }
.history-row time { color: var(--quiet); white-space: nowrap; font-size: .83rem; }

.chat-shell { display: flex; flex-direction: column; min-height: min(39rem, 77dvh); background: var(--panel); border: 1px solid var(--line); border-radius: .8rem; overflow: hidden; }
.chat-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.chat-identity { display: flex; gap: .65rem; align-items: center; min-width: 0; }
.chat-emblem { display: grid; flex: 0 0 2.48rem; width: 2.48rem; height: 2.48rem; place-items: center; border-radius: .58rem; border: 1px solid #7f6145; background: radial-gradient(at 78% 10%, var(--role-light), var(--role-dark)); color: #fff1d7; font: 700 1.45rem/1 var(--serif); }
.chat-identity h1 { font-family: var(--serif); line-height: 1.15; font-size: 1.63rem; overflow-wrap: anywhere; }
.chat-identity p { font-size: .87rem; color: var(--muted); }
.model-control { display: grid; width: min(20.2rem, 50%); gap: .2rem; }
.model-control label { color: var(--muted); font-size: .85rem; }
.model-price { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.message-list { display: flex; flex: 1; min-height: 15rem; max-height: min(47rem, 62dvh); flex-direction: column; align-items: flex-start; gap: 1.14rem; padding: 1.1rem clamp(1rem, 3vw, 2rem); overflow-y: auto; overscroll-behavior: contain; }
.message { max-width: min(87%, 46rem); }
.message-user { align-self: flex-end; }
.message-author { margin-bottom: .24rem; color: var(--muted); font-size: .83rem; }
.message-user .message-author { text-align: right; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; padding: .7rem .9rem; border: 1px solid #4b3b2b; border-radius: .71rem; color: var(--text); background: #2c231a; }
.message-user .message-content { background: #43301d; border-color: #624629; }
.message-points { margin-top: .2rem; color: var(--quiet); font-size: .82rem; }
.composer { display: grid; gap: .58rem; padding: .84rem 1rem 1rem; border-top: 1px solid var(--line); }
.composer textarea { resize: vertical; min-height: 4.6rem; max-height: 18rem; }
.composer-footer { display: flex; gap: .65rem; justify-content: space-between; align-items: center; }
.composer-footer p { color: var(--muted); font-size: .83rem; }
.composer-status:empty { display: none; }

input, textarea, select { min-width: 0; width: 100%; padding: .48rem .64rem; min-height: 2.55rem; color: var(--text); background: #16120e; border: 1px solid #564430; border-radius: .55rem; }
input::placeholder, textarea::placeholder { color: #a99b87; }
select { appearance: none; padding-right: 1.9rem; background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%), linear-gradient(135deg, var(--gold) 50%, transparent 50%); background-position: calc(100% - 1rem) 51%, calc(100% - .72rem) 51%; background-size: .31rem .31rem; background-repeat: no-repeat; }
.field { display: grid; gap: .23rem; }
.field label, label.field { color: var(--muted); font-size: .88rem; font-weight: 650; }
.inline-error:empty { display: none; }

.balance-card { display: flex; align-items: baseline; gap: .6rem; padding: 1rem 1.15rem; margin-bottom: 1rem; border: 1px solid #695136; border-radius: .67rem; background: linear-gradient(125deg,#382819,#251d14); }
.balance-card strong { font-size: 2.1rem; line-height: 1; color: var(--gold-light); }
.panel { margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: .72rem; background: var(--panel); }
.panel > h2 { margin: 0 0 .7rem; font-size: 1.19rem; }
.table-wrap { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .89rem; }
th, td { padding: .54rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); white-space: nowrap; }
td { overflow-wrap: anywhere; }
td:first-child, th:first-child { padding-left: .12rem; }
td:last-child, th:last-child { padding-right: .12rem; }
tbody tr:last-child td { border-bottom: 0; }
.amount-positive { color: var(--success); white-space: nowrap; }
.amount-negative { color: var(--gold-light); white-space: nowrap; }
.nowrap { white-space: nowrap; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .68rem; margin-bottom: 1.05rem; }
.stat { padding: .77rem .86rem; border: 1px solid var(--line); border-radius: .65rem; background: var(--panel); }
.stat p { font-size: .88rem; color: var(--muted); }
.stat strong { font-size: 1.48rem; line-height: 1.15; }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: .62rem; padding-bottom: .76rem; }
.inline-form .field { flex: 1 1 8rem; }
.inline-form .button { flex: 0 0 auto; }
.invite-result { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: 0 0 .7rem; padding: .57rem .7rem; background: #302619; border-radius: .5rem; }
.invite-result code { color: var(--gold-light); user-select: all; overflow-wrap: anywhere; }
.table-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem; }
.point-editor { width: min(31rem, 100%); }
.auth-dialog { color: var(--text); position: fixed; width: min(26rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); margin: auto; overflow-y: auto; background: #211a14; border: 1px solid #6b5035; border-radius: .96rem; padding: 1.45rem; box-shadow: 0 1.3rem 4.5rem #0009; }
.auth-dialog::backdrop { background: #120e0acc; }
.auth-dialog h2 { margin-right: 1.9rem; font-family: var(--serif); font-size: 1.75rem; }
.auth-intro { margin: .18rem 0 .85rem; color: var(--muted); font-size: .91rem; }
.close-button { position: absolute; top: .92rem; right: .9rem; width: 2.2rem; height: 2.2rem; background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: .4rem; font-size: 1.6rem; line-height: 1; }
.close-button:hover { background: #392a1a; }
.segmented { display: flex; margin-bottom: .9rem; background: #15110d; border: 1px solid var(--line); border-radius: .58rem; padding: .16rem; }
.segmented button { flex: 1; min-height: 2.25rem; background: transparent; border: 0; border-radius: .43rem; color: var(--muted); font-size: .88rem; font-weight: 650; }
.segmented button[aria-pressed="true"] { color: var(--gold-light); background: #3c2b1c; }
.auth-form { display: grid; gap: .43rem; }
.auth-form label { color: var(--muted); font-size: .88rem; font-weight: 650; }
.auth-form label[for="auth-password"] { margin-top: .34rem; }
.auth-form .button { margin-top: .48rem; }
.password-input { position: relative; }
.password-input input { padding-right: 5.45rem; }
.password-input button { position: absolute; right: .25rem; top: 50%; min-height: 2rem; transform: translateY(-50%); }
.auth-invite-field { display: grid; gap: .43rem; margin-top: .34rem; }
.toast { position: fixed; z-index: 9; bottom: 1.3rem; right: 1.3rem; max-width: min(24rem, calc(100vw - 2.6rem)); padding: .6rem .9rem; color: var(--text); background: #33271b; border: 1px solid #785735; border-radius: .6rem; box-shadow: 0 .4rem 1.8rem #0007; }

@media (max-width: 1040px) {
    .shell { grid-template-columns: 12rem minmax(0, 1fr); }
    .sidebar { padding-inline: .75rem; }
    .hero { min-height: 18rem; }
}
@media (max-width: 800px) {
    .shell { display: block; }
    .sidebar { position: relative; top: auto; height: auto; padding: .69rem 1rem .33rem; border-right: 0; border-bottom: 1px solid var(--line); }
    .brand { padding-left: 0; }
    .navigation { display: flex; flex-wrap: wrap; gap: .3rem; margin: .55rem 0 0; }
    .nav-link { min-height: 2.52rem; padding: .32rem .5rem; font-size: .86rem; gap: .34rem; }
    .sidebar-end { display: none; }
    .role-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    main { padding-top: 1.2rem; }
}
@media (max-width: 525px) {
    .topbar { min-height: 3.65rem; gap: .45rem; }
    .topbar-location { font-size: .87rem; }
    .account-bar { gap: .25rem; }
    .account-name { display: none; }
    .topbar .button { min-height: 2.25rem; font-size: .85rem; padding-inline: .5rem; }
    .hero { min-height: 16.2rem; background-position: center, 62% center, center; }
    .hero-copy { padding: 1.45rem 1.25rem; }
    .hero p { font-size: .95rem; }
    .role-grid { grid-template-columns: minmax(0, 1fr); }
    .role-art { min-height: 7.1rem; }
    .role-card-content { gap: .42rem; }
    .role-description { min-height: 0; }
    .chat-heading { flex-direction: column; gap: .68rem; padding: .8rem; }
    .model-control { width: 100%; }
    .message-list { padding-inline: .76rem; }
    .message { max-width: 95%; }
    .composer { padding: .7rem .76rem .76rem; }
    .composer-footer p { line-height: 1.35; }
    .history-row { flex-wrap: wrap; gap: .26rem; }
    .history-row time { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; }
}
