*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
* { font-family: inherit; }

:root {
    --bg:        #080808;
    --col-bg:    #111111;
    --card-bg:   #1c1c1c;
    --card-hover:#232323;
    --border:    #2a2a2a;
    --text:      #f0f0f0;
    --muted:     #484848;
    --muted2:    #888888;
    --hdr-h:     52px;   /* fixed col-header height — keeps all header lines aligned */
    --ftr-h:     52px;   /* fixed col-footer height — keeps all footer lines aligned */
    --header-h:  54px;
}

html, body {
    height: 100%;
    /* dvh accounts for mobile browser chrome (address bar, nav bar).
       Falls back to vh on older browsers. */
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
}

button { outline: none; cursor: pointer; }
button:focus, button:focus-visible { outline: none; box-shadow: none; }
::placeholder { color: var(--muted2); opacity: 1; }

/* ---- Page header ---- */

header {
    height: var(--header-h);
    background: var(--col-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    flex-shrink: 0;
}

.site-name {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--muted2);
    white-space: nowrap;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.clan-title {
    flex: 1;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--text);
    text-transform: uppercase;
}

/* ---- Season selector (header) ---- */

.season-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.season-select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23484848'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.55rem center;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted2);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.37rem 1.8rem 0.37rem 0.7rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.season-select:hover { color: var(--text); border-color: #505050; }
.season-select option { background: #1c1c1c; color: var(--text); text-transform: none; letter-spacing: 0; }
.season-select.archived { color: var(--muted); }

.season-new-btn {
    padding: 0.37rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--muted2);
    font-size: 0.9rem;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s;
}
.season-new-btn:hover { color: var(--text); border-color: #505050; }

/* Read-only banner when viewing an archived season */
.readonly-banner {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    background: #2a2010;
    border-bottom: 1px solid #5a4010;
    color: #c8a040;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-align: center;
    padding: 0.3rem;
    z-index: 90;
    display: none;
}
.readonly-banner.visible { display: block; }

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
}

#username {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--muted2);
}

.header-btn {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--muted2);
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
}
.header-btn:hover { color: var(--text); border-color: #505050; }

/* ---- Board ---- */

.board {
    display: flex;
    height: calc(100vh   - var(--header-h));   /* fallback */
    height: calc(100dvh  - var(--header-h));   /* mobile: excludes browser chrome */
    padding: 16px;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    background: var(--bg);
    align-items: stretch;
    /* pan-x: swiping horizontally on the board (or headers/footers) scrolls columns */
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
}

/* ---- Pool wrapper: pool col + button stacked below ---- */

#pool-wrapper {
    display: flex;
    flex-direction: column;
    width: 340px;
    flex-shrink: 0;
    /* No gap — math below ensures button border aligns with col-footer border */
}

#pool-col {
    flex: 1;        /* fills all space above the button */
    min-height: 0;
}

/* The add-roster-btn acts as the "footer" of the pool wrapper.
   Its height = --ftr-h and margin-top = 8px so its top border
   sits at the same Y as every roster column's col-footer border-top. */
.add-roster-btn {
    width: 100%;
    height: var(--ftr-h);
    margin-top: 8px;
    padding: 0 1.2rem;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--muted2);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
    touch-action: pan-x;
}
.add-roster-btn:hover { color: var(--text); border-color: #505050; }

/* ---- Start CWL button (solid border, stacked below + New Roster) ---- */
.start-cwl-btn {
    width: 100%;
    height: 36px;
    margin-top: 6px;
    padding: 0 1.2rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted2);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
    touch-action: pan-x;
}
.start-cwl-btn:hover { color: var(--text); border-color: #505050; }

/* ---- Column ---- */

.col {
    display: flex;
    flex-direction: column;
    width: 340px;
    flex-shrink: 0;
    background: var(--col-bg);
    border-radius: 6px;
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 0;
}

/* ---- Column header — FIXED HEIGHT so all header lines stay horizontally aligned ---- */
/* touch-action: pan-x  →  swiping on a header scrolls the board left/right on mobile */

.col-header {
    position: relative;         /* anchor for absolute-positioned gear */
    height: var(--hdr-h);
    padding: 0 1.2rem;
    padding-right: 2.4rem;      /* room for gear icon */
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted2);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    touch-action: pan-x;   /* swipe here scrolls the board */
    user-select: none;
}

#pool-count { color: var(--text); }

/* ---- Settings gear — absolute top-right of the column header ---- */
.settings-btn {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    background: none;
    border: none;
    outline: none;
    color: var(--muted);
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
    line-height: 0;
}
.settings-btn:hover { color: var(--muted2); }
.settings-btn:focus, .settings-btn:focus-visible { outline: none; box-shadow: none; }

/* ---- Pool search ---- */

.pool-search-wrap {
    padding: 0.45rem 0.75rem 0;
    flex-shrink: 0;
}

.pool-search {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    outline: none;
    transition: border-color 0.15s;
}
.pool-search:focus { border-color: #555; }

/* ---- Column body ---- */

.col-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.65rem 0.75rem 0.75rem;
    min-height: 0;
    /* pan-y: swiping vertically inside a column scrolls its content, not the page */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

/* ---- Column footer — FIXED HEIGHT so all footer lines stay horizontally aligned ---- */
/* touch-action: pan-x  →  swiping on a footer scrolls the board left/right on mobile */

.col-footer {
    height: var(--ftr-h);
    padding: 0 1.2rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    touch-action: pan-x;
}

.col-footer-count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted2);
    letter-spacing: 0.06em;
}

/* ---- Player card ---- */

.player-card {
    background: var(--card-bg);
    border-radius: 4px;
    padding: 0.42rem 0.75rem;
    margin-bottom: 0.28rem;
    cursor: grab;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    transition: background 0.1s, border-color 0.1s;
    min-height: 0;
}
.player-card:hover    { background: var(--card-hover); border-color: var(--border); }
.player-card:active   { cursor: grabbing; }

.card-remove-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1;
    padding: 0 0 0 0.4rem;
    flex-shrink: 0;
}
.card-remove-btn:hover { color: #aa4040; }

/* Overflow: highlight red instead of dimming */
.player-card.overflow {
    border-color: #6b2828;
    background: rgba(180, 50, 50, 0.15);
}
.player-card.overflow:hover {
    background: rgba(180, 50, 50, 0.22);
    border-color: #8b3333;
}

.player-name {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.player-tag {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--muted2);
    flex-shrink: 0;
    white-space: nowrap;
}

/* ---- Scrollbars ---- */

.col-body::-webkit-scrollbar        { width: 3px; }
.col-body::-webkit-scrollbar-track  { background: transparent; }
.col-body::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 2px; }

.board::-webkit-scrollbar        { height: 5px; }
.board::-webkit-scrollbar-track  { background: var(--bg); }
.board::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 3px; }

/* ---- Modal ---- */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.78);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal.active { display: flex; }

.modal-box {
    background: var(--col-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    width: 380px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.modal-box h3 {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.modal-box label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted2);
    margin-top: 0.5rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.modal-box input,
.modal-box select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 400;
    outline: none;
    transition: border-color 0.15s;
    appearance: none;
    -webkit-appearance: none;
}
.modal-box input:focus,
.modal-box select:focus { border-color: #555; }
.modal-box select option { background: var(--col-bg); }

.modal-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.modal-sep {
    height: 1px;
    background: var(--border);
    margin: 0.85rem 0 0.35rem;
}

.btn-primary {
    padding: 0.6rem 1.4rem;
    background: var(--text);
    color: #000;
    border: none;
    border-radius: 4px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.82; }

.btn-secondary {
    padding: 0.6rem 1.4rem;
    background: transparent;
    color: var(--muted2);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.82rem;
    font-weight: 500;
    transition: color 0.15s, border-color 0.15s;
}
.btn-secondary:hover { color: var(--text); border-color: #505050; }

.btn-danger {
    width: 100%;
    padding: 0.6rem;
    background: transparent;
    color: #884040;
    border: 1px solid #3a2020;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-danger:hover { background: rgba(180,60,60,0.08); border-color: #884040; color: #b05050; }

/* ---- Seasons management modal ---- */

.modal-box--seasons { width: 420px; }

.seasons-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 240px;
    overflow-y: auto;
    margin-bottom: 0.1rem;
}
.seasons-list:empty::after {
    content: 'No seasons yet.';
    font-size: 0.82rem;
    color: var(--muted2);
    text-align: center;
    padding: 0.6rem 0;
}

.season-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.season-row-star {
    font-size: 0.75rem;
    width: 14px;
    flex-shrink: 0;
    color: var(--muted);
    text-align: center;
}
.season-row-star.active { color: #c8a040; }

.season-row-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.82rem;
    padding: 0.32rem 0.6rem;
    outline: none;
    min-width: 0;
    transition: border-color 0.15s;
}
.season-row-input:focus { border-color: #555; }

.season-row-activate {
    padding: 0.28rem 0.65rem;
    font-size: 0.7rem;
    white-space: nowrap;
}

.season-row-delete {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.05rem;
    line-height: 1;
    padding: 0.1rem 0.2rem;
    flex-shrink: 0;
    transition: color 0.15s;
}
.season-row-delete:hover { color: #aa4040; }

.seasons-new-row {
    display: flex;
    gap: 0.45rem;
    align-items: center;
}
.seasons-new-row select,
.seasons-new-row input {
    flex: 1;
    padding: 0.5rem 0.7rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.88rem;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.15s;
}
.seasons-new-row select:focus,
.seasons-new-row input:focus { border-color: #555; }
.seasons-new-row select option { background: var(--col-bg); }
.seasons-new-row input { min-width: 70px; max-width: 90px; }

/* ---- Conflict list (Start CWL modal) ---- */

.conflicts-list {
    max-height: 260px;
    overflow-y: auto;
    margin: 0.25rem 0 0.5rem;
}

.conflict-item {
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 0.35rem;
    background: var(--card-bg);
}
.conflict-item:last-child { margin-bottom: 0; }

.conflict-name {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text);
}
.conflict-tag {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--muted2);
    margin-left: 0.35rem;
}
.conflict-clan {
    font-size: 0.76rem;
    margin-top: 0.1rem;
}
.conflict-clan.squatter { color: #884040; }   /* red  — needs to leave */
.conflict-clan.missing  { color: #7a6020; }   /* amber — needs to join */
.conflicts-empty {
    font-size: 0.84rem;
    color: var(--muted2);
    text-align: center;
    padding: 1.2rem 0;
}

/* ---- Nav tabs (Rosters / Bases) ---- */

.nav-tabs {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.nav-tab {
    padding: 0.35rem 0.85rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted2);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.nav-tab:first-child { border-radius: 4px 0 0 4px; }
.nav-tab:last-child  { border-radius: 0 4px 4px 0; }
.nav-tab.active {
    background: var(--card-bg);
    color: var(--text);
    border-color: #505050;
}
.nav-tab:hover:not(.active) { color: var(--text); border-color: #404040; }

/* ---- Bases view ---- */

.bases-view {
    height: calc(100vh  - var(--header-h));
    height: calc(100dvh - var(--header-h));
    overflow-y: auto;
    padding: 16px 24px;
    background: var(--bg);
}

.bases-toolbar {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.bases-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}

.base-card {
    background: var(--col-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}
.base-card-img {
    width: 100%;
    aspect-ratio: 16/10;
    object-fit: cover;
    display: block;
    background: var(--bg);
}
.base-card-img-placeholder {
    width: 100%;
    aspect-ratio: 16/10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--muted);
    font-size: 0.75rem;
}
.base-card-body {
    padding: 0.6rem 0.75rem;
}
.base-card-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.15rem;
}
.base-card-link {
    font-size: 0.7rem;
    color: var(--muted2);
    word-break: break-all;
}
.base-card-link a { color: #6688cc; text-decoration: none; }
.base-card-link a:hover { text-decoration: underline; }
.base-card-cc { font-size: 0.7rem; color: var(--muted2); margin-top: 0.2rem; }
.base-card-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.7);
    border: none;
    color: #aa4040;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: color 0.15s;
}
.base-card-remove:hover { color: #dd5050; }

/* ---- Assignment matrix ---- */

.bases-matrix-wrap { margin-top: 0.5rem; }
.matrix-title {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted2);
    margin-bottom: 0.5rem;
}
.matrix-scroll { overflow-x: auto; }

.bases-matrix {
    border-collapse: collapse;
    width: 100%;
    min-width: 500px;
}
.bases-matrix th,
.bases-matrix td {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    font-size: 0.78rem;
    text-align: left;
    vertical-align: middle;
}
.bases-matrix th {
    background: var(--col-bg);
    color: var(--muted2);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.bases-matrix td {
    background: var(--card-bg);
}
.bases-matrix .base-name-cell {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    min-width: 120px;
}
.bases-matrix select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-size: 0.78rem;
    padding: 0.3rem 0.4rem;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}
.bases-matrix select option { background: var(--col-bg); }
.bases-matrix .empty-state-cell {
    color: var(--muted);
    font-style: italic;
    text-align: center;
}

/* Image drop/paste zone */
.image-drop-zone {
    position: relative;
    border: 1px dashed var(--border);
    border-radius: 4px;
    background: var(--bg);
    cursor: pointer;
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.3rem;
    transition: border-color 0.15s, background 0.15s;
    overflow: hidden;
}
.image-drop-zone:hover,
.image-drop-zone.drag-over { border-color: #555; background: var(--card-bg); }
.image-drop-zone.has-image { border-style: solid; border-color: #505050; }

.file-input-hidden {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.image-preview {
    width: 100%;
    max-height: 160px;
    object-fit: contain;
    display: block;
    border-radius: 2px;
}

#image-drop-label {
    font-size: 0.76rem;
    color: var(--muted2);
    pointer-events: none;
    text-align: center;
    padding: 0.5rem;
    z-index: 0;
}

.image-clear-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.7);
    border: none;
    color: var(--muted2);
    font-size: 0.75rem;
    padding: 2px 7px;
    border-radius: 3px;
    cursor: pointer;
    z-index: 2;
    transition: color 0.15s;
}
.image-clear-btn:hover { color: #dd5050; }

/* ---- Drag feedback ---- */
.sortable-ghost { opacity: 0.15; }
.sortable-drag  { cursor: grabbing; }
