/* Tod's thread: a translucent glass side panel over the battlemap holding the whole conversation. Docked at the right edge on
 * a wide screen (it folds into a slim tab); a bottom sheet with three states (strip, half, full) on a portrait screen. The map
 * shows through it (dark glass, no blur: the blur would be redone each time something moves on the map under it) and the text stays fully readable. */

.tt-thread {
    position: absolute;
    z-index: 15;
    display: flex;
    flex-direction: column;
    background: rgba(12, 14, 20, var(--tt-thread-alpha));
    border: 1px solid rgba(226, 185, 90, 0.32);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 235, 180, 0.08);
    user-select: text;
}

/* docked */

.tt-root[data-layout="dock"] .tt-thread {
    /* under the toolbar, and under the turn-order bar while it shows, wherever they end (the toolbar wraps to a second row on a narrow screen):
     * never against them, with the table's margin between */
    top: calc(var(--tt-top-band, 58px) + 12px);
    right: 12px;
    bottom: calc(var(--tt-hotbar-h) + 28px);
    width: var(--tt-thread-width);
    border-radius: 16px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

@media (min-width: 1700px) {
    .tt-root[data-layout="dock"] .tt-thread {
        bottom: 14px;
    }
}

.tt-root[data-layout="dock"] .tt-thread[data-open="false"] {
    transform: translateX(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
}

.tt-thread-tab {
    position: absolute;
    z-index: 15;
    right: 0;
    top: calc(var(--tt-top-band, 58px) + 12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 52px;
    padding: 8px 0 10px;
    border: 1px solid var(--tt-line);
    border-right: 0;
    border-radius: 14px 0 0 14px;
    background: var(--tt-glass);
    color: var(--tt-gold-hi);
    cursor: pointer;
}

.tt-thread-tab:hover {
    background: rgba(40, 36, 24, 0.9);
}

.tt-thread-tab-label {
    font-family: var(--tt-serif);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    writing-mode: vertical-rl;
}

.tt-tab-dot {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--tt-red);
    box-shadow: 0 0 6px var(--tt-red);
}

.tt-root[data-layout="sheet"] .tt-thread-tab {
    display: none;
}

/* the header */

.tt-thread-head {
    display: flex;
    flex: none;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(226, 185, 90, 0.2);
}

.tt-avatar {
    display: inline-block;
    flex: none;
    width: 40px;
    height: 40px;
    overflow: hidden;
    border: 2px solid var(--tt-gold);
    border-radius: 50%;
    background: #14161c;
    box-shadow: 0 0 10px rgba(226, 185, 90, 0.35);
}

.tt-avatar.is-small {
    width: 28px;
    height: 28px;
    border-width: 1px;
}

.tt-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tt-thread-title {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.tt-thread-title strong {
    font-family: var(--tt-serif);
    font-size: 1.05rem;
    letter-spacing: 0.06em;
    color: var(--tt-gold-hi);
}

.tt-thread-title span {
    color: var(--tt-muted);
    font-size: 0.74rem;
}

/* on a phone the opened sheet covers the "Your turn" cue over the hotbar: its words stand in the sheet's header instead of the subtitle */
.tt-thread-turn { display: none; color: var(--tt-gold-hi); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; }

.tt-root[data-layout="sheet"] .tt-thread:not([data-sheet="collapsed"]) .tt-thread-title:has(.tt-thread-turn:not([hidden])) .tt-thread-role { display: none; }

.tt-root[data-layout="sheet"] .tt-thread:not([data-sheet="collapsed"]) .tt-thread-turn:not([hidden]) { display: block; }

.tt-strip-line {
    display: none;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--tt-text);
    font-size: 0.9rem;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* the messages */

.tt-thread-log {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding: 12px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--tt-gold-dim) transparent;
}

.tt-msg {
    display: flex;
    gap: 9px;
    align-items: flex-start;
}

.tt-msg-body {
    min-width: 0;
}

.tt-msg-name {
    margin-bottom: 1px;
    color: var(--tt-gold);
    font-family: var(--tt-serif);
    font-size: 0.74rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.tt-msg-text {
    margin: 0;
    color: #f4ecd9;
    font-size: 0.97rem;
    line-height: 1.5;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.tt-msg .tt-avatar {
    width: 32px;
    height: 32px;
    border-width: 1px;
}

.tt-msg-tod .tt-msg-text {
    color: #fff3d4;
}

/* Framed area description card when Tod introduces a place */
.tt-msg-scene-intro {
    padding: 11px 13px;
    border: 1px solid rgba(226, 185, 90, 0.56);
    border-left: 3px solid var(--tt-gold);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(38, 30, 18, 0.84), rgba(16, 15, 20, 0.9));
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 232, 168, 0.16);
}

.tt-msg-scene-intro .tt-msg-body {
    flex: 1;
}

.tt-scene-intro-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(226, 185, 90, 0.22);
}

.tt-scene-intro-head .tt-msg-name {
    margin-bottom: 0;
}

.tt-scene-intro-badge {
    padding: 2px 7px;
    border: 1px solid rgba(226, 185, 90, 0.42);
    border-radius: 999px;
    background: rgba(226, 185, 90, 0.14);
    color: var(--tt-gold-hi);
    font-family: var(--tt-serif);
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 65%;
}

.tt-msg-scene-intro .tt-msg-text {
    color: #fbf0d3;
    font-size: 0.94rem;
    line-height: 1.56;
}

.tt-msg-npc .tt-msg-name {
    color: #9fd0f0;
}

.tt-msg-player {
    justify-content: flex-end;
}

.tt-msg-player .tt-msg-body {
    max-width: 88%;
    padding: 7px 12px;
    border: 1px solid rgba(226, 185, 90, 0.35);
    border-radius: 14px 14px 3px 14px;
    background: rgba(226, 185, 90, 0.16);
}

.tt-msg-player.is-queued .tt-msg-body {
    border-style: dashed;
    opacity: 0.8;
}

/* a line typed while the table is busy: marked as waiting until it is sent */
.tt-msg-queued {
    display: block;
    margin-top: 2px;
    color: var(--tt-muted);
    font-size: 0.72rem;
    font-style: italic;
}

.tt-msg-system {
    justify-content: center;
}

.tt-msg-system .tt-msg-text {
    color: var(--tt-muted);
    font-size: 0.82rem;
    font-style: italic;
    text-align: center;
}

.tt-msg-roll {
    justify-content: center;
}

/* the status of the answer to come: an empty message of Tod's (his portrait, the site's spinner, what is happening) where the answer will be */

.tt-msg-thinking .tt-msg-text {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--tt-muted);
    font-style: italic;
}

.tt-msg-thinking .option-generation-spinner,
.tt-strip-line .option-generation-spinner {
    flex: none;
    width: 1.1rem;
    height: 1.1rem;
    border-width: 3px;
    color: var(--tt-gold);
}

/* the "is thinking" line of the side panel: a spinner that is seen at a glance */
.tt-msg-thinking .option-generation-spinner {
    width: 2.6rem;
    height: 2.6rem;
    border-width: 4px;
}

.tt-strip-line .option-generation-spinner { margin-right: 8px; }

.tt-thread-root.is-thinking .tt-thread-tab { animation: tt-tab-pulse 1.4s ease-in-out infinite; }

@keyframes tt-tab-pulse {
    50% { box-shadow: 0 0 14px rgba(246, 220, 146, 0.7); }
}

@media (prefers-reduced-motion: reduce) {
    .tt-thread-root.is-thinking .tt-thread-tab { animation: none; }
}

/* the initiative of a fight: every combatant in turn order, the sides told apart by colour */

.tt-msg-initiative { justify-content: center; }

.tt-initcard {
    width: 100%;
    padding: 6px 10px 8px;
    border: 1px solid rgba(226, 185, 90, 0.35);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
}

.tt-init-title {
    margin-bottom: 4px;
    color: var(--tt-gold-hi);
    font-family: var(--tt-serif);
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.tt-init-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tt-init-row {
    display: grid;
    grid-template-columns: 1.2em minmax(0, 1fr) auto;
    grid-template-areas: "rank name total" ". math math";
    align-items: center;
    gap: 1px 8px;
    padding: 3px 8px 3px 6px;
    border-left: 4px solid var(--tt-gold-dim);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
}

.tt-init-row.tt-side-foe { border-left-color: #c4574d; background: rgba(196, 87, 77, 0.1); }
.tt-init-row.tt-side-neutral { border-left-color: #6f8a74; }
.tt-init-rank { grid-area: rank; color: var(--tt-muted); font-size: 0.78rem; text-align: right; }
.tt-init-name { grid-area: name; overflow: hidden; font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; }
.tt-init-math { grid-area: math; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.tt-init-total { grid-area: total; color: #fff; font-family: var(--tt-serif); font-size: 1.15rem; font-weight: 700; }
.tt-initcard .tt-die { min-width: 22px; height: 22px; font-size: 0.8rem; border-radius: 5px; }
.tt-initcard .tt-roll-part { font-size: 0.78rem; }

/* suggestions and the input */

.tt-suggestions {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 12px 8px;
}

.tt-chip {
    max-width: 100%;
    min-height: 36px;
    padding: 4px 12px;
    overflow: hidden;
    border: 1px solid rgba(226, 185, 90, 0.45);
    border-radius: 18px;
    background: rgba(226, 185, 90, 0.1);
    color: var(--tt-gold-hi);
    font-size: 0.84rem;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.tt-chip:hover {
    background: rgba(226, 185, 90, 0.25);
}

.tt-thread-form {
    flex: none;
    padding: 10px 12px 12px;
    border-top: 1px solid rgba(226, 185, 90, 0.2);
}

/* the box a line is written in (tt/ui `typeBox`: Tod's thread's and the conversation panel's, as wide as what holds it): the send button stands in its bottom-right
   corner, over the text area, and the text keeps clear of it by the box's own padding: at the right of every line while the box is one line high, at the bottom where
   the thread's box is a tall one (a dock, below) */
.tt-input-box {
    position: relative;
    display: flex;
}

.tt-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 14px;
    padding-right: calc(14px + 36px);
    border: 1px solid rgba(226, 185, 90, 0.35);
    border-radius: 22px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--tt-text);
    font-family: var(--tt-body);
    font-size: 16px;
    line-height: 1.3;
    resize: none;
    user-select: text;
}

/* a wide screen docks the conversation at the side: its box takes five times the height of the single-line one (44px), and the text keeps clear of
   the button at its bottom (its last lines), not at the right of every line */
.tt-root[data-layout="dock"] .tt-thread-form .tt-input {
    min-height: calc(5 * 44px);
    max-height: 320px;
    padding-right: 14px;
    padding-bottom: 52px;
}

.tt-input::placeholder {
    color: #8c8574;
}

.tt-input:focus {
    border-color: var(--tt-gold);
    outline: none;
}

/* the send button: the whole 44px is its target for a finger, its face (`.tt-send-face`) a smaller disc that sits whole inside a box of one line */
.tt-send {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: #231a08;
    cursor: pointer;
}

.tt-send-face {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(180deg, #e8c773, #b88d34);
}

.tt-send:disabled,
.tt-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* the bottom sheet of a portrait screen */

.tt-root[data-layout="sheet"] .tt-thread {
    left: 0;
    right: 0;
    bottom: var(--tt-hotbar-h);
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    transition: height 0.28s ease;
}

.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] { height: 54px; }
.tt-root[data-layout="sheet"] .tt-thread[data-sheet="half"] { height: min(40%, 380px); }
.tt-root[data-layout="sheet"] .tt-thread[data-sheet="full"] { height: calc(100% - var(--tt-hotbar-h) - 60px); }

.tt-root[data-layout="sheet"] .tt-thread-fold {
    display: none;
}

.tt-root[data-layout="sheet"] .tt-thread-head {
    position: relative;
    min-height: 54px;
    padding-top: 7px;
    padding-bottom: 7px;
    cursor: pointer;
}

.tt-root[data-layout="sheet"] .tt-thread-head::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 50%;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 2px;
    background: rgba(226, 185, 90, 0.5);
}

.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] .tt-thread-title {
    display: none;
}

.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] .tt-strip-line {
    display: block;
}

.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] .tt-thread-log,
.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] .tt-thread-form,
.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] .tt-suggestions {
    display: none;
}

.tt-root[data-layout="sheet"] .tt-thread[data-sheet="collapsed"] .tt-thread-head {
    border-bottom: 0;
}

/* a roll's card waits for the dice to settle */
.tt-msg-roll.is-pending { visibility: hidden; }
