:root {
    --blue: #0a1d43;
    --red: #ff9d00;
    --light: #f4f6f8;
    --line: #d8dee6;
    --ink: #18202a;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Poppins, Arial, Helvetica, sans-serif; color: var(--ink); background: #e9edf2; }
button, select, input { font: inherit; }
.site-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 28px; color: #fff; background: var(--blue); }
.site-header h1 { margin: 3px 0 0; font-size: 24px; }
.eyebrow { color: #fff; font-size: 12px; font-weight: bold; letter-spacing: .16em; opacity: .75; }
.status { padding: 7px 12px; border-radius: 999px; background: rgba(255,255,255,.13); font-size: 13px; }
.header-user { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.header-user a { color: #fff; opacity: .8; }
.app-shell { display: grid; grid-template-columns: minmax(520px, 1fr) minmax(420px, .85fr); gap: 20px; max-width: 1500px; margin: 20px auto; padding: 0 20px 30px; }
.control-panel, .preview-panel { background: #fff; border-radius: 10px; box-shadow: 0 8px 28px rgba(16,43,78,.08); }
.control-panel { padding: 22px; }
.preview-panel { padding: 18px; align-self: start; position: sticky; top: 16px; }
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab { border: 0; background: transparent; padding: 11px 15px; cursor: pointer; color: #627083; border-bottom: 3px solid transparent; }
.tab.is-active { color: var(--blue); border-bottom-color: var(--red); font-weight: bold; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field-grid.compact { grid-template-columns: repeat(3, 1fr); }
label { display: grid; gap: 6px; color: #4e5968; font-size: 12px; font-weight: bold; }
select, input[type="date"], input[type="time"] { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff; }
.help { color: #687587; font-size: 13px; margin: 18px 0 10px; }
.squad-builder { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.player-column { min-width: 0; }
.player-column h2 { display: flex; justify-content: space-between; margin: 0 0 8px; font-size: 14px; }
.player-column h2 span { color: #718096; font-weight: normal; }
.player-list { min-height: 310px; max-height: 420px; overflow-y: auto; padding: 7px; border: 1px dashed #bcc7d3; border-radius: 7px; background: var(--light); }
.player-list.is-over { border-color: var(--red); background: #fff5f5; }
.player-card { display: flex; align-items: center; gap: 8px; padding: 8px; margin-bottom: 6px; border: 1px solid #dfe5eb; border-radius: 6px; background: #fff; cursor: grab; font-size: 12px; }
.player-card:active { cursor: grabbing; }
.number { display: inline-grid; place-items: center; min-width: 24px; height: 24px; color: #fff; background: var(--blue); border-radius: 50%; font-size: 11px; font-weight: bold; }
.player-meta { min-width: 0; }
.player-name { display: block; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-position { color: #7b8795; }
.formation-pitch { position: relative; min-height: 420px; overflow: hidden; border: 1px solid #173660; border-radius: 8px; background: linear-gradient(rgba(9,35,69,.86), rgba(4,20,44,.94)); }
.formation-pitch::before { content: ""; position: absolute; inset: 7%; border: 1px solid rgba(255,255,255,.25); border-radius: 4px; pointer-events: none; }
.formation-pitch::after { content: ""; position: absolute; left: 10%; right: 10%; top: 50%; border-top: 1px solid rgba(255,255,255,.22); pointer-events: none; }
.formation-slot { position: absolute; z-index: 1; width: 30%; min-height: 54px; padding: 4px; transform: translate(-50%,-50%); border: 1px dashed rgba(255,255,255,.38); border-radius: 7px; background: rgba(255,255,255,.08); }
.formation-slot.is-over { border-color: var(--red); background: rgba(255,157,0,.24); }
.formation-slot-label { display: block; color: rgba(255,255,255,.55); text-align: center; font-size: 9px; font-weight: 600; letter-spacing: .04em; }
.formation-slot .player-card { padding: 5px; margin: 0; font-size: 10px; }
.formation-slot .number { min-width: 21px; height: 21px; font-size: 9px; }
.formation-slot .player-position { display: none; }
#formation-field.is-disabled { opacity: .45; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.table-tools { display: flex; align-items: center; gap: 12px; margin: 18px 0 12px; }
.table-tools span { color: #687587; font-size: 12px; }
.data-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 8px 9px; text-align: center; border-bottom: 1px solid #e7ebef; }
.data-table th:nth-child(2), .data-table td:nth-child(2) { text-align: left; }
.data-table tbody tr.is-rana { color: #fff; background: var(--red); font-weight: bold; }
.button { padding: 11px 16px; border: 0; border-radius: 6px; cursor: pointer; font-weight: bold; }
.button.primary { color: #fff; background: var(--red); }
.button.secondary { color: var(--blue); background: #e9eff6; }
.button:disabled { cursor: wait; opacity: .55; }
.editor-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.editor-heading h2 { margin: 0; font-size: 18px; }
.editor-heading .help { margin: 6px 0 0; }
.editor-heading label { width: 220px; flex: 0 0 auto; }
.player-editor-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; }
.player-editor-table { width: 100%; border-collapse: collapse; }
.player-editor-table th { padding: 9px; color: #687587; background: var(--light); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.player-editor-table td { padding: 6px; border-top: 1px solid #e7ebef; }
.player-editor-table th:first-child, .player-editor-table td:first-child { width: 82px; }
.player-editor-table th:nth-child(4), .player-editor-table td:nth-child(4) { min-width: 210px; }
.player-editor-table th:nth-child(5), .player-editor-table td:nth-child(5) { width: 62px; text-align: center; }
.player-editor-table th:last-child, .player-editor-table td:last-child { width: 70px; text-align: right; }
.player-editor-table input[type="text"], .player-editor-table input[type="number"] { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 5px; }
.editor-active-input { width: 18px; height: 18px; }
.remove-player { padding: 7px 8px; border: 0; color: #a31521; background: #fff0f1; border-radius: 5px; cursor: pointer; }
.empty-row td { padding: 25px; color: #718096; text-align: center !important; }
.editor-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
body.editing-players .app-shell { grid-template-columns: 1fr; max-width: 1050px; }
body.editing-players .preview-panel, body.editing-players .actions { display: none; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; background: linear-gradient(145deg, var(--blue), #07182d); }
.login-card { width: 100%; max-width: 410px; padding: 32px; background: #fff; border-radius: 12px; box-shadow: 0 18px 55px rgba(0,0,0,.28); }
.login-card h1 { margin: 5px 0 8px; color: var(--blue); font-size: 25px; }
.login-card p { margin: 0 0 22px; color: #687587; }
.login-card form { display: grid; gap: 15px; }
.login-card input { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 6px; }
.login-card .button { margin-top: 3px; }
.eyebrow.dark { color: var(--red); opacity: 1; }
.login-error { margin-bottom: 16px; padding: 10px 12px; color: #8b101a; background: #fff0f1; border-radius: 6px; font-size: 13px; }
.preview-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.preview-heading h2 { margin: 0; font-size: 18px; }
.preview-heading label { width: 170px; }
.canvas-wrap { display: grid; place-items: center; padding: 12px; min-height: 440px; background: #dfe4ea; border-radius: 7px; overflow: hidden; }
#preview-canvas { display: block; max-width: 100%; max-height: 68vh; width: auto; height: auto; box-shadow: 0 6px 20px rgba(0,0,0,.22); background: #fff; }

@media (max-width: 1050px) {
    .app-shell { grid-template-columns: 1fr; }
    .preview-panel { position: static; }
}
@media (max-width: 680px) {
    .field-grid, .field-grid.compact, .squad-builder { grid-template-columns: 1fr; }
    .site-header { align-items: flex-start; gap: 12px; }
    .site-header h1 { font-size: 20px; }
    .header-user { align-items: flex-end; flex-direction: column; }
    .editor-heading { align-items: stretch; flex-direction: column; }
    .editor-heading label { width: 100%; }
}

.match-import { padding: 16px; margin-bottom: 18px; border: 1px solid rgba(255,255,255,.18); border-radius: 10px; }
.match-import label { display: block; margin-top: 12px; }
.match-import select { width: 100%; min-width: 0; }
.match-import p { font-size: .8rem; line-height: 1.5; margin: 10px 0 0; }
.match-import a { color: inherit; font-size: .8rem; }
#result-fetch-matches[hidden] { display: none; }
#result-match-summary { font-weight: 600; }
.table-zone-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: .75rem; }
.table-zone-legend span { display: inline-flex; align-items: center; gap: 6px; }
.table-zone-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.table-zone-legend small { flex-basis: 100%; }
.zone-sr { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
body.editing-logos .app-shell { grid-template-columns: 1fr; max-width: 1050px; }
body.editing-logos .preview-panel, body.editing-logos .actions { display: none; }
.logo-editor-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 20px; align-items: center; }
#logo-editor-canvas { width: 100%; height: auto; border-radius: 16px; touch-action: none; cursor: grab; }
#logo-editor-canvas:active { cursor: grabbing; }
.logo-editor-controls label { display: block; margin-bottom: 22px; }
.logo-editor-controls input[type=range] { width: 100%; padding: 0; accent-color: #ff9d00; }
.logo-editor-controls output { float: right; font-weight: 400; }
@media (max-width: 650px) { .logo-editor-layout { grid-template-columns: 1fr; } }

.lineup-overrides { margin: 0 0 24px; padding: 14px 18px; border: 1px solid #d5dce5; border-radius: 8px; }
.lineup-overrides summary { cursor: pointer; font-weight: 600; }
.lineup-overrides[open] summary { margin-bottom: 12px; }

.layout-choice { grid-column: span 2; min-width: 0; margin: 0; padding: 0; border: 0; }
.layout-choice legend { margin-bottom: 6px; padding: 0; color: #4e5968; font-size: 12px; font-weight: bold; }
.layout-options { display: flex; flex-wrap: wrap; gap: 8px; }
.layout-options label { position: relative; cursor: pointer; }
.layout-options input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.layout-options span { display: block; padding: 10px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.layout-options input:checked + span { background: #11264d; border-color: #11264d; color: #fff; box-shadow: inset 0 -3px #ff9d00; }
.layout-options input:focus-visible + span { outline: 3px solid #89adff; outline-offset: 2px; }
@media (max-width: 900px) { .layout-choice { grid-column: 1 / -1; } }

#formation-drag-tools { text-align: center; }
#formation-reset-tools { text-align: center; margin-top: 16px; }
#formation-reset-tools:not([hidden]) { display: flex; justify-content: center; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
#formation-reset-tools label { width: 180px; text-align: left; }
.background-tools { margin-bottom: 18px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; }
.background-tools summary { cursor: pointer; font-weight: 600; }
.background-tools label { margin-top: 12px; }
.background-tools input[type=file] { max-width: 100%; }

body.editing-backgrounds .actions { display: none; }

#lineup-sort-tools { margin: 16px auto 0; }
#lineup-sort-tools legend { width: 100%; text-align: center; }
#lineup-sort-tools .layout-options { justify-content: center; }
#lineup-opponent-name { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff; }

body.editing-backgrounds #download-all { display: none; }

.player-image-drop { min-width: 170px; padding: 12px; border: 2px dashed #b5c2d3; border-radius: 10px; background: #f6f8fb; text-align: center; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; }
.player-image-drop.is-over, .player-image-drop:focus-visible { border-color: #ff9d00; background: #fff5e3; outline: 2px solid #ff9d00; }
.player-image-drop[aria-busy="true"] { cursor: progress; }
.player-image-drop .player-image-preview { width: 56px; height: 64px; object-fit: contain; }
.player-image-drop [hidden] { display: none; }
.player-image-drop progress { width: 100%; height: 10px; accent-color: #ff9d00; }
.player-image-status { color: #526077; }
