/* SlipSync
   Flat, dark, hairline borders. Color is reserved for the two players and
   for state changes, so it actually means something when it shows up. */

:root {
    /* Surfaces */
    --bg: #0a0810;
    --arena: #0f0c16;
    --panel: #110e19;
    --raised: #18131f;
    --line: #262032;
    --line-strong: #3a3049;

    /* Text */
    --text: #e8e4ef;
    --text-dim: #8a8296;
    --text-faint: #5c5568;

    /* Accent + game colors (renderer/effects read the --color-* ones) */
    --accent: #8b6cf0;
    --accent-press: #7558db;

    --color-text: var(--text);
    --color-text-muted: var(--text-dim);
    --color-grid: #19151f;
    --color-border: #2f2740;
    --color-accent: var(--accent);
    --color-player: #4fa8ff;
    --color-chaser: #ff3b52;
    --color-dismantle: #c91438;
    --color-shield: #19b3a0;
    --color-refill: #e8a900;
    --color-slow: #d9d4f0;

    --role: var(--color-player);

    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
    --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;

    --radius: 3px;

    color-scheme: dark;

    /* Largest 4:3 frame that fits under the HUD and above the status bar. */
    --game-width: min(100%, calc((100vh - 132px) * 4 / 3));
    --game-width: min(100%, calc((100dvh - 132px) * 4 / 3));
}

body[data-role="chaser"] {
    --role: var(--color-chaser);
}

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

html,
body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    overflow: hidden;
    padding:
        max(10px, env(safe-area-inset-top, 0px))
        max(14px, env(safe-area-inset-right, 0px))
        max(10px, env(safe-area-inset-bottom, 0px))
        max(14px, env(safe-area-inset-left, 0px));
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

[hidden] {
    display: none !important;
}

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 1px 5px;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    line-height: 1.3;
    text-align: center;
    color: var(--text-dim);
    background: transparent;
}

/* --------------------------------------------------------------------------
   HUD
   -------------------------------------------------------------------------- */

.hud {
    width: var(--game-width);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    font-family: var(--font-mono);
}

.hud-left {
    display: flex;
    align-items: flex-end;
    gap: 28px;
    min-width: 0;
    flex-wrap: wrap;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 3px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--role);
}

.role-badge-dot {
    width: 8px;
    height: 8px;
    background: currentColor;
}

.hud-stats {
    display: flex;
    align-items: flex-end;
    gap: 24px;
}

.hud-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 7px;
    white-space: nowrap;
}

.hud-label {
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.hud-value {
    font-size: 1.3rem;
    font-weight: 500;
    line-height: 1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.hud-multiplier {
    font-size: 0.8rem;
    color: var(--color-refill);
    font-variant-numeric: tabular-nums;
}

.hud-stat--timer.is-urgent .hud-value {
    color: var(--color-chaser);
}

.hud-score-tag--you {
    color: var(--role);
}

.hud-vs {
    color: var(--text-faint);
}

.hud-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    border: 0;
    background: none;
    padding: 0;
}

button:focus-visible {
    outline: 1px solid var(--text);
    outline-offset: 2px;
}

button:disabled {
    cursor: default;
    opacity: 0.4;
}

.text-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 8px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--text-dim);
}

.text-btn:hover:not(:disabled) {
    color: var(--text);
    background: var(--raised);
}

.text-btn.is-paused {
    color: var(--color-refill);
}

.text-btn.is-muted #mute-label {
    text-decoration: line-through;
    color: var(--text-faint);
}

.btn-primary {
    padding: 9px 18px;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
}

.btn-primary:hover {
    background: #977af3;
}

.btn-primary:active {
    background: var(--accent-press);
}

.btn-ghost {
    padding: 8px 14px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}

.btn-ghost:hover {
    background: var(--raised);
}

/* --------------------------------------------------------------------------
   Game frame
   -------------------------------------------------------------------------- */

.game-frame {
    position: relative;
    width: var(--game-width);
    aspect-ratio: 4 / 3;
    border: 1px solid var(--line);
    border-top: 2px solid var(--role);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--arena);
    touch-action: none;
}

body[data-role="chaser"] canvas {
    cursor: crosshair;
}

/* --------------------------------------------------------------------------
   Overlay panel (start / pause / game over)
   -------------------------------------------------------------------------- */

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(6, 5, 10, 0.72);
    z-index: 10;
}

.panel {
    width: min(440px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 22px 24px 20px;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
}

.panel-eyebrow,
.overlay-eyebrow {
    display: block;
    margin-bottom: 6px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.panel-eyebrow:empty,
.overlay-eyebrow:empty {
    display: none;
}

.overlay-eyebrow.is-win {
    color: var(--color-refill);
}

.overlay-eyebrow.is-loss {
    color: var(--color-chaser);
}

.panel-title {
    margin: 0 0 6px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: #fff;
}

.panel-message {
    margin: 0 0 18px;
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--text-dim);
}

/* End-of-round numbers: label above value, no boxes */
.panel-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 12px 0 14px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.overlay-stat-chip {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.overlay-stat-chip b {
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.overlay-stat-chip.is-highlight b {
    color: var(--color-refill);
}

/* Mode list: rows, not cards */
.mode-picker {
    display: flex;
    flex-direction: column;
    margin: 0 0 18px;
    border-top: 1px solid var(--line);
}

.mode-card {
    display: grid;
    grid-template-columns: 26px 1fr 26px;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    border-left: 2px solid transparent;
    text-align: center;
    color: var(--text-dim);
}

.mode-card:hover {
    background: var(--raised);
    color: var(--text);
}

.mode-card.is-selected {
    background: var(--raised);
    border-left-color: var(--accent);
    color: var(--text);
}

.mode-card[data-mode="runner"].is-selected {
    border-left-color: var(--color-player);
}

.mode-card[data-mode="chaser"].is-selected {
    border-left-color: var(--color-chaser);
}

.mode-key {
    justify-self: start;
}

.mode-card.is-selected .mode-key {
    color: var(--text);
    border-color: var(--text-dim);
}

.mode-name {
    font-weight: 600;
    font-size: 0.94rem;
    color: inherit;
    text-align: center;
}

.mode-card.is-selected .mode-name {
    color: #fff;
}

.swap-role-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 0.8rem;
    color: var(--text-dim);
}

.swap-role-toggle {
    display: inline-flex;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
}

.swap-role-btn {
    padding: 4px 12px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.swap-role-btn + .swap-role-btn {
    border-left: 1px solid var(--line-strong);
}

.swap-role-btn:hover {
    color: var(--text);
}

.swap-role-btn[data-start-role="runner"].is-active {
    color: var(--color-player);
    background: var(--raised);
}

.swap-role-btn[data-start-role="chaser"].is-active {
    color: var(--color-chaser);
    background: var(--raised);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-hint {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-faint);
}

/* --------------------------------------------------------------------------
   Status bar: one strip, four cells, thin progress line under each
   -------------------------------------------------------------------------- */

.status-bar {
    width: var(--game-width);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--line);
    background: var(--panel);
}

.status-pill {
    position: relative;
    height: 32px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--text-faint);
    user-select: none;
    overflow: hidden;
}

.status-pill + .status-pill {
    border-left: 1px solid var(--line);
}

.status-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    transform-origin: left center;
    transform: scaleX(0);
    background: var(--text-faint);
    pointer-events: none;
}

.status-fill--dash { background: var(--color-player); }
.status-fill--parry { background: var(--accent); }
.status-fill--shield { background: var(--color-shield); }
.status-fill--slow { background: var(--color-slow); }
.status-fill--lunge { background: #ff7a45; }
.status-fill--dismantle { background: var(--color-chaser); }
.status-fill--blackflash { background: #ff6b81; }
.status-fill--target { background: var(--text-faint); }

.status-content {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    white-space: nowrap;
}

.status-key {
    flex-shrink: 0;
    font-size: 0.66rem;
}

.status-label {
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.status-pill.is-ready,
.status-pill.is-active {
    color: var(--text);
}

.status-pill.is-ready .status-key,
.status-pill.is-active .status-key {
    color: var(--text);
}

.status-pill.is-active {
    background: var(--raised);
}

.status-pill.is-shield { color: var(--color-shield); }
.status-pill.is-slow { color: var(--color-slow); }
.status-pill.is-punished { color: #ff7d8d; }
.status-pill.is-danger { color: #ff7d8d; background: var(--raised); }

/* --------------------------------------------------------------------------
   On-canvas action buttons (touch + click)
   -------------------------------------------------------------------------- */

.canvas-actions {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 5;
    pointer-events: none;
}

.action-cluster {
    display: flex;
    gap: 6px;
    pointer-events: auto;
}

.action-btn {
    padding: 7px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: rgba(17, 14, 25, 0.9);
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--text);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.action-btn:hover {
    border-color: var(--text-dim);
}

.action-btn.is-active {
    border-color: var(--text);
    background: var(--raised);
}

.action-btn.is-cooldown {
    color: var(--text-faint);
}

.action-btn--parry.is-active { border-color: var(--accent); }
.action-btn--dismantle.is-active,
.action-btn--blackflash.is-active { border-color: var(--color-chaser); }

/* --------------------------------------------------------------------------
   Controls hint
   -------------------------------------------------------------------------- */

.controls-hint {
    width: var(--game-width);
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-faint);
}

/* --------------------------------------------------------------------------
   Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
    :root {
        --game-width: min(100%, calc((100dvh - 170px) * 4 / 3));
    }

    .hud-left {
        gap: 16px;
    }

    .hud-stats {
        gap: 14px;
    }

    .hud-value {
        font-size: 1.05rem;
    }

    .text-btn kbd {
        display: none;
    }

    .status-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .status-pill:nth-child(3) {
        border-left: 0;
    }

    .status-pill:nth-child(n + 3) {
        border-top: 1px solid var(--line);
    }

    .panel-hint {
        display: none;
    }
}
