/* What the table asks of the player: the cast flow's panel (tt/aim), the card of a reaction (tt/reaction_prompt), the level-up panel (tt/level_up) and the
 * character sheet (tt/sheet). They use the table's own tokens (tabletop.css) and its window rule (the journal's: sized to the visible viewport, scrolling inside).
 * Every control is at least 44px on a touch screen (`is-touch`) and the panels hold at 360px. */

/* --- The cast flow ----------------------------------------------------------------------------------------------------------- */

.tt-aim {
    position: absolute;
    z-index: 25;
    top: calc(var(--tt-top-band, 56px) + 8px);
    left: 50%;
    transform: translateX(-50%);
    box-sizing: border-box;
    width: min(440px, calc(100% - 32px));
    max-height: calc(100dvh - var(--tt-top-band, 56px) - var(--tt-hotbar-h) - 40px);
    display: flex;
    flex-direction: column;
    padding: 10px 12px 12px;
    border: 1px solid var(--tt-gold);
    border-radius: 14px;
    background: var(--tt-glass);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.6);
}

.tt-aim-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
    padding-right: 80px;
    position: relative;
}

.tt-aim-title {
    margin: 0;
    font-family: var(--tt-serif);
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    color: var(--tt-gold-hi);
}

.tt-aim-summary {
    color: var(--tt-muted);
    font-size: 0.85rem;
}

.tt-aim-close,
.tt-aim-fold {
    position: absolute;
    top: -4px;
    right: -6px;
}

.tt-aim-fold {
    right: 36px;
}

/* folded: only the question and the buttons, so that the map under the panel can be tapped */
.tt-aim.is-folded .tt-aim-body > :not(.tt-aim-ask) {
    display: none;
}

.tt-aim-body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tt-aim-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}

.tt-aim-label {
    color: var(--tt-gold);
    font-family: var(--tt-serif);
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.tt-aim-hint,
.tt-aim-note {
    margin: 4px 0 0;
    color: var(--tt-muted);
    font-size: 0.85rem;
}

.tt-aim-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tt-aim-number {
    width: 5rem;
    padding: 4px 6px;
}

.tt-aim-candidates {
    max-height: 92px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tt-aim-chip {
    min-width: 40px;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--tt-line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--tt-text);
    cursor: pointer;
}

.tt-aim-chip:hover {
    border-color: var(--tt-gold);
}

.tt-aim-chip.is-on {
    border-color: var(--tt-gold-hi);
    background: rgba(226, 185, 90, 0.22);
    color: var(--tt-gold-hi);
}

.tt-aim-check {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    margin-top: 8px;
    cursor: pointer;
}

.tt-aim-check input {
    width: 20px;
    height: 20px;
    accent-color: var(--tt-gold);
}

.tt-aim-ask {
    margin: 10px 0 0;
    color: var(--tt-text);
}

.tt-aim-ask.is-ready {
    color: var(--tt-green);
}

.tt-aim-split {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tt-aim-split-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tt-aim-split-count {
    min-width: 1.5em;
    text-align: center;
    font-weight: 700;
}

.tt-aim-actions,
.tt-reaction-actions,
.tt-levelup-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

.tt-aim-actions .tt-btn-primary {
    flex: 1;
}

/* on a portrait screen the map is what is aimed at: the panel takes the foot of the screen while it asks (the hotbar and Tod's sheet, which cannot be used
 * meanwhile, are out of the way under it), and the map is framed above it (tabletop.js `measureInsets`) */
.tt-root[data-layout="sheet"].is-aiming .tt-hotbar,
.tt-root[data-layout="sheet"].is-aiming .tt-thread {
    visibility: hidden;
}

.tt-root[data-layout="sheet"] .tt-aim {
    top: auto;
    bottom: 8px;
    max-height: 50dvh;
    padding: 8px 10px 10px;
    background: rgba(14, 16, 22, 0.88);
}

.tt-root[data-layout="sheet"] .tt-aim-group {
    margin-top: 6px;
}

.tt-root[data-layout="sheet"] .tt-aim-summary,
.tt-root[data-layout="sheet"] .tt-aim-hint {
    display: none;
}

.tt-root.is-touch .tt-aim-chip,
.tt-root.is-touch .tt-aim-check {
    min-height: 44px;
}

/* --- A reaction waits for the player ---------------------------------------------------------------------------------------------- */

.tt-reaction {
    position: absolute;
    z-index: 70;
    top: 22%;
    left: 50%;
    transform: translateX(-50%);
    box-sizing: border-box;
    width: min(440px, calc(100% - 24px));
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 14px 16px 12px;
    border: 2px solid var(--tt-orange);
    border-radius: 14px;
    background: var(--tt-glass);
    box-shadow: 0 0 0 9999px rgba(5, 6, 9, 0.35), 0 16px 44px #000;
}

.tt-reaction-title {
    margin: 0 0 6px;
    font-family: var(--tt-serif);
    font-size: 1.15rem;
    color: var(--tt-gold-hi);
}

.tt-reaction-text {
    margin: 0;
}

.tt-reaction-setting {
    margin-top: 10px;
    color: var(--tt-muted);
    font-size: 0.85rem;
}

/* --- The level-up panel -------------------------------------------------------------------------------------------------------- */

.tt-levelup-backdrop,
.tt-rest-backdrop {
    z-index: 48;
}

.tt-levelup {
    --tt-dialog-width: 600px;
}

.tt-levelup .tt-journal-body {
    padding-bottom: 8px;
}

.tt-levelup-actions {
    padding: 10px 20px 14px;
    border-top: 1px solid rgba(226, 185, 90, 0.25);
}

.tt-levelup-choice {
    margin-bottom: 14px;
    padding: 4px 0 10px;
    border-bottom: 1px solid rgba(226, 185, 90, 0.14);
}

.tt-levelup-source,
.tt-levelup-earlier,
.tt-levelup-count {
    margin: 0 0 6px;
    color: var(--tt-muted);
    font-size: 0.85rem;
}

.tt-levelup-earlier {
    color: var(--tt-orange);
    text-transform: none;
    letter-spacing: 0;
}

.tt-levelup-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 6px;
}

.tt-levelup-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 4px 10px;
    border: 1px solid rgba(226, 185, 90, 0.22);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    cursor: pointer;
}

.tt-levelup-option:has(input:checked) {
    border-color: var(--tt-gold-hi);
    background: rgba(226, 185, 90, 0.16);
}

.tt-levelup-option input {
    width: 20px;
    height: 20px;
    accent-color: var(--tt-gold);
}

.tt-levelup-select,
.tt-levelup-number {
    min-height: 40px;
    padding: 0 8px;
    border: 1px solid var(--tt-line);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.4);
    color: var(--tt-text);
}

.tt-levelup-number {
    width: 4.5em;
}

.tt-levelup-select {
    width: 100%;
}

.tt-levelup-point,
.tt-rest-hero {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.tt-levelup-ability,
.tt-rest-name {
    flex: 1;
}

.tt-levelup-value,
.tt-rest-count {
    min-width: 1.5em;
    text-align: center;
    font-weight: 700;
}

.tt-levelup-others {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 8px;
}

/* --- The short rest: the Hit Dice each hero spends ------------------------------------------------------------------------------ */

.tt-rest {
    --tt-dialog-width: 480px;
}

.tt-rest-intro {
    margin: 0 0 10px;
    color: var(--tt-muted);
}

.tt-rest-hero {
    padding: 6px 0;
    border-bottom: 1px solid rgba(226, 185, 90, 0.14);
}

.tt-rest-name {
    min-width: 0;
}

.tt-rest-name small {
    display: block;
    color: var(--tt-muted);
    font-size: 0.85rem;
}

/* --- The character sheet ------------------------------------------------------------------------------------------------------- */

.tt-sheet {
    --tt-dialog-width: 760px;
}

.tt-sheet-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 20px;
}

.tt-sheet-head,
.tt-sheet-vitals,
.tt-sheet-abilities,
.tt-sheet-wide {
    grid-column: 1 / -1;
}

.tt-sheet-head {
    display: flex;
    align-items: center;
    gap: 14px;
}

.tt-sheet-face {
    flex: none;
    width: 64px;
    height: 64px;
    overflow: hidden;
    border: 1px solid var(--tt-gold-dim);
    border-radius: 50%;
}

.tt-sheet-face img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tt-sheet-name,
.tt-sheet-class,
.tt-sheet-kind {
    margin: 0;
}

.tt-sheet-name {
    font-family: var(--tt-serif);
    font-size: 1.3rem;
    color: var(--tt-gold-hi);
}

.tt-sheet-class,
.tt-sheet-kind {
    color: var(--tt-muted);
}

.tt-sheet-vitals {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 6px 0;
}

.tt-sheet-stat {
    display: flex;
    flex: 1 1 110px;
    flex-direction: column;
    align-items: center;
    padding: 6px 8px;
    border: 1px solid rgba(226, 185, 90, 0.25);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
}

.tt-sheet-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.tt-sheet-stat-label {
    color: var(--tt-muted);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.tt-sheet-conditions {
    flex-basis: 100%;
    margin: 0;
}

.tt-sheet-abilities {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
}

.tt-sheet-ability {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 2px;
    border: 1px solid rgba(226, 185, 90, 0.25);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
}

.tt-sheet-ability-name {
    color: var(--tt-gold);
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.tt-sheet-ability strong {
    font-size: 1.2rem;
}

.tt-sheet-ability small {
    color: var(--tt-muted);
}

.tt-sheet-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.tt-sheet-list li {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-height: 26px;
    padding: 1px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tt-sheet-list li > span:not(.tt-sheet-mark) {
    flex: 1;
}

.tt-sheet-list em {
    color: var(--tt-muted);
    font-size: 0.8rem;
}

.tt-sheet-list .is-trained {
    color: var(--tt-gold-hi);
}

.tt-sheet-mark {
    flex: none;
    width: 1.6em;
    color: var(--tt-gold);
    font-size: 0.7rem;
}

.tt-sheet-subtitle {
    margin: 8px 0 2px;
    color: var(--tt-muted);
    font-size: 0.8rem;
}

.tt-sheet-spells p {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
}

.tt-sheet-spell {
    padding: 2px 10px;
    border: 1px solid rgba(226, 185, 90, 0.25);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.3);
}

/* the gear of the character sheet: each worn or carried item with the buttons of its hotbar entries and the engine's words for what is refused */
.tt-sheet-attunement {
    margin: 0 0 6px;
    color: var(--tt-gold-hi);
    font-size: 0.85rem;
}

.tt-gear-list,
.tt-gear-reasons {
    margin: 0;
    padding: 0;
    list-style: none;
}

.tt-gear-item {
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.tt-gear-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
}

.tt-gear-name {
    font-weight: 600;
}

.tt-gear-slot {
    color: var(--tt-muted);
    font-size: 0.8rem;
}

.tt-gear-badge {
    padding: 0 8px;
}

.tt-gear-badge.is-attuned {
    background: #3f6b4a;
}

.tt-gear-facts,
.tt-gear-reason {
    margin: 2px 0 0;
    color: var(--tt-muted);
    font-size: 0.8rem;
}

.tt-gear-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.tt-gear-button {
    min-height: 40px;
    padding: 0 12px;
}

.tt-aim-select {
    display: block;
    width: 100%;
    min-height: 40px;
    margin-top: 4px;
    padding: 0 8px;
    border: 1px solid var(--tt-line);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.4);
    color: var(--tt-text);
}

@media (max-width: 560px) {
    .tt-sheet-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .tt-sheet-abilities {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .tt-levelup-options {
        grid-template-columns: minmax(0, 1fr);
    }
}

.tt-levelup-swap {
    margin: 0 0 8px;
    padding: 4px 8px;
    border: 1px solid var(--tt-line);
    border-radius: 8px;
}

.tt-levelup-option.is-unmet {
    opacity: 0.55;
}
