/* ============================================================
   board.css: HUD, table, dock, action bar, game log
   ============================================================ */

/* ---------------- App shell ---------------- */

#app {
    display: flex;
    flex-direction: column;
}

#screens {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

/* headroom for the floating controls, which no longer take layout space */
#screen-game {
    height: 100%;
    padding-top: calc(var(--hud-h) + env(safe-area-inset-top));
}

/* ---------------- Floating controls ----------------
   Not a bar: these sit *over* whatever screen is showing, the way the in-game
   HUD always did. Out of the layout flow entirely, with only a faint scrim for
   legibility over the table. Screens reserve their own headroom below. */

#topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    height: calc(var(--hud-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--sp-4) 0;
    pointer-events: none;
    z-index: 60;
}

/*
 * No scrim. The old one existed because the controls sat over pools of
 * lamplight that could wash them out; the plate behind them is flat ink now,
 * so contrast is guaranteed and the strip can stay genuinely invisible. Each
 * control carries its own ruled frame, which is all the separation it needs.
 */

.topbar__side,
.topbar__center {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

/* only the controls themselves take clicks: the scrim must not eat them */
.topbar__side>*,
.topbar__center>* {
    pointer-events: auto;
}

.topbar__side {
    flex: 1 1 0;
    min-width: 0;
}

.topbar__side--right {
    justify-content: flex-end;
}

.topbar__center {
    flex: 0 0 auto;
}

/* ---------------- Turn pill ---------------- */

.turn-pill {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    height: 48px;
    padding: 0 22px 0 5px;
    background: var(--ink-850);
    border: 1px solid var(--rule);
    border-radius: var(--r-sm);
    transition: border-color var(--t-med), background var(--t-med);
}

/* your turn: the rule thickens rather than the plate lighting up */
.turn-pill.is-mine {
    border-color: var(--rule-strong);
    background: var(--ink-700);
}

/* running out of time: the rule alternates weight, like a warning border */
.turn-pill.is-urgent {
    animation: urgentPulse .6s var(--ease-in-out) infinite;
}

@keyframes urgentPulse {

    0%,
    100% {
        border-color: var(--oxblood);
    }

    50% {
        border-color: var(--oxblood-hot);
    }
}

/*
 * Centred on the monogram tile, not on the pill. The avatar starts at the
 * pill's 5px padding plus its own 5px margin, so the ring has to start at 5px
 * for the drawn square to sit concentric with it. At 3px the square was 2px
 * left of the tile: a visible gap down the left edge and an overlap on the
 * right. If you change the pill's padding or the avatar's margin, re-derive
 * this: left = avatarCentre - ringWidth / 2.
 */
.turn-pill__ring {
    position: absolute;
    left: 5px;
    top: 50%;
    width: 46px;
    height: 46px;
    transform: translateY(-50%);
    pointer-events: none;
}

.turn-pill__ring-bg {
    fill: none;
    stroke: var(--rule-faint);
    stroke-width: 2;
}

.turn-pill__ring-arc {
    fill: none;
    stroke: var(--gold);
    stroke-width: 2;
    stroke-linecap: butt;
    /* 136 = the perimeter of the 34x34 path above */
    stroke-dasharray: 136;
    stroke-dashoffset: 136;
    transition: stroke-dashoffset .25s linear, stroke .3s;
}

.turn-pill__ring-arc.is-low {
    stroke: var(--oxblood-hot);
}

.turn-pill__avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    margin-left: 5px;
    font-family: var(--font-engraved);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: .04em;
    color: #0a0908;
    background: var(--seat-color, var(--gold));
    border-radius: 0;
}

.turn-pill__text {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .04em;
    white-space: nowrap;
}

/* ---------------- Table area ---------------- */

#table-area {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

/*
 * #seats deliberately shares #table's exact box rather than filling the play
 * area. SEAT_LAYOUTS is expressed in percentages of the table, so the ring of
 * players hugs the felt at any size, the way the waiting-room preview does.
 * Against the play area the side seats ended up out by the screen edges,
 * because the table only occupies the middle third of it.
 *
 * The geometry below must stay identical to #table above. Nothing clips here,
 * so seats can sit outside the box (x: -8, y: 104) and still show.
 */
#seats {
    position: absolute;
    left: 50%;
    top: 56%;
    height: min(60%, 46vw);
    width: auto;
    aspect-ratio: 1.5 / 1;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 20;
    /* makes cqw units inside resolve against the table's width, so the plates
       scale with the table rather than staying a fixed size on a shrinking
       one. Size containment does not clip, so seats still show outside the
       box. */
    container-type: size;
}

/* ---------------- The table ---------------- */

/*
 * Sized off the *height* of the play area, with the width derived from it.
 * (max-height + aspect-ratio does NOT work here: the height gets clamped but
 * the width keeps its own value, which squashes the ellipse.) The 46vw term
 * stops a tall narrow window from pushing the table off the sides.
 */
#table {
    position: absolute;
    left: 50%;
    top: 56%;
    height: min(60%, 46vw);
    width: auto;
    aspect-ratio: 1.5 / 1;
    transform: translate(-50%, -50%);
    z-index: 10;
}

/*
 * Four stacked ellipses, all drawn: an outer rim, a bead rule, the crosshatched
 * baize, and a deco inlay. There is no light source any more, so the depth
 * comes from line weight stepping down as you move inward: the bead is the
 * strongest rule on the board, the innermost inlay the faintest.
 */

.table__felt {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    overflow: hidden;
    background-color: var(--felt);
    background-image: var(--hatch-cross);
    box-shadow: inset 0 0 0 1px var(--rule-faint);
}

.table__felt::after {
    /* paper tooth over the hatching, so the field is not mechanically even */
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    opacity: .16;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23f)'/%3E%3C/svg%3E");
}

/* the ruled ring set in from the cushion */
.table__felt::before {
    content: '';
    position: absolute;
    inset: 7%;
    border: 1px solid var(--rule);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
}

.table__inlay {
    position: absolute;
    inset: calc(7% + 6px);
    border: 1px solid var(--rule-faint);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
}

.table__rim {
    position: absolute;
    inset: -18px;
    border-radius: 50%;
    background-color: var(--ink-850);
    background-image: var(--hatch-fine);
    border: 1px solid var(--rule-faint);
    z-index: -2;
}

/* the bead where the rim meets the baize: the heaviest rule on the table */
.table__bead {
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 1px solid var(--rule-strong);
    z-index: -1;
}

.table__content {
    position: absolute;
    inset: 8%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 4% 0;
}

/* ---------------- Suit medallion ---------------- */

.suit-medallion {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 6px 22px 8px;
    background: var(--ink-900);
    border: 1px solid var(--rule);
    border-radius: 0;
    transition: transform var(--t-slow) var(--ease-back);
}

/* corner ticks: the deco marker that says "this is the called suit" */
.suit-medallion::before,
.suit-medallion::after {
    content: '';
    position: absolute;
    width: 7px;
    height: 7px;
    border: 1px solid var(--rule-strong);
    pointer-events: none;
}

.suit-medallion::before {
    top: -1px;
    left: -1px;
    border-width: 1px 0 0 1px;
}

.suit-medallion::after {
    right: -1px;
    bottom: -1px;
    border-width: 0 1px 1px 0;
}

.suit-medallion.is-new {
    animation: medallionSlam .6s var(--ease-back);
}

@keyframes medallionSlam {
    0% {
        transform: scale(2.1) rotate(-9deg);
        opacity: 0;
    }

    60% {
        transform: scale(.94) rotate(2deg);
        opacity: 1;
    }

    100% {
        transform: scale(1) rotate(0);
    }
}

.suit-medallion__label {
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.suit-medallion__glyph {
    font-family: var(--font-suit);
    font-size: 46px;
    line-height: 1.05;
    color: var(--text-dim);
    transition: color var(--t-med);
}

.suit-medallion[data-color="red"] .suit-medallion__glyph {
    color: #b8404e;
}

.suit-medallion[data-color="black"] .suit-medallion__glyph {
    color: var(--text);
}

.suit-medallion__name {
    font-family: var(--font-engraved);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--gold);
}

/* ---------------- Center pile ---------------- */

.pile {
    position: relative;
    width: var(--card-w-mini);
    height: var(--card-h-mini);
    flex: none;
}

.pile .card {
    position: absolute;
    left: 0;
    top: 0;
    animation: pileDrop .35s var(--ease-back) backwards;
}

@keyframes pileDrop {
    from {
        opacity: 0;
        transform: translateY(-16px) scale(1.15) rotate(var(--pile-rot, 0deg));
    }
}

.pile__count {
    position: absolute;
    left: 50%;
    bottom: -26px;
    transform: translateX(-50%);
    padding: 2px 9px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    background: var(--ink-900);
    border: 1px solid var(--rule-faint);
    border-radius: 0;
    white-space: nowrap;
}

/* ---------------- Last play caption ---------------- */

.last-play {
    max-width: 92%;
    padding: 6px 16px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    color: var(--text-dim);
    background: var(--ink-900);
    border: 1px solid var(--rule-faint);
    border-radius: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.last-play b {
    color: var(--gold);
}

/* ---------------- Dock (hand + actions) ---------------- */

#dock {
    position: relative;
    flex: none;
    height: var(--dock-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom));
    z-index: 25;
}

/*
 * Was a pool of light under your hand to say "you are up". Now a ruled band:
 * a hatch field closed by a rule along the bottom edge, masked out at the
 * sides so it does not read as a box.
 */
#dock::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    width: min(760px, 92%);
    height: 120px;
    transform: translateX(-50%);
    background-image: var(--hatch);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent),
        linear-gradient(0deg, #000 30%, transparent);
    -webkit-mask-composite: source-in;
    mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent),
        linear-gradient(0deg, #000 30%, transparent);
    mask-composite: intersect;
    opacity: 0;
    transition: opacity var(--t-slow);
    pointer-events: none;
}

#dock.is-my-turn::before {
    opacity: 1;
}

#hand-wrap {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
    min-height: 0;
    padding: 0 var(--sp-4);
}

/* ---------------- Action bar ---------------- */

#actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-4);
    margin-top: var(--sp-4);
}

.btn--action {
    min-width: 184px;
    height: 62px;
    font-size: 17px;
    letter-spacing: .1em;
    border-radius: var(--r-md);
}

.btn--action .btn__label {
    font-family: var(--font-display);
    font-size: 27px;
    font-weight: 400;
    letter-spacing: .09em;
}

/*
 * The one place oxblood is used at full strength. It used to hum with a glow;
 * now the inner rule breathes instead, which reads as the same urgency without
 * anything emitting.
 */
.btn--liar {
    --btn-bg: #2a0f14;
    --btn-fg: #e8bcc2;
    --btn-line: var(--oxblood);
}

.btn--liar:not(:disabled) {
    text-shadow: 1px 1px 0 #000;
}

.btn--liar:not(:disabled)::after {
    animation: liarHum 2.2s var(--ease-in-out) infinite;
}

@keyframes liarHum {

    0%,
    100% {
        border-color: rgba(142, 34, 48, .5);
    }

    50% {
        border-color: rgba(209, 112, 124, .85);
    }
}

.select-counter {
    min-width: 124px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    text-align: center;
    color: var(--text-faint);
    transition: color var(--t-fast);
}

.select-counter b {
    font-family: var(--font-mono);
    font-size: 17px;
    color: var(--text-dim);
}

.select-counter.is-active b {
    color: var(--gold);
}

.select-counter.is-full b {
    color: var(--oxblood-hot);
}

/* ---------------- Turn announcement ---------------- */

.turn-announce {
    position: fixed;
    left: 0;
    right: 0;
    top: 34%;
    z-index: 700;
    display: grid;
    place-items: center;
    pointer-events: none;
    opacity: 0;
}

.turn-announce.is-shown {
    animation: announce 1.7s var(--ease-out) both;
}

.turn-announce__text {
    font-family: var(--font-engraved);
    font-weight: 900;
    font-size: clamp(58px, 10.5vw, 118px);
    letter-spacing: .04em;
    color: var(--gold-hot);
    text-shadow: 4px 4px 0 #000;
}

.turn-announce--danger .turn-announce__text {
    color: var(--oxblood-hot);
}

/*
 * The entrance used to resolve out of a blur. It now lands as a stamp:
 * overshoot, strike, settle. The 0% scale is bigger and the strike sharper
 * to compensate for losing the blur as a softening cue.
 */
@keyframes announce {
    0% {
        opacity: 0;
        transform: scale(1.65);
    }

    14% {
        opacity: 1;
        transform: scale(.97);
    }

    22% {
        transform: scale(1);
    }

    72% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: scale(1.06) translateY(-16px);
    }
}

/* ---------------- Game log ---------------- */

#log-panel {
    position: absolute;
    top: calc(var(--hud-h) + env(safe-area-inset-top));
    right: 0;
    bottom: 0;
    width: var(--log-w);
    display: flex;
    flex-direction: column;
    background-color: var(--ink-850);
    background-image: var(--hatch-fine);
    border-left: 1px solid var(--rule);
    transform: translateX(100%);
    transition: transform var(--t-med) var(--ease-out);
    z-index: 40;
}

#log-panel.is-open {
    transform: translateX(0);
}

.log-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--line);
}

.log-panel__head h3 {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.log-panel__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--sp-3) var(--sp-4) var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.log-line {
    padding-left: 11px;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text-dim);
    border-left: 2px solid var(--line-strong);
    animation: riseIn .25s var(--ease-out) both;
}

.log-line--system {
    color: var(--text);
    border-left-color: var(--gold);
}

.log-line--success {
    color: var(--verdigris);
    border-left-color: var(--verdigris);
}

.log-line--error {
    color: var(--oxblood-hot);
    border-left-color: var(--oxblood);
}

.log-line__time {
    margin-right: 7px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
}

/* Unread dot on the log toggle */
#logToggleBtn.has-unread::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    background: var(--gold);
    border-radius: 50%;
}

#logToggleBtn {
    position: relative;
}
