/* ============================================
   TABLETOP — the generic table canvas, and the
   Deck subtab's Free Form view built on it.

   The Playtest battlefield uses the same canvas
   with its own classes layered on top (see
   goldfish.css); everything under .table-* is
   shared, everything under .deck-table-* is the
   Free Form view.
   ============================================ */

/* ---- Canvas ---------------------------------------------------------- */

.table-viewport {
    position: relative;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    --battlefield-grid-line: color-mix(in srgb, var(--text-muted) 12%, transparent);
    --battlefield-grid-major: color-mix(in srgb, var(--accent-color) 16%, transparent);
}

.table-viewport.gridded {
    background-image:
        linear-gradient(to right, var(--battlefield-grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--battlefield-grid-line) 1px, transparent 1px),
        linear-gradient(to right, var(--battlefield-grid-major) 1px, transparent 1px),
        linear-gradient(to bottom, var(--battlefield-grid-major) 1px, transparent 1px);
    background-repeat: repeat;
}

.table-viewport.panning {
    cursor: grabbing;
}

@supports not (color: color-mix(in srgb, red 50%, transparent)) {
    .table-viewport {
        --battlefield-grid-line: rgba(148, 163, 184, 0.12);
        --battlefield-grid-major: rgba(148, 163, 184, 0.2);
    }
}

.table-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.table-card-image {
    width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    pointer-events: none;
}

/* ---- Free Form view --------------------------------------------------- */

.deck-table-view {
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* The table needs real height; the deck-zone-content it sits in is
       content-sized, so this is where the height is decided. */
    height: clamp(420px, 68vh, 900px);
    min-height: 0;
}

.deck-table-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    /* The same ground as the Playtest battlefield. */
    background: var(--bg-tertiary);
}

.deck-table-viewport {
    flex: 1;
    cursor: crosshair;
}

.deck-table-viewport.panning {
    cursor: grabbing;
}

/* ---- Toolbar ---------------------------------------------------------- */

.deck-table-toolbar {
    display: flex;
    align-items: center;
    /* One row, always. When the buttons will not fit, the bar drops their
       captions (`.compact`) rather than wrapping to a second line. */
    flex-wrap: nowrap;
    overflow: hidden;
    gap: 6px 8px;
    padding: 6px 8px;
    border-radius: 10px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
}

.deck-table-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.deck-table-toolbar-divider {
    width: 1px;
    align-self: stretch;
    margin: 2px 2px;
    background: var(--border-color);
}

.deck-table-toolbar-spacer {
    flex: 1;
}

.deck-table-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-color);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.deck-table-btn .ui-icon,
.deck-table-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.deck-table-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--accent-light);
}

.deck-table-btn.active {
    background: color-mix(in srgb, var(--accent-color) 22%, transparent);
    border-color: color-mix(in srgb, var(--accent-color) 50%, transparent);
    color: var(--accent-light);
}

.deck-table-btn.btn-unavailable {
    opacity: 0.4;
}

.deck-table-arrange-select {
    padding: 5px 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.deck-table-selection-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0 6px;
    min-width: 0;
}

.deck-table-selection-count.empty {
    display: none;
}

/* ---- Highlight swatches ---------------------------------------------- */

.deck-table-highlights {
    gap: 5px;
}

.deck-table-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: var(--swatch, #888);
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s, border-color 0.12s;
}

.deck-table-swatch:hover {
    transform: scale(1.15);
    border-color: #fff;
}

.deck-table-swatch.btn-unavailable {
    opacity: 0.35;
}

.deck-table-swatch.swatch-clear {
    background: transparent;
    border-style: dashed;
    color: var(--text-muted);
}

.deck-table-swatch.swatch-clear .ui-icon,
.deck-table-swatch.swatch-clear svg {
    width: 10px;
    height: 10px;
}

.swatch-red    { --swatch: #ef4444; }
.swatch-orange { --swatch: #f97316; }
.swatch-yellow { --swatch: #eab308; }
.swatch-green  { --swatch: #22c55e; }
.swatch-blue   { --swatch: #3b82f6; }
.swatch-purple { --swatch: #a855f7; }

/* ---- Cards ------------------------------------------------------------ */

.table-card {
    width: 120px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    cursor: grab;
    /* Position and rotation are inline; only the lift animates. */
    transition: box-shadow 0.15s, opacity 0.2s, outline-color 0.15s;
    outline: 3px solid transparent;
    outline-offset: 2px;
}

.table-card:hover {
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.6);
    /* Above every unhovered card, whatever their paint order. */
    z-index: 100000 !important;
}

.table-card:active {
    cursor: grabbing;
}

.table-card.selected {
    outline-color: var(--accent-color);
    box-shadow: 0 0 20px var(--accent-glow), 0 4px 12px rgba(0, 0, 0, 0.5);
}

.table-card.dimmed {
    opacity: 0.28;
    filter: grayscale(0.6);
}

/* Spotlight: everything not selected recedes. */
.deck-table-view.spotlight .table-card:not(.selected) {
    opacity: 0.18;
    filter: grayscale(0.8) brightness(0.8);
}

.deck-table-view.spotlight .table-note {
    opacity: 0.35;
}

/* Highlight rings. A highlight is a colour *around* the card, kept distinct
   from the accent-coloured selection ring by sitting outside it. */
.table-card[class*="highlight-"] {
    box-shadow:
        0 0 0 3px var(--highlight),
        0 0 18px var(--highlight),
        0 4px 12px rgba(0, 0, 0, 0.5);
}

.table-card.highlight-red    { --highlight: #ef4444; }
.table-card.highlight-orange { --highlight: #f97316; }
.table-card.highlight-yellow { --highlight: #eab308; }
.table-card.highlight-green  { --highlight: #22c55e; }
.table-card.highlight-blue   { --highlight: #3b82f6; }
.table-card.highlight-purple { --highlight: #a855f7; }

.table-card.selected[class*="highlight-"] {
    box-shadow:
        0 0 0 3px var(--highlight),
        0 0 24px var(--highlight),
        0 0 20px var(--accent-glow);
}

.table-card-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--popup-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--accent-light);
    pointer-events: none;
}

.table-card-badge .ui-icon,
.table-card-badge svg {
    width: 12px;
    height: 12px;
}

.table-card-companion {
    left: auto;
    right: -8px;
}

/* ---- Notes ------------------------------------------------------------ */

.table-note {
    width: 180px;
    min-height: 72px;
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    background: #fbe89a;
    color: #2b2410;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    /* Notes sit above cards: they are captions, and a card dragged over
       one would otherwise hide it. */
    z-index: 200000;
    font-size: 0.8rem;
    --note: #fbe89a;
}

.table-note.note-red    { --note: #fecaca; }
.table-note.note-orange { --note: #fed7aa; }
.table-note.note-yellow { --note: #fef08a; }
.table-note.note-green  { --note: #bbf7d0; }
.table-note.note-blue   { --note: #bfdbfe; }
.table-note.note-purple { --note: #e9d5ff; }

.table-note[class*="note-"] {
    background: var(--note);
}

.table-note.dragging {
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
}

.table-note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 6px;
    cursor: grab;
    border-bottom: 1px solid rgba(0, 0, 0, 0.12);
    opacity: 0.85;
}

.table-note-grip {
    font-size: 0.7rem;
    letter-spacing: -2px;
    opacity: 0.6;
}

.table-note-tools {
    display: flex;
    gap: 2px;
}

.table-note-tool {
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 5px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.table-note-tool:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.table-note-tool .ui-icon,
.table-note-tool svg {
    width: 12px;
    height: 12px;
}

.table-note-palette {
    display: flex;
    gap: 5px;
    padding: 5px 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.table-note-body,
.table-note-field {
    display: flex;
    flex: 1;
    min-height: 0;
}

.table-note-field {
    width: 100%;
}

.table-note-text {
    flex: 1;
    width: 100%;
    min-height: 44px;
    resize: none;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: 1.3;
    padding: 6px 8px;
    outline: none;
    cursor: text;
}

.table-note-text::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

/* ---- Context menu additions ------------------------------------------ */

.deck-table-menu .context-menu-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 4px 10px 2px;
}

.deck-table-menu-swatches {
    display: flex;
    gap: 6px;
    padding: 4px 10px 6px;
}

.deck-table-menu .context-menu-item--danger:hover {
    color: var(--danger-color);
}

/* ---- Presentation mode ----------------------------------------------- */

.deck-table-present-bar {
    display: none;
}

.deck-table-spotlight {
    display: none;
}

.deck-table-view.presenting {
    /* Mounted directly under <body> by a portal, so no transformed or
       filtered ancestor can capture this `fixed` box. */
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 0;
    background: #0d1117;
}

.deck-table-presenting-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    border: 1px dashed var(--border-color);
    border-radius: 12px;
}

.deck-table-view.presenting .deck-table-toolbar {
    display: none;
}

.deck-table-view.presenting .deck-table-stage {
    border: none;
    border-radius: 0;
    background:
        radial-gradient(ellipse at 50% 20%, rgba(255, 255, 255, 0.05), transparent 65%),
        #14181f;
}

.deck-table-view.presenting .deck-table-present-bar {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(20, 24, 31, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    opacity: 0.35;
    transition: opacity 0.2s;
}

.deck-table-view.presenting .deck-table-present-bar:hover {
    opacity: 1;
}

.deck-table-view.presenting .deck-table-spotlight {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: min(320px, 28vw);
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.deck-table-spotlight-image {
    width: 100%;
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.deck-table-spotlight-text {
    background: rgba(20, 24, 31, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 10px 12px;
    color: #e6edf3;
}

.deck-table-spotlight-name {
    font-weight: 800;
    font-size: 1rem;
}

.deck-table-spotlight-type {
    font-size: 0.75rem;
    color: #9da7b3;
    margin-bottom: 6px;
}

.deck-table-spotlight-oracle {
    font-size: 0.8rem;
    line-height: 1.35;
    white-space: pre-wrap;
}

/* The spotlight panel can cover the right edge of the table; leave it room. */
.deck-table-view.presenting .deck-table-viewport {
    cursor: default;
}

/* Cards read larger on a stream. */
.deck-table-view.presenting .table-card:hover {
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.7);
}

/* ---- Compact / phone --------------------------------------------------- */

@media (max-width: 768px) {
    .deck-table-view {
        height: clamp(360px, 60vh, 700px);
    }

    .deck-table-btn span {
        display: none;
    }

    .deck-table-btn {
        padding: 6px;
    }

    .deck-table-toolbar-divider {
        display: none;
    }

    .deck-table-view.presenting .deck-table-spotlight {
        display: none;
    }
}


/* ---- Selection, card actions, presentation extras ------------------- */

.table-note.selected {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 20px var(--accent-glow), 0 6px 16px rgba(0, 0, 0, 0.35);
}

.table-note-tool .ui-icon,
.table-note-tool svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    color: #2b2410;
}

.table-note-tool.danger-btn:hover {
    color: var(--danger-color, #ef4444) !important;
    background: rgba(0, 0, 0, 0.08) !important;
}

/* The flip/rotate bar at the bottom of a table card, like every other card
   image: revealed on hover, since the table is a pointer surface. */
.table-card .card-action-bar {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
}

.table-card:hover .card-action-bar,
.table-card.selected .card-action-bar {
    opacity: 1;
}

/* Presentation spotlight: as large as the Playtest hover preview, and a
   sideways card gets the turned footprint so it never clips. */
.deck-table-view.presenting .deck-table-spotlight {
    width: min(480px, 34vw);
}

.deck-table-spotlight-frame {
    display: flex;
    align-items: center;
    justify-content: center;
}

.deck-table-spotlight-frame.sideways {
    --sideways-spotlight: min(480px, 34vw);
    width: var(--sideways-spotlight);
    height: calc(var(--sideways-spotlight) * 0.7176);
}

.deck-table-spotlight-frame.sideways .deck-table-spotlight-image {
    width: auto;
    height: var(--sideways-spotlight);
    max-width: none;
}

.deck-table-spotlight-image {
    transform-origin: center center;
}

.deck-table-spotlight-text {
    max-height: 38vh;
    overflow-y: auto;
}

.deck-table-oracle-line {
    margin: 0 0 6px;
    font-size: 0.82rem;
    line-height: 1.4;
}

.deck-table-oracle-line:last-child {
    margin-bottom: 0;
}

.oracle-symbol {
    width: 0.95em;
    height: 0.95em;
    vertical-align: -0.12em;
    margin: 0 1px;
}

.deck-table-view.presenting .deck-table-present-filters {
    position: absolute;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    width: min(880px, 92vw);
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(20, 24, 31, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.deck-table-present-filters {
    display: none;
}

.deck-table-view.presenting .deck-table-present-filters {
    display: block;
}


/* ---- Single-row toolbar: icon-only when cramped ----------------------- */

.deck-table-toolbar.compact .deck-table-btn span {
    display: none;
}

.deck-table-toolbar.compact .deck-table-btn {
    padding: 6px;
}

.deck-table-toolbar.compact .deck-table-arrange-select {
    max-width: 96px;
}

/* ---- Selection badge, top-right of the table ------------------------- */

.deck-table-selection-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    padding: 4px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent-color) 30%, rgba(20, 24, 31, 0.85));
    border: 1px solid color-mix(in srgb, var(--accent-color) 60%, transparent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.deck-table-selection-badge.empty {
    display: none;
}

/* Playtest's board settings use the same Snap / Grid toggles as the table. */
.playtest-board-toggles {
    display: flex;
    gap: 4px;
}


/* ---- Zones on the table ------------------------------------------------ */

.table-zone {
    z-index: 0;
    border-radius: 14px;
    border: 2px dashed color-mix(in srgb, var(--accent-color) 45%, transparent);
    background: color-mix(in srgb, var(--accent-color) 8%, transparent);
    box-sizing: border-box;
    transition: border-color 0.15s, background 0.15s;
}

.table-zone.drop-ready {
    border-color: color-mix(in srgb, var(--accent-color) 85%, transparent);
    background: color-mix(in srgb, var(--accent-color) 16%, transparent);
}

.table-zone.dragging {
    border-style: solid;
}

.table-zone.zone-command-zone {
    border-color: color-mix(in srgb, #eab308 55%, transparent);
    background: color-mix(in srgb, #eab308 8%, transparent);
}

.table-zone.zone-maybeboard {
    border-color: color-mix(in srgb, var(--text-muted) 45%, transparent);
    background: color-mix(in srgb, var(--text-muted) 8%, transparent);
}

.table-zone-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 28px;
    padding: 0 12px;
    cursor: grab;
    user-select: none;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.table-zone-header:active {
    cursor: grabbing;
}

.table-zone-count {
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-color);
    font-size: 0.7rem;
}

.table-zone-resize {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    border-right: 3px solid color-mix(in srgb, var(--accent-color) 60%, transparent);
    border-bottom: 3px solid color-mix(in srgb, var(--accent-color) 60%, transparent);
    border-bottom-right-radius: 10px;
    opacity: 0.7;
}

.table-zone-resize:hover {
    opacity: 1;
}

/* The deck toolbar's sort control is meaningless on the table. */
.sort-select-container.table-hidden {
    display: none;
}

/* ---- Sticky-note contrast ---------------------------------------------- */

.table-note .table-note-tool,
.table-note .table-note-tool .ui-icon,
.table-note .table-note-tool svg {
    color: rgba(30, 24, 8, 0.85);
    stroke: rgba(30, 24, 8, 0.85);
}

.table-note .table-note-tool:hover {
    background: rgba(0, 0, 0, 0.14);
}

.table-note .standard-text-field-affix,
.table-note .standard-text-field-count,
.table-note .standard-text-field-clear {
    color: rgba(30, 24, 8, 0.7);
    background: transparent;
    border: none;
    box-shadow: none;
}

.table-note .standard-text-field-clear:hover {
    color: rgba(30, 24, 8, 1);
    background: rgba(0, 0, 0, 0.12);
}

/* ---- Spotlight sections ------------------------------------------------ */

.deck-table-spotlight-divider {
    height: 1px;
    margin: 8px 0;
    background: rgba(255, 255, 255, 0.14);
}

.deck-table-spotlight-section.secondary .deck-table-spotlight-name {
    font-size: 0.9rem;
    color: #c9d1d9;
}

.context-menu-card-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Free Form is a desktop view. */
@media (max-width: 768px) {
    /* Specific and `!important`: the toggle cluster's own display rule for
       its buttons otherwise wins and the button stays visible but inert. */
    .toolbar-view-toggles .toolbar-view-btn--table,
    .toolbar-view-btn--table {
        display: none !important;
    }
}


/* ---- Piles ------------------------------------------------------------- */

/* Copies squared up on one another wear the Stack view's count badge on the
   top copy, top-right so the name strip stays readable. */
.table-card .table-card-pile-count {
    position: absolute;
    top: -8px;
    right: -8px;
    z-index: 3;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

/* ---- Caption frames ---------------------------------------------------- */

/* The reader's own boxes: the zone look, in the highlight colours, and
   selectable like anything else. */
.table-frame {
    --frame: var(--accent-color);
    border-color: color-mix(in srgb, var(--frame) 45%, transparent);
    background: color-mix(in srgb, var(--frame) 7%, transparent);
}

.table-frame.frame-red    { --frame: #ef4444; }
.table-frame.frame-orange { --frame: #f97316; }
.table-frame.frame-yellow { --frame: #eab308; }
.table-frame.frame-green  { --frame: #22c55e; }
.table-frame.frame-blue   { --frame: #3b82f6; }
.table-frame.frame-purple { --frame: #a855f7; }

.table-frame.selected {
    border-style: solid;
    border-color: var(--frame);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--frame) 30%, transparent);
}

.table-frame .table-zone-header {
    color: color-mix(in srgb, var(--frame) 70%, var(--text-color));
}

.table-frame .table-zone-resize {
    border-color: color-mix(in srgb, var(--frame) 70%, transparent);
}

.table-frame-label-field {
    flex: 1;
    min-width: 0;
    margin-right: 8px;
}

.table-frame-label-input {
    width: 100%;
    padding: 2px 6px;
    font: inherit;
    font-size: 0.78rem;
    letter-spacing: normal;
    text-transform: none;
    border-radius: 4px;
    border: 1px solid var(--frame);
    background: var(--input-bg);
    color: var(--text-color);
}

/* ---- Arrows ------------------------------------------------------------ */

.deck-table-arrows {
    /* Above the cards, below the notes. */
    z-index: 150000;
    pointer-events: none;
}

.table-arrow {
    --arrow: var(--accent-light, var(--accent-color));
    pointer-events: none;
}

.table-arrow.arrow-red    { --arrow: #ef4444; }
.table-arrow.arrow-orange { --arrow: #f97316; }
.table-arrow.arrow-yellow { --arrow: #eab308; }
.table-arrow.arrow-green  { --arrow: #22c55e; }
.table-arrow.arrow-blue   { --arrow: #3b82f6; }
.table-arrow.arrow-purple { --arrow: #a855f7; }

/* A fat invisible shaft to grab, then the visible one. */
.table-arrow-grab {
    stroke: transparent;
    stroke-width: 18;
    stroke-linecap: round;
    pointer-events: stroke;
    cursor: grab;
}

.table-arrow-grab:active {
    cursor: grabbing;
}

.table-arrow-shaft {
    stroke: var(--arrow);
    stroke-width: 4;
    stroke-linecap: round;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

.table-arrow-head {
    fill: var(--arrow);
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

.table-arrow.selected .table-arrow-shaft {
    stroke-width: 5;
    filter: drop-shadow(0 0 4px color-mix(in srgb, var(--arrow) 80%, white));
}

.table-arrow-handle {
    fill: var(--bg-color);
    stroke: var(--arrow);
    stroke-width: 3;
    pointer-events: all;
    cursor: move;
}

.table-arrow-caption-box {
    overflow: visible;
    pointer-events: none;
}

.table-arrow-caption-box.editing {
    pointer-events: all;
}

/* The caption is a pill at the arrow's midpoint. */
.table-arrow-caption {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 28px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-color);
    pointer-events: none;
}

.table-arrow-caption::before {
    content: "";
}

.table-arrow-caption-field {
    width: 100%;
}

.table-arrow-caption-input {
    width: 100%;
    padding: 4px 8px;
    font: inherit;
    font-size: 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--arrow);
    background: var(--input-bg);
    color: var(--text-color);
    text-align: center;
}

/* ---- Widgets ----------------------------------------------------------- */

.table-widget {
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    /* With the notes: a caption over the cards, not something to bury. */
    z-index: 180000;
    overflow: hidden;
    box-sizing: border-box;
}

.table-widget.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color) 30%, transparent), 0 10px 28px rgba(0, 0, 0, 0.45);
}

.table-widget.dragging {
    opacity: 0.9;
}

.table-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 28px;
    padding: 0 8px 0 12px;
    cursor: grab;
    user-select: none;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: color-mix(in srgb, var(--accent-color) 8%, transparent);
    border-bottom: 1px solid var(--border-color);
}

.table-widget-header:active {
    cursor: grabbing;
}

.table-widget-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-widget-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 8px;
    font-size: 0.85rem;
}

/* The embedded widget fills its box rather than the Stats grid's slot. */
.table-widget-body > .stat-item,
.table-widget-body > [class$="-widget"] {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    margin: 0;
}

.table-widget-resize {
    border-color: color-mix(in srgb, var(--accent-color) 60%, transparent);
}

.table-widget-synergy,
.table-widget-combo {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
}

.table-widget-thumbs {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.table-widget-thumb {
    width: 72px;
    aspect-ratio: 63 / 88;
    border-radius: 5px;
    overflow: hidden;
    background: var(--input-bg);
    display: grid;
    place-items: center;
    font-size: 0.65rem;
    text-align: center;
    color: var(--text-muted);
}

.table-widget-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.table-widget-thumb-name {
    padding: 4px;
}

.table-widget-link {
    color: var(--accent-light);
    display: inline-flex;
}

.table-widget-caption {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: center;
}

.table-widget-caption.muted {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.8rem;
}

.table-widget-category {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-light);
    font-weight: 700;
}

.table-widget-reason {
    color: var(--text-color);
    font-weight: 600;
}

.table-widget-strength {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* The picker: a panel under the toolbar's Widget button. */
.deck-table-objects {
    position: relative;
}

.deck-table-widget-picker {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 400;
    width: min(360px, calc(100vw - 24px));
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--bg-color) 96%, transparent);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

.deck-table-widget-picker-tabs {
    display: flex;
    gap: 4px;
}

.deck-table-widget-picker-close {
    margin-left: auto;
}

.deck-table-widget-picker-search {
    width: 100%;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font: inherit;
    font-size: 0.85rem;
}

.deck-table-widget-picker-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    min-height: 0;
}

.deck-table-widget-picker-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-color);
    text-align: left;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.deck-table-widget-picker-item:hover {
    background: color-mix(in srgb, var(--accent-color) 14%, transparent);
}

.deck-table-widget-picker-main {
    font-weight: 600;
}

.deck-table-widget-picker-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.deck-table-widget-picker-empty {
    padding: 12px;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85rem;
}

/* ---- Notes that cannot be saved --------------------------------------- */

.table-note.flagged {
    outline: 2px solid #ef4444;
    outline-offset: 1px;
}

.table-note-flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* The picker is portalled to <body> (the toolbar clips its overflow), so it
   positions itself from the Widget button's rectangle; the backdrop closes it. */
.deck-table-widget-picker-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100009;
}

.deck-table-widget-picker-float .deck-table-widget-picker {
    position: static;
}

.deck-table-widget-picker-search-field {
    width: 100%;
}

/* The last resort after dropping captions: the icon row wraps onto a second
   line rather than clipping. The spacer gives way so the groups pack. */
.deck-table-toolbar.wrap {
    flex-wrap: wrap;
    overflow: visible;
}

.deck-table-toolbar.wrap .deck-table-toolbar-spacer {
    flex: 0 0 0;
}

.deck-table-toolbar.wrap .deck-table-toolbar-divider {
    align-self: center;
    height: 22px;
}

/* ---- Close buttons that read as close buttons -------------------------- */

/* On a note: a dark pill with a white glyph, whatever the note's colour. The
   global danger treatment (faint red on transparent) was invisible on yellow. */
.table-note .table-note-tool.danger-btn {
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: none;
}

.table-note .table-note-tool.danger-btn .ui-icon,
.table-note .table-note-tool.danger-btn svg {
    color: #fff;
    stroke: #fff;
}

.table-note .table-note-tool.danger-btn:hover {
    background: var(--danger-color, #ef4444) !important;
    color: #fff !important;
}

/* On a widget: header tools share one pill style; close turns red on hover. */
.table-widget-tools {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.table-widget-tool {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--text-color) 25%, transparent);
    background: color-mix(in srgb, var(--text-color) 12%, transparent);
    color: var(--text-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.table-widget-tool .ui-icon,
.table-widget-tool svg {
    width: 12px;
    height: 12px;
    color: var(--text-color);
    stroke: currentColor;
}

.table-widget-tool:hover {
    background: color-mix(in srgb, var(--accent-color) 30%, transparent);
    border-color: var(--accent-color);
}

.table-widget-tool.table-widget-close:hover {
    background: var(--danger-color, #ef4444);
    border-color: var(--danger-color, #ef4444);
    color: #fff;
}

.table-widget-tool.table-widget-close:hover .ui-icon,
.table-widget-tool.table-widget-close:hover svg {
    color: #fff;
}

/* Combo widgets carry the full outcomes + walkthrough; let them read. */
.table-widget-combo-details {
    text-align: left;
    font-size: 0.82rem;
}

.table-widget-description {
    margin: 4px 0 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-secondary, var(--text-color));
    font-weight: 400;
}

/* ---- Paint order and presentation ------------------------------------ */

/* Each arrow's SVG carries its own z-index inline (ARROW_LAYER by default,
   above notes and widgets; higher once raised). The layer div is only a home. */
.deck-table-arrows-layer {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
}

/* Presentation sits above the app but *below* the modals (card details at
   10000, the explainers at 6000), so "more information" still opens on top
   of the stage instead of behind it. */
.deck-table-view.presenting {
    z-index: 5000;
}

.deck-table-widget-picker-backdrop {
    z-index: 5009;
}

.deck-table-widget-picker-float {
    z-index: 5010 !important;
}
