/* Shared UI for optional features: tools row, dialogs, buttons.
   Colours use the theme variables when the theme defines them, with the
   original dark-slate values as fallbacks. */
/* Tools row: buttons added by optional features (EFL.addTool) */
.tools-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin: 8px auto 0;
    max-width: 560px;
}

.tools-bar[hidden] {
    display: none;
}

.tool-btn {
    font-family: var(--font-display, 'Oswald', system-ui, sans-serif);
    padding: 6px 12px;
    border-radius: var(--radius-sm, 5px);
    border: 1px solid var(--border, #3d4460);
    background: var(--surface-2, #242938);
    color: var(--text-2, #d1d5e0);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    cursor: pointer;
    min-height: 32px;
    box-shadow: var(--highlight, none);
}

.tool-btn:hover {
    background: var(--surface-3, #2f3447);
    color: var(--text, #fff);
}

.tool-btn.is-on {
    border-color: var(--accent, #22c55e);
    color: var(--accent, #22c55e);
}

/* Panels opened by features (EFL.openPanel) */
.efl-panel-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(8, 10, 16, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.efl-panel {
    width: min(100%, 460px);
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: var(--glass, none), var(--surface, #1f2433);
    box-shadow: var(--highlight, 0 0 0 transparent), 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border, #3d4460);
    border-radius: var(--radius, 10px);
    text-align: left;
}

.efl-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--surface-3, #2f3447);
}

.efl-panel-head h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text, #fff);
}

.efl-panel-close {
    background: none;
    border: none;
    color: var(--muted, #a0a8b8);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    width: 32px;
    height: 32px;
}

.efl-panel-body {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 14px;
    color: var(--text-2, #d1d5e0);
}

.efl-panel-body label {
    font-size: 12px;
    color: var(--muted, #a0a8b8);
    letter-spacing: 0.3px;
}

.efl-panel-body textarea,
.efl-panel-body input[type="text"],
.efl-panel-body select {
    width: 100%;
    background: var(--bg, #151926);
    color: var(--text, #fff);
    border: 1px solid var(--border, #3d4460);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
}

.efl-panel-body textarea {
    min-height: 140px;
    resize: vertical;
    line-height: 1.5;
}

.efl-panel-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.efl-btn {
    font-family: var(--font-display, 'Oswald', system-ui, sans-serif);
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border, #3d4460);
    background: var(--surface-3, #2a3042);
    color: var(--text, #fff);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
}

.efl-btn--primary {
    background: var(--accent-grad, var(--accent, #22c55e));
    border-color: var(--accent, #22c55e);
    color: var(--accent-ink, #0b1a10);
}

.efl-hint {
    font-size: 12px;
    color: var(--muted-2, #8a93a6);
}

/* A name cleared on purpose stays blank but keeps a tappable label */
.player-name:empty {
    min-width: 44px;
}

.player-name:empty::before {
    content: "Name";
    opacity: 0.45;
    font-weight: 400;
}

/* One clear close button for every panel, sheet and menu */
button.efl-panel-close,
button.fp-close,
button.ly-menu-close {
    width: 40px;
    height: 40px;
    flex: none;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 0;
    cursor: pointer;
    position: relative;
    transition: background 0.15s, transform 0.15s;
}

button.efl-panel-close::before,
button.fp-close::before,
button.ly-menu-close::before {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px;
    height: 16px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 2l12 12M14 2L2 14' stroke='black' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 2l12 12M14 2L2 14' stroke='black' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

button.efl-panel-close:hover,
button.fp-close:hover,
button.ly-menu-close:hover {
    background: rgba(255, 255, 255, 0.24);
}

button.efl-panel-close:active,
button.fp-close:active,
button.ly-menu-close:active {
    transform: scale(0.92);
}

button.efl-panel-close:focus-visible,
button.fp-close:focus-visible,
button.ly-menu-close:focus-visible {
    outline: 2px solid var(--accent, #22c55e);
    outline-offset: 2px;
}

/* Phones: every panel is a short tray along the bottom. No dark overlay, so
   the pitch above stays in view and shows changes as they happen. It sits
   just above the on-screen keyboard (--vv-* are set in app.js). */
@media (max-width: 600px) {
    .efl-panel-overlay {
        top: var(--vv-top, 0);
        bottom: auto;
        height: var(--vv-h, 100%);
        padding: 0;
        align-items: flex-end;
        background: transparent;
    }

    .efl-panel {
        width: 100%;
        max-height: min(48vh, calc(var(--vv-h, 100vh) - 96px));
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.55);
        transform: translateY(105%);
        transition: transform var(--tray-in, 420ms) var(--tray-ease, cubic-bezier(0.32, 0.72, 0, 1));
        will-change: transform;
    }

    .efl-panel.is-open { transform: none; }

    .efl-panel.is-leaving {
        transition-duration: var(--tray-out, 260ms);
        transition-timing-function: var(--tray-ease-out, cubic-bezier(0.4, 0, 0.9, 0.6));
    }

    .efl-panel-overlay.is-closing { pointer-events: none; }

    /* The top bar is the grip: swipe it down to close */
    .efl-panel-head {
        flex: none;
        position: relative;
        padding: 18px 14px 8px 16px;
        touch-action: none;
        cursor: grab;
    }

    .efl-panel-head::before {
        content: '';
        position: absolute;
        left: 50%;
        top: 7px;
        width: 40px;
        height: 4px;
        margin-left: -20px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.22);
    }

    .efl-panel-head h2 {
        font-size: 17px;
    }

    .efl-panel-body {
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .efl-panel-body textarea {
        min-height: 96px;
        height: 96px;
        font-size: 16px; /* 16px stops iOS zooming in on focus */
    }

    .efl-panel-body input[type="text"],
    .efl-panel-body select {
        font-size: 16px;
    }

    /* Keyboard up: drop the hints and keep the tray compact */
    .kb-open .efl-panel {
        max-height: calc(var(--vv-h, 100vh) - 56px);
        border-radius: 14px 14px 0 0;
    }

    .kb-open .efl-panel-body p.efl-hint {
        display: none;
    }

    .kb-open .efl-panel-body textarea {
        min-height: 72px;
        height: 72px;
    }
}

/* Tray motion: one feel everywhere (iOS-style sheet curve) */
:root {
    --tray-ease: cubic-bezier(0.32, 0.72, 0, 1);
    --tray-ease-out: cubic-bezier(0.4, 0, 0.9, 0.6);
    --tray-in: 420ms;
    --tray-out: 260ms;
}

@media (prefers-reduced-motion: reduce) {
    .efl-panel,
    .fp-panel.is-sheet,
    .ly-menu.is-sheet { transition: none !important; }
}

/* Desktop: panels drop down from the button that opened them, the same way
   the formation picker does (placed by EFL._placePopover in app.js) */
@media (min-width: 601px) {
    .efl-panel-overlay.is-popover {
        display: block;
        padding: 0;
        background: transparent;
    }

    .efl-panel-overlay.is-popover .efl-panel {
        position: fixed;
        width: min(420px, calc(100vw - 24px));
        border-radius: 16px;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.3);
        opacity: 0;
        transform: translateY(-6px);
        transition: opacity 0.16s ease, transform 0.16s ease;
    }

    .efl-panel-overlay.is-popover .efl-panel.is-open {
        opacity: 1;
        transform: none;
    }
}
