/* ==========================================================================
   TTRPG Scheduler design system
   A candle-lit tavern base with four room themes. Availability colours are
   semantic and identical in every theme, always paired with a symbol and text.
   ========================================================================== */

:root {
    color-scheme: dark;

    /* Base palette: midnight tavern */
    --bg: #0e0c13;
    --bg-glow-1: rgba(217, 164, 65, .10);
    --bg-glow-2: rgba(124, 58, 120, .12);
    --surface: #1a1724;
    --surface-2: #231f30;
    --surface-3: #2d283d;
    --border: #3b3450;
    --border-strong: #574d73;
    --ink: #efe8d8;
    --ink-muted: #b9ae99;
    --ink-faint: #8b8296;
    --accent: #e0aa4a;
    --accent-strong: #f2c46d;
    --accent-ink: #1c1205;
    --accent-soft: rgba(224, 170, 74, .14);
    --danger: #ff7b7b;
    --success: #6fdc9a;
    --focus: #ffd27a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --radius: 14px;
    --radius-sm: 9px;

    /* Semantic availability colours (never themed) */
    --s-available: #33b86f;
    --s-available-ink: #03160b;
    --s-probably: #f29d2f;
    --s-probably-ink: #1f1100;
    --s-unavailable: #e5484f;
    --s-unavailable-ink: #1f0406;
    --s-unset: #77728a;
    --s-unset-ink: #d9d5e6;
    --vote: #f6c453;
    --vote-ink: #2a1a00;
    --d20: #ffd76a;

    /* Typography */
    --font-body: "Alegreya Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-display: "Cinzel", "Palatino Linotype", "Book Antiqua", Georgia, serif;
    --font-title: var(--font-display);
    --font-label: var(--font-body);
    --title-transform: none;
    --title-tracking: .02em;

    /* Theme hooks (overridden by room themes) */
    --banner-image: url("../img/themes/banner-custom.png");
    --banner-tint: linear-gradient(180deg, rgba(14, 12, 19, .25) 0%, rgba(14, 12, 19, .92) 100%);
    --pattern: none;
    --frame: var(--border);
    --cell-bg: rgba(255, 255, 255, .025);
    --cell-bg-hover: rgba(255, 255, 255, .06);
    --panel-bg: var(--surface);
}

/* ---- Room themes ------------------------------------------------------- */

.theme-dnd {
    --bg: #110b0c;
    --bg-glow-1: rgba(201, 162, 39, .12);
    --bg-glow-2: rgba(122, 31, 43, .22);
    --surface: #1d1414;
    --surface-2: #281b1b;
    --surface-3: #342323;
    --border: #4a3328;
    --border-strong: #7b5a32;
    --ink: #f3e7cc;
    --ink-muted: #c9b48f;
    --accent: #d4a73a;
    --accent-strong: #f0c75a;
    --accent-ink: #1d1203;
    --accent-soft: rgba(212, 167, 58, .14);
    --font-title: "Uncial Antiqua", "Cinzel", Georgia, serif;
    --font-display: "Cinzel", Georgia, serif;
    --font-label: var(--font-body);
    --title-transform: none;
    --title-tracking: .02em;
    --banner-image: url("../img/themes/banner-dnd.png");
    --banner-tint: linear-gradient(180deg, rgba(17, 11, 12, .15) 0%, rgba(17, 11, 12, .9) 100%);
    --pattern: url("../img/themes/pattern-dnd.svg");
    --frame: #7b5a32;
    --cell-bg: rgba(212, 167, 58, .035);
    --panel-bg: linear-gradient(180deg, #221717, #1b1313);
}

.theme-coc {
    --bg: #070d12;
    --bg-glow-1: rgba(58, 125, 124, .16);
    --bg-glow-2: rgba(30, 60, 90, .25);
    --surface: #0f1a22;
    --surface-2: #14232d;
    --surface-3: #1b2f3a;
    --border: #24414c;
    --border-strong: #3a6a6f;
    --ink: #e9e3cf;
    --ink-muted: #a9b6ad;
    --accent: #7fc4b2;
    --accent-strong: #a6e3d1;
    --accent-ink: #04130f;
    --accent-soft: rgba(127, 196, 178, .13);
    --font-title: "IM Fell English", Georgia, serif;
    --font-display: "IM Fell English", Georgia, serif;
    --font-label: "Special Elite", "Courier New", monospace;
    --title-transform: none;
    --title-tracking: .01em;
    --banner-image: url("../img/themes/banner-coc.png");
    --banner-tint: linear-gradient(180deg, rgba(7, 13, 18, .1) 0%, rgba(7, 13, 18, .92) 100%);
    --pattern: url("../img/themes/pattern-coc.svg");
    --frame: #3a6a6f;
    --cell-bg: rgba(127, 196, 178, .03);
    --panel-bg: linear-gradient(180deg, #111e27, #0d171e);
}

.theme-fate {
    --bg: #101118;
    --bg-glow-1: rgba(255, 122, 61, .12);
    --bg-glow-2: rgba(79, 70, 229, .2);
    --surface: #181a24;
    --surface-2: #20232f;
    --surface-3: #2a2e3d;
    --border: #353a52;
    --border-strong: #5a5fa0;
    --ink: #f1f0ec;
    --ink-muted: #b6b6c6;
    --accent: #ff8a4c;
    --accent-strong: #ffad7f;
    --accent-ink: #220b00;
    --accent-soft: rgba(255, 138, 76, .14);
    --font-title: "Oswald", "Arial Narrow", sans-serif;
    --font-display: "Oswald", "Arial Narrow", sans-serif;
    --font-label: "Kalam", "Segoe Print", cursive;
    --title-transform: uppercase;
    --title-tracking: .06em;
    --banner-image: url("../img/themes/banner-fate.png");
    --banner-tint: linear-gradient(180deg, rgba(16, 17, 24, .1) 0%, rgba(16, 17, 24, .9) 100%);
    --pattern: url("../img/themes/pattern-fate.svg");
    --frame: #5a5fa0;
    --cell-bg: rgba(129, 140, 248, .035);
    --panel-bg: linear-gradient(180deg, #1b1e2a, #161822);
}

.theme-custom {
    --bg: #110e0b;
    --bg-glow-1: rgba(224, 163, 90, .13);
    --bg-glow-2: rgba(60, 98, 74, .16);
    --surface: #1c1712;
    --surface-2: #261f18;
    --surface-3: #31281f;
    --border: #46392b;
    --border-strong: #72583a;
    --ink: #f2e8d8;
    --ink-muted: #c3b096;
    --accent: #e3a55c;
    --accent-strong: #f5c58a;
    --accent-ink: #1e1104;
    --accent-soft: rgba(227, 165, 92, .14);
    --font-title: "Cinzel", "Palatino Linotype", Georgia, serif;
    --font-display: "Cinzel", "Palatino Linotype", Georgia, serif;
    --font-label: var(--font-body);
    --title-transform: none;
    --title-tracking: .02em;
    --banner-image: url("../img/themes/banner-custom.png");
    --pattern: url("../img/themes/pattern-custom.svg");
    --frame: #72583a;
    --cell-bg: rgba(227, 165, 92, .03);
    --panel-bg: linear-gradient(180deg, #211a14, #1a1510);
}

/* ---- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-body);
    font-size: 1.0625rem;
    line-height: 1.5;
    color: var(--ink);
    background:
        radial-gradient(1200px 600px at 10% -10%, var(--bg-glow-1), transparent 60%),
        radial-gradient(900px 700px at 110% 10%, var(--bg-glow-2), transparent 60%),
        var(--bg);
    background-attachment: fixed;
}

img, svg { max-width: 100%; }

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 .5em;
    letter-spacing: .01em;
}

h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h1:focus { outline: none; }
p { margin: 0 0 1em; }

a { color: var(--accent-strong); text-underline-offset: .18em; }
a:hover { color: var(--ink); }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 6px;
}

::selection { background: var(--accent); color: var(--accent-ink); }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem; top: -4rem;
    z-index: 100;
    padding: .6rem 1rem;
    background: var(--accent);
    color: var(--accent-ink);
    border-radius: var(--radius-sm);
    font-weight: 700;
}
.skip-link:focus { top: 1rem; }

.icon {
    width: 1.15em;
    height: 1.15em;
    flex: none;
    vertical-align: -.2em;
}
.icon-lg { width: 1.6em; height: 1.6em; }

.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.nowrap { white-space: nowrap; }
.stack { display: grid; gap: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- App shell ----------------------------------------------------------- */

.shell {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    background: rgba(14, 12, 19, .86);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    color: var(--ink);
    text-decoration: none;
    font-family: "Cinzel", Georgia, serif;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .04em;
}
.brand img { width: 34px; height: 34px; }
.brand small { display: block; font-family: var(--font-body); font-weight: 400; font-size: .72rem; letter-spacing: .08em; color: var(--ink-muted); text-transform: uppercase; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.nav-toggle-label {
    margin-left: auto;
    display: inline-grid;
    place-items: center;
    width: 44px; height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    color: var(--ink);
    cursor: pointer;
}
.nav-toggle:focus-visible ~ .rail .nav-toggle-label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Below the desktop breakpoint the rail wrapper has no box, so the top bar and menu stay direct grid items. */
.rail { display: contents; }

.sidenav {
    display: none;
    flex-direction: column;
    gap: .25rem;
    padding: .75rem;
    border-bottom: 1px solid var(--border);
    background: rgba(18, 15, 25, .97);
}
.nav-toggle:checked ~ .rail .sidenav { display: flex; }

.nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    min-height: 44px;
    padding: .55rem .8rem;
    color: var(--ink-muted);
    text-decoration: none;
    border-radius: 10px;
    border: 1px solid transparent;
    background: none;
    font: inherit;
    width: 100%;
    text-align: left;
    cursor: pointer;
}
.nav-link:hover { color: var(--ink); background: rgba(255, 255, 255, .05); }
.nav-link.active { color: var(--ink); background: var(--accent-soft); border-color: rgba(224, 170, 74, .35); }
.nav-link .icon { width: 1.3em; height: 1.3em; }
.nav-section { margin: .9rem .8rem .2rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-faint); }
.nav-user { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; color: var(--ink-muted); font-size: .95rem; }
.nav-user strong { color: var(--ink); font-weight: 700; }
.nav-footer { margin-top: auto; display: grid; gap: .25rem; }

.main {
    min-width: 0;
    padding: 1rem;
}

.content-narrow { max-width: 760px; margin: 0 auto; }
.content-wide { max-width: 1480px; margin: 0 auto; }

@media (min-width: 960px) {
    .shell { grid-template-columns: 264px 1fr; }
    /* The menu toggle only serves narrow layouts; keep its invisible checkbox out of the desktop Tab order. */
    .nav-toggle { display: none; }
    /* One sticky, viewport-tall rail. The brand keeps its natural (wrapping, text-scaled) height and the
       navigation takes the rest, scrolling inside the rail when it does not fit (AF-02). */
    .rail {
        display: flex;
        flex-direction: column;
        grid-column: 1; grid-row: 1;
        align-self: start;
        position: sticky; top: 0;
        height: 100vh; height: 100dvh;
        border-right: 1px solid var(--border);
    }
    .topbar { position: static; flex: none; border-bottom: 0; background: transparent; backdrop-filter: none; padding: 1.25rem 1rem .5rem; }
    .nav-toggle-label { display: none; }
    .sidenav {
        display: flex;
        flex: 1 1 auto;
        min-height: 0;
        border-bottom: 0;
        background: transparent;
        overflow-y: auto;
    }
    .main { grid-column: 2; grid-row: 1; padding: 1.75rem 2rem 3rem; }
}

/* ---- Page header ------------------------------------------------------ */

.page-header { margin-bottom: 1.5rem; }
.page-kicker { font-size: .8rem; text-transform: uppercase; letter-spacing: .16em; color: var(--accent); margin-bottom: .35rem; font-weight: 700; }
.page-lede { color: var(--ink-muted); max-width: 60ch; margin: 0; }
.ornament {
    display: block;
    height: 14px;
    margin: .6rem 0 1.2rem;
    background: url("../img/ornament-rule.svg") left center / auto 14px no-repeat;
    opacity: .85;
}

/* ---- Cards and surfaces --------------------------------------------- */

.card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 21rem), 1fr)); align-items: start; gap: 1rem; }
.account-grid > .card { margin-top: 0; min-width: 0; }
.directory-account { display: grid; min-width: 0; overflow-wrap: anywhere; }
.device-title { margin: 1rem 0 .4rem; font-size: 1rem; }
.device-list.preview-list { max-height: none; }
.device-list li { align-items: center; flex-wrap: wrap; }
[hidden] { display: none !important; }
.card-title { display: flex; align-items: center; gap: .55rem; font-size: 1.15rem; margin-bottom: .75rem; }
.card-title .icon { color: var(--accent); }

.empty-state {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: .75rem;
    padding: 2.5rem 1.25rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .02);
}
.empty-state img { width: min(260px, 70%); opacity: .95; }

/* ---- Buttons ---------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-height: 44px;
    padding: .55rem 1.05rem;
    border-radius: 11px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
    touch-action: manipulation;
}
.btn:hover { background: var(--surface-3); border-color: var(--accent); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary {
    background: linear-gradient(180deg, var(--accent-strong), var(--accent));
    border-color: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.btn-primary:hover { background: linear-gradient(180deg, #fff1c9, var(--accent-strong)); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: rgba(255, 255, 255, .06); border-color: var(--border); color: var(--ink); }
.btn-danger { border-color: rgba(255, 123, 123, .5); color: var(--danger); background: rgba(229, 72, 79, .08); }
.btn-danger:hover { background: rgba(229, 72, 79, .18); border-color: var(--danger); color: #ffd1d1; }
.btn-sm { min-height: 36px; padding: .35rem .7rem; font-size: .92rem; border-radius: 9px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

/* ---- Forms ------------------------------------------------------------ */

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field > label, .field-label { font-weight: 700; font-size: .95rem; }
.field-hint { font-size: .88rem; color: var(--ink-muted); }

.input, .select, .textarea {
    width: 100%;
    min-height: 44px;
    padding: .55rem .75rem;
    border-radius: 10px;
    border: 1px solid var(--border-strong);
    background: rgba(0, 0, 0, .28);
    color: var(--ink);
    font: inherit;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); outline: 3px solid rgba(255, 210, 122, .35); outline-offset: 0; }
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%), linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 2rem; }
.select option { background: var(--surface); color: var(--ink); }
input[type="time"].input, input[type="date"].input { color-scheme: dark; }

.check { display: flex; align-items: center; gap: .6rem; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.validation-message, .field-error { color: var(--danger); font-size: .9rem; }
.invalid { border-color: var(--danger) !important; }
.validation-errors { color: var(--danger); padding-left: 1.2rem; }

.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }

/* ---- Alerts and chips -------------------------------------------------- */

.alert {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    padding: .8rem 1rem;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    margin-bottom: 1rem;
}
.alert .icon { margin-top: .15rem; }
.alert-error { border-color: rgba(255, 123, 123, .5); background: rgba(229, 72, 79, .12); color: #ffd6d6; }
.alert-success { border-color: rgba(111, 220, 154, .45); background: rgba(51, 184, 111, .12); color: #d7f8e4; }
.alert-info { border-color: rgba(224, 170, 74, .4); background: var(--accent-soft); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: rgba(0, 0, 0, .25);
    font-size: .85rem;
    color: var(--ink-muted);
    white-space: nowrap;
}
.chip-accent { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

.avatar {
    display: inline-grid;
    place-items: center;
    width: 32px; height: 32px;
    border-radius: 50%;
    font-weight: 700;
    font-size: .85rem;
    color: #120e08;
    background: hsl(var(--hue, 40) 70% 68%);
    border: 2px solid var(--surface);
    flex: none;
    text-transform: uppercase;
}
.avatar-sm { width: 26px; height: 26px; font-size: .72rem; }

/* ---- Tables (admin) ---------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .97rem; }
.table th, .table td { padding: .7rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-muted); background: rgba(0, 0, 0, .2); }
.table tr:last-child td { border-bottom: 0; }

/* ---- Dashboard -------------------------------------------------------- */

.hero {
    position: relative;
    overflow: hidden;
    border-radius: calc(var(--radius) + 4px);
    border: 1px solid var(--border);
    padding: clamp(1.25rem, 3vw, 2.25rem);
    margin-bottom: 1.75rem;
    background:
        linear-gradient(90deg, rgba(14, 12, 19, .96) 0%, rgba(14, 12, 19, .75) 55%, rgba(14, 12, 19, .2) 100%),
        url("../img/hero-tavern.png") right center / cover no-repeat;
    box-shadow: var(--shadow);
}
.hero h1 { font-family: "Cinzel", Georgia, serif; max-width: 22ch; }
.hero p { max-width: 52ch; color: var(--ink-muted); }

.room-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }

.room-card {
    position: relative;
    display: grid;
    grid-template-rows: 120px auto;
    overflow: hidden;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--panel-bg);
    color: var(--ink);
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform .15s, border-color .15s;
}
.room-card:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--ink); }
.room-card-art { background: var(--banner-tint), var(--banner-image) center / cover no-repeat; position: relative; }
.room-card-art .sigil { position: absolute; left: 1rem; bottom: -18px; width: 44px; height: 44px; padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--frame); color: var(--accent); }
.room-card-body { padding: 1.4rem 1rem 1rem; display: grid; gap: .45rem; }
.room-card-title { font-family: var(--font-title); text-transform: var(--title-transform); letter-spacing: var(--title-tracking); font-size: 1.3rem; margin: 0; }
.room-card-meta { display: flex; gap: .4rem; flex-wrap: wrap; }
.next-session { display: flex; align-items: center; gap: .5rem; font-size: .95rem; color: var(--ink-muted); }
.next-session strong { color: var(--ink); }

/* ---- Room page ---------------------------------------------------------- */

.room { position: relative; }

.room-banner {
    position: relative;
    overflow: hidden;
    border-radius: calc(var(--radius) + 4px);
    border: 1px solid var(--frame);
    min-height: 168px;
    padding: 1.25rem 1.25rem 1.1rem;
    display: grid;
    align-content: end;
    gap: .5rem;
    margin-bottom: 1rem;
    background: var(--banner-tint), var(--banner-image) center 35% / cover no-repeat;
    box-shadow: var(--shadow);
}
.room-banner::after {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid rgba(255, 255, 255, .08);
    pointer-events: none;
}
.room-title {
    font-family: var(--font-title);
    text-transform: var(--title-transform);
    letter-spacing: var(--title-tracking);
    font-size: clamp(1.7rem, 1.2rem + 2vw, 2.8rem);
    margin: 0;
    text-shadow: 0 2px 18px rgba(0, 0, 0, .7);
}
.room-type { display: inline-flex; align-items: center; gap: .45rem; font-family: var(--font-label); color: var(--accent-strong); font-size: .95rem; }
.room-type .icon { width: 1.5em; height: 1.5em; }
.room-meta { display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: center; color: var(--ink-muted); font-size: .92rem; }
.member-stack { display: flex; align-items: center; }
.member-stack .avatar { margin-left: -6px; }
.member-stack .avatar:first-child { margin-left: 0; }

.room-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    align-items: center;
    margin-bottom: .9rem;
}
.month-nav { display: flex; align-items: center; gap: .35rem; }
.month-label {
    min-width: 11ch;
    text-align: center;
    font-family: var(--font-display);
    text-transform: var(--title-transform);
    letter-spacing: var(--title-tracking);
    font-size: 1.3rem;
    margin: 0;
}

.room-layout { display: grid; gap: 1rem; align-items: start; }
@media (min-width: 1180px) {
    .room-layout { grid-template-columns: minmax(0, 1fr) 400px; }
    .side-pane { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; scrollbar-width: thin; }
    .day-back { display: none; }
}

/* ---- Calendar ---------------------------------------------------------- */

.calendar {
    position: relative;
    border: 1px solid var(--frame);
    border-radius: var(--radius);
    background: var(--panel-bg);
    padding: .6rem;
    box-shadow: var(--shadow);
}
.calendar::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--pattern) center / 420px auto;
    opacity: .5;
    pointer-events: none;
}
.cal-head, .cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; position: relative; }
.cal-head { margin-bottom: 4px; }
.cal-head span {
    text-align: center;
    font-size: .78rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-muted);
    font-family: var(--font-label);
    padding: .25rem 0;
}
.cal-grid { display: grid; gap: 4px; position: relative; }
.cal-cell { display: grid; min-width: 0; }
.cal-cell > .cal-day { height: 100%; width: 100%; }

.cal-day {
    position: relative;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 2px;
    min-height: 66px;
    padding: 4px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--cell-bg);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition: background .12s, border-color .12s, box-shadow .12s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.cal-day:hover { background: var(--cell-bg-hover); border-color: var(--border-strong); }
.cal-day.is-out { opacity: .45; }
.cal-day.is-past { background: repeating-linear-gradient(135deg, rgba(255, 255, 255, .015) 0 6px, transparent 6px 12px); }
.cal-day.is-past .cal-date { color: var(--ink-faint); }
.cal-day.is-today .cal-date { background: var(--accent); color: var(--accent-ink); }
.cal-day.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 18px var(--accent-soft); }
.cal-day.is-picked { background: var(--accent-soft); border-color: var(--accent); }
.cal-day.is-picked::after {
    content: "";
    position: absolute;
    top: 4px; right: 4px;
    width: 16px; height: 16px;
    border-radius: 5px;
    background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 8.4 2.6 2.6L12 5.4' fill='none' stroke='%231c1205' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.cal-day.feasible-firm { border-color: var(--s-available); box-shadow: inset 0 0 0 1px var(--s-available), 0 0 14px rgba(51, 184, 111, .25); }
.cal-day.feasible-tentative { border-color: var(--s-probably); border-style: dashed; box-shadow: inset 0 0 0 1px rgba(242, 157, 47, .5); }
.cal-day.has-session { background: linear-gradient(180deg, var(--accent-soft), var(--cell-bg)); }

.cal-top { display: flex; align-items: center; gap: 3px; min-width: 0; }
.cal-date {
    display: inline-grid;
    place-items: center;
    min-width: 1.6rem;
    height: 1.6rem;
    padding: 0 .3rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: .92rem;
}
.cal-badges { margin-left: auto; display: flex; gap: 2px; align-items: center; }
.vote-badge {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    height: 1.25rem;
    padding: 0 .35rem;
    border-radius: 999px;
    background: var(--vote);
    color: var(--vote-ink);
    font-weight: 800;
    font-size: .78rem;
    line-height: 1;
}
.vote-badge .bang { font-family: Georgia, serif; font-size: .95rem; }
.d20-badge { display: inline-grid; place-items: center; width: 1.55rem; height: 1.55rem; color: var(--d20); filter: drop-shadow(0 0 6px rgba(255, 215, 106, .6)); }
.d20-badge .icon { width: 100%; height: 100%; }
.comment-badge { display: inline-flex; align-items: center; gap: 1px; font-size: .75rem; color: var(--ink-muted); }
.comment-badge .icon { width: .95rem; height: .95rem; }

.cal-mid { display: grid; align-content: start; gap: 2px; min-width: 0; }
.cal-session {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 1px 5px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: .74rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-session .icon { width: .95rem; height: .95rem; }
.cal-session.st-delayed { background: #f6d48b; }
.cal-session.st-postponed { background: transparent; color: var(--ink-muted); border: 1px dashed var(--border-strong); text-decoration: line-through; }
.cal-session.st-tookplace { background: #b8a5e3; color: #140b2b; }
.cal-moved { font-size: .7rem; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-window { font-size: .72rem; font-weight: 700; color: var(--s-available); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feasible-tentative .cal-window { color: var(--s-probably); }

.cal-bar { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; }
.seg { flex: 1 1 0; min-width: 3px; border-radius: 2px; }
.seg.s-available { background: var(--s-available); }
.seg.s-probably { background: var(--s-probably); }
.seg.s-unavailable { background: var(--s-unavailable); }
.seg.s-unset { background: repeating-linear-gradient(90deg, var(--s-unset) 0 3px, transparent 3px 5px); opacity: .38; }

.cal-solo { display: flex; align-items: center; gap: 3px; font-size: .74rem; color: var(--ink-muted); min-width: 0; }
.cal-solo .icon { width: 1rem; height: 1rem; }
.cal-solo.s-available { color: var(--s-available); }
.cal-solo.s-probably { color: var(--s-probably); }
.cal-solo.s-unavailable { color: var(--s-unavailable); }
.cal-solo.s-unset { color: var(--ink-faint); }
.cal-solo-fill { position: absolute; inset: auto 0 0 0; height: 5px; }

@media (min-width: 720px) {
    .cal-day { min-height: 104px; padding: 6px; }
    .cal-session { font-size: .8rem; }
    .cal-bar { height: 10px; }
}

@media (max-width: 480px) {
    .calendar { padding: .35rem; }
    .cal-head span { font-size: .66rem; letter-spacing: .06em; }
    .cal-head, .cal-week, .cal-grid { gap: 3px; }
    .cal-day { min-height: 58px; padding: 3px; border-radius: 7px; }
    .cal-date { min-width: 1.35rem; height: 1.35rem; font-size: .8rem; }
    .cal-window, .cal-moved, .comment-badge { display: none; }
    .cal-session { font-size: 0; padding: 2px; justify-content: center; }
    .cal-session .icon { width: .85rem; height: .85rem; }
    .vote-badge { height: 1.05rem; padding: 0 .25rem; font-size: .68rem; }
    .d20-badge { width: 1.25rem; height: 1.25rem; }
}

/* ---- Legend ------------------------------------------------------------- */

.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin: .8rem .2rem 0; font-size: .86rem; color: var(--ink-muted); }
.legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; }

/* ---- State pills -------------------------------------------------------- */

.state-pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .18rem .6rem .18rem .4rem;
    border-radius: 999px;
    font-size: .86rem;
    font-weight: 700;
    white-space: nowrap;
}
.state-pill .icon { width: 1.05rem; height: 1.05rem; }
.s-available.state-pill { background: var(--s-available); color: var(--s-available-ink); }
.s-probably.state-pill { background: var(--s-probably); color: var(--s-probably-ink); }
.s-unavailable.state-pill { background: var(--s-unavailable); color: var(--s-unavailable-ink); }
.s-unset.state-pill { background: transparent; color: var(--s-unset-ink); border: 1px dashed var(--s-unset); }

/* ---- Side panel (selected day, bulk editor) ----------------------------- */

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--frame);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    padding: 1rem 1.1rem .8rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(255, 255, 255, .04), transparent);
}
.panel-head h2 { margin: 0; font-size: 1.25rem; text-transform: var(--title-transform); letter-spacing: var(--title-tracking); }
.panel-head .muted { font-size: .9rem; }
.panel-section { padding: .95rem 1.1rem; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: 0; }
.section-title {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: 0 0 .65rem;
    font-family: var(--font-label);
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--accent-strong);
    font-weight: 700;
}
.theme-fate .section-title { text-transform: none; letter-spacing: .02em; font-size: 1rem; }

.feasibility {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    padding: .7rem .8rem;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, .2);
    font-size: .95rem;
}
.feasibility.f-firm { border-color: var(--s-available); background: rgba(51, 184, 111, .1); }
.feasibility.f-tentative { border-color: var(--s-probably); background: rgba(242, 157, 47, .1); }
.feasibility.f-blocked { border-color: rgba(229, 72, 79, .55); background: rgba(229, 72, 79, .08); }
.feasibility strong { display: block; }

.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.roster-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: .6rem;
    align-items: center;
    padding: .4rem .5rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, .16);
}
.roster-row.is-me { outline: 1px solid var(--border-strong); }
.roster-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-name small { display: block; font-weight: 400; color: var(--ink-muted); font-size: .84rem; }
.roster-vote { color: var(--vote); font-weight: 800; font-family: Georgia, serif; }

.state-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; margin-bottom: .8rem; }
.radio-choice { min-width: 0; }
.radio-choice > label { height: 100%; }
.radio-choice > input:focus-visible + label { outline: 2px solid var(--accent-strong); outline-offset: 3px; }
.state-option {
    display: flex;
    align-items: center;
    gap: .45rem;
    min-height: 46px;
    padding: .5rem .65rem;
    border-radius: 11px;
    border: 1px solid var(--border-strong);
    background: rgba(0, 0, 0, .2);
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    font-size: .95rem;
    cursor: pointer;
    text-align: left;
}
.state-option .icon { width: 1.3rem; height: 1.3rem; }
.state-option.s-available .icon { color: var(--s-available); }
.state-option.s-probably .icon { color: var(--s-probably); }
.state-option.s-unavailable .icon { color: var(--s-unavailable); }
.state-option.s-unset .icon { color: var(--s-unset); }
input:checked + .state-option.s-available { background: var(--s-available); color: var(--s-available-ink); border-color: var(--s-available); }
input:checked + .state-option.s-probably { background: var(--s-probably); color: var(--s-probably-ink); border-color: var(--s-probably); }
input:checked + .state-option.s-unavailable { background: var(--s-unavailable); color: var(--s-unavailable-ink); border-color: var(--s-unavailable); }
input:checked + .state-option.s-unset { background: var(--surface-3); border-color: var(--s-unset); }
input:checked + .state-option .icon { color: currentColor; }

.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.time-row .field { margin-bottom: .6rem; }

.vote-toggle {
    width: 100%;
    justify-content: flex-start;
    gap: .7rem;
    min-height: 52px;
}
.vote-toggle .bang {
    display: inline-grid;
    place-items: center;
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--vote);
    color: var(--vote-ink);
    font-family: Georgia, serif;
    font-weight: 900;
    font-size: 1.2rem;
}
.vote-toggle[aria-pressed="true"] { border-color: var(--vote); background: rgba(246, 196, 83, .14); }
.unanimous-banner {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .7rem .85rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 215, 106, .55);
    background: radial-gradient(circle at 10% 50%, rgba(255, 215, 106, .25), rgba(255, 215, 106, .05) 60%);
    margin-bottom: .7rem;
}
.unanimous-banner .icon { width: 2.4rem; height: 2.4rem; color: var(--d20); filter: drop-shadow(0 0 8px rgba(255, 215, 106, .7)); }

.session-card {
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: .8rem .9rem;
    background: linear-gradient(135deg, var(--accent-soft), rgba(0, 0, 0, .15));
    display: grid;
    gap: .45rem;
}
.session-card + .session-card { margin-top: .6rem; }
.session-time { font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.status-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 999px; font-size: .85rem; font-weight: 800; }
.status-chip .icon { width: 1.05rem; height: 1.05rem; }
.st-scheduled.status-chip { background: var(--accent); color: var(--accent-ink); }
.st-tookplace.status-chip { background: #b8a5e3; color: #140b2b; }
.st-delayed.status-chip { background: #f6d48b; color: #2b1d00; }
.st-postponed.status-chip { background: transparent; color: var(--ink); border: 1px dashed var(--ink-muted); }
.status-actions { display: flex; flex-wrap: wrap; gap: .4rem; }

.comments { list-style: none; margin: 0 0 .8rem; padding: 0; display: grid; gap: .6rem; }
.comment { display: grid; grid-template-columns: auto 1fr; gap: .55rem; }
.comment-body {
    background: rgba(0, 0, 0, .22);
    border: 1px solid var(--border);
    border-radius: 4px 12px 12px 12px;
    padding: .45rem .7rem .55rem;
    min-width: 0;
}
.comment-meta { display: flex; gap: .5rem; align-items: baseline; font-size: .84rem; color: var(--ink-muted); }
.comment-meta strong { color: var(--ink); font-size: .93rem; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: .15rem 0 0; }
.theme-fate .comment-body { background: #f4f1e6; color: #1b1c22; border-color: #d9d3bf; background-image: linear-gradient(transparent 1.45em, rgba(70, 110, 200, .25) 1.45em, transparent calc(1.45em + 1px)); background-size: 100% 1.5em; }
.theme-fate .comment-meta { color: #555a6e; }
.theme-fate .comment-meta strong { color: #1b1c22; }
.theme-fate .comment-text { font-family: "Kalam", cursive; }

.weekday-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.weekday-chips .btn { min-width: 52px; }
.preview-list { max-height: 180px; overflow-y: auto; margin: .4rem 0 0; padding: 0; list-style: none; display: grid; gap: .25rem; font-size: .9rem; }
.preview-list li { display: flex; justify-content: space-between; gap: .5rem; padding: .25rem .45rem; border-radius: 7px; background: rgba(0, 0, 0, .18); }

.toast-region { position: fixed; z-index: 60; left: 50%; bottom: 1rem; transform: translateX(-50%); display: grid; gap: .5rem; width: min(92vw, 460px); pointer-events: none; }
.toast { pointer-events: auto; padding: .75rem 1rem; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.toast-error { border-color: var(--danger); }

.loading-rune { display: grid; place-items: center; gap: .75rem; padding: 3rem 1rem; color: var(--ink-muted); }
.loading-rune .icon { width: 3rem; height: 3rem; color: var(--accent); animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Room creation ----------------------------------------------------- */

.type-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.type-option {
    position: relative;
    display: grid;
    gap: .25rem;
    align-content: end;
    min-height: 110px;
    padding: .8rem;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--banner-tint), var(--banner-image) center / cover no-repeat;
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    text-align: left;
}
.type-option .icon { width: 1.6rem; height: 1.6rem; color: var(--accent-strong); }
.type-option strong { font-family: var(--font-title); text-transform: var(--title-transform); letter-spacing: var(--title-tracking); font-size: 1.05rem; }
input:checked + .type-option { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.people-list { display: grid; gap: .35rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); max-height: 340px; overflow-y: auto; padding: .2rem; }
.person {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-height: 48px;
    padding: .4rem .6rem;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, .18);
    cursor: pointer;
}
.person input { width: 20px; height: 20px; accent-color: var(--accent); }
.person:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.person.is-locked { cursor: default; opacity: .85; }

/* ---- Auth pages ---------------------------------------------------------- */

.auth-layout { display: grid; min-height: calc(100vh - 2rem); place-items: center; }
.auth-card { width: min(100%, 440px); }
.auth-art { display: block; width: 120px; margin: 0 auto 1rem; }

/* ---- Blazor plumbing ------------------------------------------------------ */

.blazor-error-boundary { padding: 1rem; border-radius: 11px; background: rgba(229, 72, 79, .15); border: 1px solid var(--danger); color: #ffd6d6; }
.blazor-error-boundary::after { content: "Something went wrong while rendering this part of the page."; }
#blazor-error-ui {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; right: 0; bottom: 0;
    padding: .75rem 1.25rem;
    background: #3a1418;
    color: #ffe0e0;
    border-top: 1px solid var(--danger);
}
#blazor-error-ui .reload { color: #fff; font-weight: 700; margin-left: .5rem; }
#blazor-error-ui .dismiss { position: absolute; right: 1rem; top: .6rem; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
    .seg, .state-pill, .cal-session, .vote-badge { border: 1px solid CanvasText; }
}
