/* The tabletop page: the screen is the battlemap, and everything else is an overlay on it. This file holds the design tokens,
 * the hiding of the site's chrome, the stage, and the small overlays (toolbar, banners, toasts, dialogs). The hotbar, Tod's
 * thread and the panels have their own files (tabletop_hud.css, tabletop_thread.css, tabletop_panels.css). */

.tt-root {
    --tt-gold: #e2b95a;
    --tt-gold-hi: #f6dc92;
    --tt-gold-dim: #8a6c2f;
    --tt-ink: #0b0d12;
    --tt-glass: rgba(14, 16, 22, 0.9);
    --tt-glass-thin: rgba(12, 14, 20, 0.62);
    /* the width of Tod's docked thread, and what each side of the top row keeps for the toolbar (about 370px, at the right) and the place's name (at the left):
     * the turn-order bar, centred, may be as wide as what is left between them */
    --tt-thread-width: clamp(300px, 26vw, 400px);
    --tt-top-reserve: 440px;
    /* what the toolbar leaves to the back link at the left of the screen (its margin, its 44px, a gap) and its own margin at the right */
    --tt-toolbar-keep: 78px;
    /* how much of the map Tod's thread and the conversation panel hide behind them (the rest shows through) */
    --tt-thread-alpha: 0.8;
    --tt-conversation-alpha: 0.82;
    --tt-line: rgba(226, 185, 90, 0.34);
    --tt-text: #f1e8d2;
    --tt-muted: #aaa392;
    --tt-green: #58c26b;
    --tt-orange: #f08a2e;
    --tt-blue: #5aa0e0;
    --tt-red: #d9483f;
    --tt-serif: "Cinzel", "Trajan Pro", Georgia, "Times New Roman", serif;
    --tt-body: Georgia, "Times New Roman", serif;
    --tt-hotbar-h: 176px;
    --tt-slot: 60px;
    --tt-top: 56px;
    position: fixed;
    inset: 0;
    z-index: 1040;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 40%, #1b212b 0%, #0b0d12 75%);
    color: var(--tt-text);
    font-family: var(--tt-body);
    font-size: 15px;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.tt-root[data-layout="sheet"] {
    --tt-hotbar-h: 152px;
    --tt-slot: 48px;
}

/* a hero who has spells has the row of spell levels above the slots */
.tt-root:has(.tt-levels:not([hidden])) {
    --tt-hotbar-h: 206px;
}

.tt-root[data-layout="sheet"]:has(.tt-levels:not([hidden])) {
    --tt-hotbar-h: 184px;
}

/* --- The site's chrome, out of the way ----------------------------------------------------------------------------------- */

body.tt-body {
    overflow: hidden;
    background: #0b0d12;
}

.tt-body > nav,
.tt-body > .jumbo,
.tt-body > .container,
.tt-body .main-content > .container {
    display: none;
}

.tt-body .main-content {
    padding: 0;
    margin: 0;
}

.tt-root *,
.tt-root *::before,
.tt-root *::after {
    box-sizing: border-box;
}

.tt-root button {
    font-family: inherit;
}

.tt-root [hidden] {
    display: none !important;
}

/* --- The stage ------------------------------------------------------------------------------------------------------------ */

/* The battlemap fills the whole screen, edge to edge; the camera keeps what it follows in the part the overlays leave free, and the
 * party, Tod's thread, the hotbar and the toolbar lie over it, translucent. */
.tt-stage {
    position: absolute;
    z-index: 0;
    inset: 0;
}

.tt-stage .bm-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    outline: none;
    transition: opacity 0.32s ease;
}

.tt-stage .bm-canvas:focus-visible {
    outline: none;
}

.tt-stage .bm-canvas.is-faded {
    opacity: 0;
}

.tt-dice-host {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.tt-dice-layer {
    position: absolute;
    inset: 0;
}

.tt-loading {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    background: #0b0d12;
    transition: opacity 0.5s ease;
}

.tt-loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    color: var(--tt-gold);
}

.tt-loading-text {
    margin: 0;
    font-family: var(--tt-serif);
    font-size: 1.3rem;
    letter-spacing: 0.1em;
    color: var(--tt-gold);
}

/* the screen that is hidden (the table is ready) runs no animation: the spinner (the site's, option_generation.css) stops with it */
.tt-root.is-ready .tt-loading {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.5s ease, visibility 0s linear 0.5s;
}

.tt-root.is-ready .tt-loading .option-generation-spinner {
    animation: none;
}

/* a table that could not be set shows the words only */
.tt-root.is-failed .tt-loading .option-generation-spinner {
    display: none;
}

.tt-root.is-failed .tt-loading-text {
    color: #ff9a8a;
}

@keyframes tt-breathe {
    50% { opacity: 0.45; }
}

/* --- Top left: back link and scene name ------------------------------------------------------------------------------------- */

.tt-topleft {
    position: absolute;
    z-index: 12;
    top: 10px;
    left: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 230px);
}

.tt-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--tt-line);
    border-radius: 20px;
    background: var(--tt-glass);
    color: var(--tt-gold-hi);
    font-size: 0.85rem;
    text-decoration: none;
}

.tt-back:hover {
    border-color: var(--tt-gold);
    color: #fff;
}

.tt-scene-name {
    overflow: hidden;
    font-family: var(--tt-serif);
    font-size: 1rem;
    letter-spacing: 0.06em;
    color: var(--tt-text);
    text-shadow: 0 1px 4px #000, 0 0 12px #000;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* --- Top right: the toolbar ------------------------------------------------------------------------------------------------ */

.tt-toolbar {
    position: absolute;
    z-index: 12;
    top: 10px;
    right: 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    /* the buttons never run under the back link at the left: on a screen too narrow for all of them in one row the rest wrap to a second row */
    max-width: calc(100% - var(--tt-toolbar-keep));
    padding: 3px;
    border: 1px solid var(--tt-line);
    border-radius: 22px;
    background: var(--tt-glass);
}

.tt-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--tt-gold-hi);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tt-icon-btn:hover,
.tt-icon-btn:focus-visible {
    background: rgba(226, 185, 90, 0.2);
    color: #fff;
    outline: none;
}

.tt-camera {
    position: absolute;
    z-index: 11;
    left: 12px;
    bottom: calc(var(--tt-hotbar-h) + 18px);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tt-camera .tt-icon-btn {
    border: 1px solid var(--tt-line);
    background: var(--tt-glass);
}

.tt-icon-btn[aria-pressed="true"] {
    background: rgba(226, 185, 90, 0.28);
}

/* --- A campaign that cannot be played now ------------------------------------------------------------------------------------ */

.tt-blocked {
    position: absolute;
    inset: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    max-height: 100dvh;
    overflow-y: auto;
    background: #0b0d12;
    text-align: center;
}

.tt-blocked-title {
    margin: 0;
    font-family: var(--tt-serif);
    font-size: clamp(1.4rem, 4vw, 2.2rem);
    color: var(--tt-gold-hi);
}

.tt-blocked-text {
    max-width: 520px;
    margin: 0;
    color: var(--tt-text);
}

.tt-blocked .tt-btn {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.tt-skip {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: calc(var(--tt-hotbar-h) + 22px);
    display: none;
    width: fit-content;
    margin: 0 auto;
    min-height: 44px;
    padding: 0 22px;
    border: 1px solid var(--tt-gold);
    border-radius: 22px;
    background: var(--tt-glass);
    color: var(--tt-gold-hi);
    font-family: var(--tt-serif);
    letter-spacing: 0.08em;
    cursor: pointer;
}

.tt-root.is-playing .tt-skip {
    display: block;
}

/* --- Notices: the title of a scene, toasts ------------------------------------------------------------------------------------ */

.tt-notices {
    position: absolute;
    inset: 0;
    z-index: 40;
    pointer-events: none;
}

.tt-banner {
    position: absolute;
    top: 24%;
    left: 0;
    right: 0;
    text-align: center;
    opacity: 0;
}

.tt-banner.is-shown {
    animation: tt-banner 2.6s ease both;
}

.tt-banner::before,
.tt-banner::after {
    content: "";
    display: block;
    width: min(420px, 70%);
    height: 1px;
    margin: 0 auto;
    background: linear-gradient(90deg, transparent, var(--tt-gold), transparent);
}

.tt-banner-title {
    padding: 10px 0 4px;
    font-family: var(--tt-serif);
    font-size: clamp(1.8rem, 5vw, 3.2rem);
    letter-spacing: 0.12em;
    color: var(--tt-gold-hi);
    text-shadow: 0 2px 12px #000, 0 0 30px rgba(0, 0, 0, 0.9);
    text-transform: uppercase;
}

.tt-banner-sub {
    padding-bottom: 10px;
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    letter-spacing: 0.3em;
    color: var(--tt-text);
    text-shadow: 0 1px 6px #000;
    text-transform: uppercase;
}

.tt-banner[data-tone="combat"] .tt-banner-title,
.tt-banner[data-tone="defeat"] .tt-banner-title {
    color: #ff9a82;
}

@keyframes tt-banner {
    0% { opacity: 0; transform: translateY(-8px) scale(0.98); }
    15%, 75% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateY(6px); }
}

.tt-toasts {
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.tt-root:has(.tt-initiative:not([hidden])) .tt-toasts {
    top: 112px;
}

.tt-toast {
    display: flex;
    flex-direction: column;
    max-width: min(440px, calc(100vw - 32px));
    padding: 8px 16px;
    border: 1px solid var(--tt-line);
    border-left: 4px solid var(--tt-gold);
    border-radius: 8px;
    background: rgba(12, 14, 20, 0.9);
    font-size: 0.92rem;
    animation: tt-toast-in 0.25s ease both;
}

.tt-toast strong {
    font-family: var(--tt-serif);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    color: var(--tt-gold-hi);
}

.tt-toast-warn {
    border-left-color: var(--tt-red);
}

/* a notice with a close control (told once per page load) */
.tt-toast.is-closable {
    position: relative;
    padding-right: 40px;
}

.tt-toast-close {
    position: absolute;
    top: 4px;
    right: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--tt-muted);
    cursor: pointer;
}

.tt-toast-close:hover,
.tt-toast-close:focus-visible {
    background: rgba(226, 185, 90, 0.16);
    color: var(--tt-gold-hi);
}

.tt-toast.is-leaving {
    opacity: 0;
    transition: opacity 0.4s;
}

@keyframes tt-toast-in {
    from { opacity: 0; transform: translateY(-6px); }
}

/* --- Dialogs --------------------------------------------------------------------------------------------------------------- */

.tt-backdrop {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 12px;
    background: rgba(5, 6, 9, 0.72);
}

/* ONE rule for every window over the table (journal, trade, chooser, level-up card, confirmations, begin and defeat screens): sized to the
 * visible viewport (dvh follows the browser's bars and keyboard), centred, never larger than it, scrolling inside, its header and close
 * button always in view. */
.tt-journal,
.tt-trade,
.tt-chooser,
.tt-card,
dialog.mg-confirm {
    box-sizing: border-box;
    width: min(var(--tt-dialog-width, 560px), calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    min-height: 0;
    overflow: hidden;
}

.tt-journal-body,
.tt-trade-body,
.tt-choices {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tt-btn {
    min-height: 44px;
    padding: 0 20px;
    border: 1px solid var(--tt-line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--tt-text);
    cursor: pointer;
}

.tt-btn:hover:not(:disabled) {
    border-color: var(--tt-gold);
}

.tt-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tt-btn-primary {
    border-color: var(--tt-gold);
    background: linear-gradient(180deg, #e8c773, #b88d34);
    color: #231a08;
    font-weight: 700;
}

.tt-btn-small {
    min-height: 34px;
    padding: 0 14px;
}

.tt-root :focus-visible {
    outline: 2px solid var(--tt-gold-hi);
    outline-offset: 2px;
}

/* --- Tooltips (one for the whole page; it lives in the body, above everything) -------------------------------------------------- */

.tt-tooltip {
    position: fixed;
    z-index: 2000;
    top: 0;
    left: 0;
    max-width: 280px;
    padding: 10px 12px;
    border: 1px solid var(--tt-gold);
    border-radius: 8px;
    background: rgba(10, 11, 16, 0.96);
    color: #f1e8d2;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

.tt-tip-name {
    display: block;
    font-family: "Cinzel", "Trajan Pro", Georgia, serif;
    font-size: 15px;
    letter-spacing: 0.04em;
    color: #f6dc92;
}

.tt-tip-kind,
.tt-tip-facts {
    color: #aaa392;
    font-size: 12.5px;
}

.tt-tip-cost {
    color: #8fc7f2;
    font-size: 12.5px;
}

.tt-tip-text {
    margin: 6px 0 0;
}

.tt-tip-reason {
    margin: 6px 0 0;
    color: #ff8f7e;
}

/* a creature's card (hover, or a long press on a touch screen) */
.tt-tokencard { display: flex; flex-direction: column; gap: 5px; min-width: 190px; }
.tt-tokencard-about { margin: 0; color: #d8cfb8; font-size: 13px; font-style: italic; }
.tt-tokencard-state { display: flex; flex-wrap: wrap; gap: 3px; }
.tt-tokencard-facts { display: flex; flex-wrap: wrap; gap: 3px 12px; }
.tt-fact { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tt-fact-label { margin-right: 4px; color: #aaa392; font-size: 11px; font-weight: 400; letter-spacing: 0.06em; text-transform: uppercase; }
.tt-tokencard-abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin-top: 2px; }
.tt-ability { display: flex; flex-direction: column; align-items: center; padding: 2px 0; border-radius: 6px; background: rgba(255, 255, 255, 0.06); line-height: 1.15; }
.tt-ability-mark { color: #aaa392; font-size: 9.5px; letter-spacing: 0.06em; }
.tt-ability-score { font-size: 14px; font-weight: 700; }
.tt-ability-mod { color: #f6dc92; font-size: 11px; }

@media (prefers-reduced-motion: reduce) {
    .tt-root *,
    .tt-root *::before,
    .tt-root *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

.tt-clock {
    flex: none;
    padding: 4px 12px;
    border: 1px solid var(--tt-line);
    border-radius: 14px;
    background: var(--tt-glass);
    color: var(--tt-gold-hi);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.tt-blocked-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

/* a card that stays until dismissed (a level gained) */
.tt-card {
    overflow-y: auto;
    position: absolute;
    top: 12%;
    left: 0;
    right: 0;
    width: min(380px, calc(100% - 24px));
    margin: 0 auto;
    padding: 18px 20px;
    border: 1px solid var(--tt-gold);
    border-radius: 14px;
    background: rgba(14, 16, 22, 0.95);
    box-shadow: 0 14px 44px #000;
    text-align: center;
    pointer-events: auto;
}

.tt-card-title {
    margin: 0 0 8px;
    font-family: var(--tt-serif);
    font-size: 1.2rem;
    color: var(--tt-gold-hi);
}

.tt-card-line {
    margin: 0 0 6px;
}

.tt-bag button {
    margin-left: auto;
}

/* the layers over the map (tokens, reach, floating numbers) are drawn on their own canvas, which lets every press through */
.tt-stage .tt-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* toasts and cards are seen above every window (a purchase's gold, a refusal in the shop) */
.tt-notices { z-index: 70; }

.tt-voice.is-playing { animation: tt-breathe 1.6s ease-in-out infinite; }

/* the on-screen keyboard is up: the hotbar steps aside and the thread's sheet sits just above the keyboard */
.tt-root.is-typing .tt-hotbar,
.tt-root.is-typing .tt-camera { display: none; }

.tt-root.is-typing[data-layout="sheet"] .tt-thread[data-sheet] {
    bottom: var(--tt-keyboard, 0px);
    height: calc(100% - var(--tt-keyboard, 0px) - 70px);
}

/* notices: low ones sit above the hotbar (a refused slot), near ones at the tapped square */
.tt-toasts-low {
    top: auto;
    bottom: calc(var(--tt-hotbar-h) + 24px);
}

.tt-toast { pointer-events: auto; cursor: pointer; }

.tt-toast.is-near {
    position: absolute;
    top: 0;
    left: 0;
}
