/* base.css — layout & components. No literal colors/fonts: tokens only. */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    color: var(--ink);
    background-color: var(--bg-page);
    background-image: var(--bg-page-image);
    background-attachment: fixed;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* -- login gates -- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
    width: min(420px, 100%); display: flex; flex-direction: column; gap: 16px;
    text-align: center; padding: 40px 32px;
    background: var(--bg-panel); background-image: var(--bg-panel-image);
    border: var(--border-panel); border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
}
.login-d20 { align-self: center; color: var(--accent-icon); }
.login-title { margin: 0; font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: .04em; color: var(--ink-title); }
.login-card h2 { margin: 0; font-family: var(--font-display); font-size: 18px; }
.login-card p { margin: 0; color: var(--ink-muted); line-height: 1.5; }
.login-signed-in { font-size: 14px; }
.login-card input {
    height: 44px; padding: 0 14px; border: var(--border-inset);
    border-radius: var(--radius-sm); background: var(--bg-input); color: var(--ink);
}
.login-error { color: var(--accent); font-size: 14px; }

/* -- buttons -- */
.btn-primary {
    height: 44px; padding: 0 22px; border: none; cursor: pointer;
    border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent);
    font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }
.icon-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0; cursor: pointer;
    background: transparent; border: none; border-radius: var(--radius-sm);
    color: var(--ink-muted);
}
.icon-btn:hover { background: var(--bg-inset); color: var(--ink); }

/* -- shell & top bar -- */
.shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
    height: 56px; flex: 0 0 auto; display: flex; align-items: center;
    justify-content: space-between; gap: 12px; padding: 0 16px;
    background: var(--bg-header); border-bottom: var(--border-strong);
}
.brand {
    display: flex; align-items: center; gap: 10px; min-width: 0;
    font-family: var(--font-display); font-size: 17px; font-weight: 600;
    letter-spacing: .05em; color: var(--ink-title);
}
.brand svg { color: var(--accent-icon); flex: 0 0 auto; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.theme-select {
    height: 34px; padding: 0 8px; border: var(--border-inset);
    border-radius: var(--radius-sm); background: var(--bg-input); color: var(--ink);
    font-size: 13px;
}
.user-name { font-size: 13px; color: var(--ink-muted); white-space: nowrap; }

/* -- header menu -- */
.menu { position: relative; }
.menu-dropdown {
    position: absolute; right: 0; top: 42px; z-index: 30;
    display: flex; flex-direction: column; gap: 8px; padding: 10px; width: 240px;
    background: var(--bg-panel); border: var(--border-panel);
    border-radius: var(--radius); box-shadow: var(--shadow-panel);
}
.menu-form { display: flex; gap: 6px; }
.menu-form input {
    flex: 1; min-width: 0; height: 34px; padding: 0 10px;
    border: var(--border-inset); border-radius: var(--radius-sm);
    background: var(--bg-input); color: var(--ink); font-size: 13px;
}
.menu-item {
    height: 36px; border: none; background: transparent; cursor: pointer;
    border-radius: var(--radius-sm); color: var(--ink); text-align: left;
    padding: 0 8px; font-size: 14px;
}
.menu-item:hover { background: var(--bg-inset); }

/* -- panes grid -- */
.panes {
    flex: 1; min-height: 0; position: relative;
    display: grid; grid-template-columns: 288px minmax(0, 1fr) 324px;
    gap: 12px; padding: 12px;
}
.pane { min-height: 0; }
.pane-left, .card {
    background: var(--bg-panel); background-image: var(--bg-panel-image);
    border: var(--border-panel); border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
}
.pane-left { overflow-y: auto; padding: 16px; }
.pane-center {
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--bg-panel); background-image: var(--bg-panel-image);
    border: var(--border-panel); border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
}
.pane-right { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.card { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; flex: 0 0 auto; }
.card-feed { flex: 1 1 auto; min-height: 120px; }
.card-label {
    display: flex; align-items: center; justify-content: space-between; gap: 7px;
    font-family: var(--font-display); font-size: 11px; font-weight: 600;
    letter-spacing: .13em; text-transform: uppercase; color: var(--ink-muted);
}
.card-label svg { flex: 0 0 auto; }
.card-label-accent { display: flex; align-items: center; gap: 7px; color: var(--accent); }

/* -- chat -- */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; }
.message { max-width: 640px; line-height: 1.6; }
.gm-message { align-self: flex-start; }
.user-message {
    align-self: flex-end; max-width: 460px; padding: 10px 14px;
    background: var(--bg-user-msg); border: var(--border-inset);
    border-radius: var(--radius); font-size: 14px;
}
.history-message { opacity: .75; }
.stream-status {
    display: flex; align-items: center; gap: 8px; font-size: 13px;
    font-style: italic; color: var(--gold);
}
.streaming .stream-text::after { content: "▋"; opacity: .6; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* -- error frames in chat -- */
.error-message-chat {
    align-self: stretch; padding: 14px; border-radius: var(--radius);
    background: var(--accent); color: var(--on-accent);
}
.error-message-chat .error-title { font-weight: 700; margin-bottom: 6px; }
.error-message-chat .error-details { font-size: 12px; opacity: .8; margin-top: 6px; }
.retry-button {
    margin-top: 10px; height: 34px; padding: 0 14px; border: none; cursor: pointer;
    border-radius: var(--radius-sm); background: var(--gold); color: var(--bg-page);
    font-weight: 600; font-size: 13px;
}

/* -- reconnect banner & composer -- */
.banner {
    flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
    gap: 12px; padding: 8px 16px; font-size: 13px;
    background: var(--bg-inset); border-top: var(--border-strong); color: var(--gold);
}
.composer {
    flex: 0 0 auto; display: flex; gap: 10px; padding: 14px 16px;
    background: var(--bg-header); border-top: var(--border-strong);
    border-radius: 0 0 var(--radius) var(--radius);
}
.composer input {
    flex: 1; min-width: 0; height: 44px; padding: 0 14px;
    border: var(--border-inset); border-radius: var(--radius-sm);
    background: var(--bg-input); color: var(--ink);
}

/* -- character sheet (left pane content, rendered by sheet.js) -- */
.sheet { display: flex; flex-direction: column; gap: 14px; }
.sheet-empty { color: var(--ink-muted); font-style: italic; line-height: 1.5; }
.sheet-party-label {
    display: flex; align-items: center; gap: 8px;
    font-family: var(--font-display); font-size: 11px; font-weight: 600;
    letter-spacing: .13em; text-transform: uppercase; color: var(--ink-muted);
}
.sheet-party-label::after { content: ""; flex: 1; height: 1px; background: var(--border-color); }
.sheet-name { font-family: var(--font-display); font-size: 21px; font-weight: 600; color: var(--ink-title); }
.sheet-sub { font-size: 13px; color: var(--ink-muted); }
.sheet-row-label {
    font-family: var(--font-display); font-size: 10px; font-weight: 600;
    letter-spacing: .13em; text-transform: uppercase; color: var(--ink-muted);
}
.hp-header { display: flex; justify-content: space-between; align-items: baseline; }
.hp-value { font-weight: 700; color: var(--hp-fill); }
.hp-max { font-weight: 400; color: var(--ink-muted); }
.hp-track { height: 9px; margin-top: 5px; background: var(--hp-track); border-radius: 5px; overflow: hidden; }
.hp-fill { height: 100%; background: var(--hp-fill); border-radius: 5px; transition: width .5s ease; }
.defense-row { display: flex; gap: 8px; }
.defense-tile {
    flex: 1; display: flex; align-items: center; gap: 9px; padding: 9px 11px;
    background: var(--bg-inset); border: var(--border-inset); border-radius: var(--radius-sm);
}
.defense-tile svg { color: var(--gold); flex: 0 0 auto; }
.defense-num { font-weight: 800; font-size: 16px; }
.defense-cap { font-size: 11px; color: var(--ink-muted); }
.abilities { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.ability {
    display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 2px;
    background: var(--bg-inset); border: var(--border-inset); border-radius: var(--radius-sm);
}
.ability-key { font-size: 10px; font-weight: 700; letter-spacing: .1em; color: var(--ink-muted); }
.ability-score { font-weight: 800; font-size: 16px; }
.ability-mod { font-size: 12px; font-weight: 700; color: var(--gold); }
.ability-mod-zero { color: var(--ink-muted); }
.sheet-list { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.sheet-muted { color: var(--ink-muted); font-size: 13px; line-height: 1.5; }
.condition-chip {
    display: inline-block; padding: 2px 10px; margin: 2px 4px 2px 0;
    background: var(--bg-inset); border: 1px solid var(--accent);
    border-radius: 999px; font-size: 12px; color: var(--accent);
}

/* -- combat card -- */
.combat-list { display: flex; flex-direction: column; gap: 3px; }
.combat-row {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    border-radius: var(--radius-sm); font-size: 14px;
}
.combat-row.active-turn { background: var(--bg-row-active); border: var(--border-inset); font-weight: 700; }
.combat-init { width: 20px; text-align: center; font-weight: 700; color: var(--ink-muted); }
.combat-row.active-turn .combat-init { color: var(--gold); }
.combat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combat-name.defeated { text-decoration: line-through; opacity: .55; }
.combat-hp { width: 80px; }
.combat-hp .hp-track { height: 5px; margin-top: 0; }
.combat-hp-num { display: block; font-size: 11px; color: var(--ink-muted); text-align: right; margin-top: 3px; }
.turn-tag { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--gold); }

/* -- quests & feed -- */
.quest-list { display: flex; flex-direction: column; gap: 10px; }
.quest-goal { font-weight: 700; font-size: 13.5px; }
.quest-notes { font-size: 12.5px; color: var(--ink-muted); }
.feed-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.feed-row {
    display: flex; gap: 10px; align-items: flex-start; padding: 9px 0;
    border-bottom: 1px solid var(--border-color);
}
.feed-row:last-child { border-bottom: none; }
.feed-row svg { flex: 0 0 auto; margin-top: 2px; color: var(--ink-muted); }
.feed-row.kind-roll svg { color: var(--gold); }
.feed-row.kind-damage svg { color: var(--accent); }
.feed-text { font-size: 13px; }
.feed-detail { font-size: 12px; color: var(--ink-muted); }
.feed-divider {
    padding: 8px 0; text-align: center; font-size: 10px; font-weight: 600;
    letter-spacing: .13em; text-transform: uppercase; color: var(--ink-muted);
}
.feed-empty { color: var(--ink-muted); font-size: 13px; font-style: italic; }

/* -- drawers (phone) -- */
.scrim { display: none; position: absolute; inset: 0; z-index: 18; background: var(--scrim); }
.drawer-toggle { display: none; }
@media (max-width: 900px) {
    .panes { grid-template-columns: minmax(0, 1fr); }
    .drawer-toggle { display: flex; width: 44px; height: 44px; }
    .scrim { display: block; }
    .pane-left, .pane-right {
        position: absolute; top: 12px; bottom: 12px; z-index: 20;
        width: min(320px, 85vw); transition: transform .25s ease;
    }
    .pane-left { left: 12px; transform: translateX(calc(-100% - 24px)); }
    .pane-right { right: 12px; transform: translateX(calc(100% + 24px)); }
    .shell.drawer-left .pane-left { transform: translateX(0); }
    .shell.drawer-right .pane-right { transform: translateX(0); }
    .pane-right { background: var(--bg-panel); border: var(--border-panel); border-radius: var(--radius); padding: 12px; }
    .user-name { display: none; }
}
