/* Self-hosted, OFL-licensed type (downloaded into /fonts):
   Space Grotesk for everything display/title, Space Mono for details. */
@font-face {
    font-family: "Space Grotesk";
    src: url("fonts/SpaceGrotesk.woff2") format("woff2");
    font-weight: 300 700; /* variable */
    font-display: swap;
}
@font-face {
    font-family: "Space Mono";
    src: url("fonts/SpaceMono-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "Space Mono";
    src: url("fonts/SpaceMono-Bold.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}

:root {
    --bg: #f4f2ec; /* off-white */
    --ink: #1a1a1a;
    --muted: #6a665e; /* ~4.7:1 on --bg, passes WCAG AA for small text */
    --line: #ddd8cc;
    --font-display: "Space Grotesk", Arial, sans-serif;
    --font-mono: "Space Mono", "Courier New", monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-display);
}

.app {
    display: grid;
    grid-template-columns: 340px 1fr;
    height: 100vh; /* fixed to the viewport so the poster never forces a scroll */
}

.sidebar {
    display: flex;
    flex-direction: column;
    padding: 28px 24px 96px; /* bottom space clears the fixed dock */
    background: var(
        --bg
    ); /* opaque: as a mobile drawer it sits over the poster */
    border-right: 1px solid var(--line);
    overflow-y: auto; /* the menu scrolls on its own if it's taller than the window */
}

.sidebar h1 {
    margin: 0 0 8px;
    font-size: 28px;
    letter-spacing: 4px;
}

.tagline {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.tagline code {
    font-size: 12px;
}

.tagline a {
    color: var(--ink);
    font-weight: 700;
    text-decoration: underline;
}

.controls {
    margin: 36px 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.control {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.control-label {
    color: var(--muted);
}

/* Button-group control: label on its own line, buttons fill the width below. */
.control--stack {
    display: block;
}
.control--stack .control-label {
    display: block;
    margin-bottom: 8px;
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
/* Palette group: equal-size buttons, three per row. */
.btn-group--grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.seg-btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 11px 12px;
    font: inherit;
    font-size: 13px;
    text-transform: capitalize;
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    cursor: pointer;
}
.seg-btn:hover {
    border-color: var(--ink);
}
.seg-btn.is-active {
    background: var(--ink);
    color: var(--bg);
    border-color: var(--ink);
}
.seg-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.14);
}

/* Palette buttons preview their color scheme (bg + court) on hover/active,
   fading in via a ::before overlay so the change is smooth. */
.seg-btn--palette {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    transition:
        color 0.25s ease,
        border-color 0.25s ease;
}
.seg-btn--palette > span {
    position: relative;
    z-index: 1;
}
.seg-btn--palette::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.25s ease;
    background: linear-gradient(
        135deg,
        var(--p-bg) 0 52%,
        var(--p-court) 52% 100%
    );
}
.seg-btn--palette:hover::before,
.seg-btn--palette.is-active::before {
    opacity: 1;
}
.seg-btn--palette:hover,
.seg-btn--palette.is-active {
    background: #fff; /* base under the gradient; overrides the generic active fill */
    color: var(--p-ink);
    border-color: var(--p-ink);
}

/* --- Custom form controls -------------------------------------------------
   Range, select and checkbox share one visual language: white surface, a
   1px --line border, --ink as the accent, slightly squared corners (4px) and
   the same --ink focus ring. Native chrome is stripped with appearance:none. */

.control input[type="range"],
.control select,
.control input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    font: inherit;
    color: var(--ink);
    cursor: pointer;
}

/* Select ------------------------------------------------------------------ */
.control select {
    width: 100%;
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 6px 28px 6px 9px;
    /* custom chevron (ink), replaces the native dropdown arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%231a1a1a' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}
.control select:hover {
    border-color: var(--ink);
}
.control select:focus-visible {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.14);
}

/* Range slider ------------------------------------------------------------ */
.control input[type="range"] {
    width: 100%;
    height: 18px; /* hit area; the visible track is thinner */
    background: transparent;
}
.control input[type="range"]::-webkit-slider-runnable-track {
    height: 2px;
    background: var(--line);
    border-radius: 2px;
}
.control input[type="range"]::-moz-range-track {
    height: 2px;
    background: var(--line);
    border-radius: 2px;
}
.control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -6px; /* center the thumb on the 2px track */
    background: var(--ink);
    border: 2px solid #fff;
    border-radius: 4px;
}
.control input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--ink);
    border: 2px solid #fff;
    border-radius: 4px;
}
.control input[type="range"]:focus-visible {
    outline: none;
}
.control input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.14);
}
.control input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.14);
}

/* Checkbox ---------------------------------------------------------------- */
.control input[type="checkbox"] {
    position: relative;
    justify-self: start;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
}
.control input[type="checkbox"]:hover {
    border-color: var(--ink);
}
.control input[type="checkbox"]:checked {
    background: var(--ink);
    border-color: var(--ink);
}
.control input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid var(--bg);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.control input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.14);
}

/* Primary action button — full menu width, dark fill. */
.btn-primary {
    display: block;
    width: 100%;
    background: var(--ink);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    padding: 12px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}
.btn-primary:hover {
    background: #333;
}

/* Secondary (outlined) variant — used for the Menu toggle. */
.btn-secondary {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn-secondary:hover {
    background: #efece4;
}

/* Action dock: pinned at the bottom of the sidebar column on desktop (just the
   New rally button), becomes the full-width sticky bar on mobile (New rally +
   Menu). One button instance for both layouts — no duplicates. */
.dock {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 340px;
    box-sizing: border-box;
    display: flex;
    gap: 10px;
    padding: 16px 24px;
    background: var(--bg);
    border-top: 1px solid var(--line);
    border-right: 1px solid var(--line);
    z-index: 15;
}
.dock .btn-primary {
    flex: 1;
    width: auto;
}
#menuToggle {
    display: none; /* mobile only */
}

/* Foldable sections (Import / Export) — collapsed by default. The summary is
   the uppercase section title with a +/− fold indicator. */
.panel {
    margin-top: 28px;
    border-top: 1px solid var(--line);
}
.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 0;
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    cursor: pointer;
    list-style: none; /* hide native disclosure marker */
}
.panel-title::-webkit-details-marker {
    display: none;
}
.panel-title::after {
    content: "+";
    font-size: 16px;
    line-height: 1;
}
.panel[open] .panel-title {
    color: var(--ink);
}
.panel[open] .panel-title::after {
    content: "−";
}

.panel-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-bottom: 18px;
}

/* Export option groups: format row, definition stacked one per line. */
.export-group {
    display: flex;
    gap: 10px;
}
.export-group--stack {
    flex-direction: column;
}

/* Custom-rally modal ------------------------------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(20, 18, 12, 0.45);
    z-index: 40; /* above the mobile drawer (20) and dock (30) */
}
.modal[hidden] {
    display: none;
}

.modal-card {
    position: relative;
    max-width: 580px;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--bg);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 34px 34px 30px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.modal-card h2 {
    margin: 0 0 12px;
    font-size: 18px;
    letter-spacing: 1px;
}

.modal-card p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted);
}

/* Rally form — same visual language as the menu (line-bordered fields, ink
   focus ring, segmented button groups). */
.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 18px;
}
.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.field-label {
    font-size: 12px;
    color: var(--muted);
}
.field-input {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 10px;
    font: inherit;
    font-size: 13px;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
}
.field-input:hover {
    border-color: var(--ink);
}
.field-input:focus-visible {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.14);
}
#f-code {
    font-family: var(--font-mono); /* it's a code — monospace reads better */
}
.form-row {
    display: flex;
    gap: 12px;
}
.form-row .field {
    flex: 1;
}
.form .btn-primary {
    margin-top: 4px;
}

.modal-card a {
    color: var(--ink);
    font-weight: 700;
    text-decoration: underline;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.modal-close:hover {
    color: var(--ink);
}

/* The MCP code of the rally currently on screen: a label above, then the code
   as a full-width chip so a long code wraps cleanly inside one box. */
.code-line {
    margin: 16px 0 0;
    font-family: var(--font-mono);
    font-size: 11px;
}
.code-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
}
/* The code chip. Click copies it; double-click selects the whole string
   (handled in main.js, since a default double-click would stop at the
   "@" / "*" markers). */
#code {
    display: block;
    padding: 6px 8px;
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    word-break: break-all;
    cursor: pointer;
}

/* Transient copy confirmation — separate from the status line, fades out. */
.copy-hint {
    margin-top: 18px;
    font-size: 11px;
    color: var(--ink);
    min-height: 14px;
    opacity: 0;
    transition: opacity 0.4s ease;
}
.copy-hint.is-visible {
    opacity: 1;
}

.status {
    margin-top: 14px;
    font-size: 11px;
    color: var(--muted);
    min-height: 14px;
}

/* Author credit, pinned at the bottom of the sidebar menu, just above the
   fixed dock's top border line. */
.credit {
    margin-top: auto; /* push to the bottom of the flex sidebar column */
    padding-top: 24px;
    font-size: 11px;
    color: var(--muted);
}
.credit a {
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid var(--line);
}
.credit a:hover {
    color: var(--ink);
}

.stage {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    overflow: hidden; /* keep the poster inside the viewport */
}

#poster {
    aspect-ratio: 2 / 3; /* logical poster ratio; the SVG scales to fill */
    max-width: 100%;
    max-height: 100%; /* fit the stage (= viewport height minus padding) */
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.14);
}
#poster svg {
    display: block;
    width: 100%;
    height: 100%; /* crisp at any size via the SVG viewBox */
}

/* Soft fade-in replayed each time a new rally is drawn. */
@keyframes poster-in {
    from {
        opacity: 0;
        transform: scale(0.99);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
.poster-anim {
    animation: poster-in 0.6s ease;
}

@media (max-width: 720px) {
    /* Poster fills the screen; the menu lives in a slide-up drawer. */
    .app {
        display: block;
        height: 100vh;
        overflow: hidden;
    }

    .stage {
        height: 100vh;
        padding: 16px 16px 84px; /* leave room for the bottom dock */
    }

    /* The sidebar becomes a full-screen, scrollable drawer, hidden by default. */
    .sidebar {
        position: fixed;
        inset: 0;
        z-index: 20;
        border-right: none;
        transform: translateY(100%);
        transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
    }
    .sidebar.is-open {
        transform: translateY(0);
    }

    /* Dock spans the full width and sits above the drawer; Menu toggle appears. */
    .dock {
        width: 100%;
        border-right: none;
        z-index: 30;
    }
    #menuToggle {
        display: block;
    }
}
