:root {
    --bg: #f5f5f7;
    --panel: #ffffff;
    --panel-2: #f5f5f7;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 113, 227, 0.35);
    --text: #1d1d1f;
    --text-dim: #6e6e73;
    --text-faint: #a1a1a6;
    --accent: #0071e3;
    --warn: #ff9500;
    --break: #ff3b30;
    --place: #34c759;
    --islander: #248a3d;
    --discord: #5865f2;
    --radius-lg: 20px;
    --radius: 12px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -14px rgba(0, 0, 0, 0.16);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', 'Pretendard', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    word-break: keep-all;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 40px 0 30px;
    margin-bottom: 26px;
    position: relative;
}

.user-chip {
    position: absolute;
    top: 8px;
    right: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 8px 6px 16px;
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    font-weight: 600;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

header h1 .pick {
    font-size: 1.9rem;
}

header .subtitle {
    color: var(--text-dim);
    margin-top: 8px;
    font-size: 1rem;
}

.panel {
    background: var(--panel);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 22px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.panel h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel h2::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.panel-header h2 {
    margin-bottom: 0;
}

.badge {
    background: rgba(0, 113, 227, 0.1);
    border: 1px solid rgba(0, 113, 227, 0.22);
    color: var(--accent);
    padding: 5px 14px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ---- Gate screen ---- */

.gate-panel {
    text-align: center;
    padding: 52px 24px;
    max-width: 460px;
    margin: 0 auto 22px;
}

.gate-emoji {
    font-size: 3rem;
    margin-bottom: 10px;
}

.gate-title {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 10px;
}

.gate-desc {
    color: var(--text-dim);
    font-size: 0.92rem;
    margin-bottom: 22px;
}

.gate-hint {
    margin-top: 14px;
    font-size: 0.82rem;
    color: var(--warn);
    font-weight: 600;
}

.btn-discord {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--discord);
    color: #fff;
    padding: 12px 24px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: filter 0.2s var(--ease);
}

.btn-discord:hover {
    filter: brightness(1.08);
}

.discord-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
    opacity: 0.85;
}

/* ---- Islander tags ---- */

.islander-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(52, 199, 89, 0.12);
    color: var(--islander);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    vertical-align: middle;
}

.islander-dot {
    font-size: 0.75rem;
    margin-left: 4px;
}

.player-link.islander {
    color: var(--islander);
    font-weight: 700;
}

.ac-name.islander {
    color: var(--islander);
}

.alba-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(255, 149, 0, 0.12);
    color: var(--warn);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    vertical-align: middle;
}

.alba-dot {
    font-size: 0.75rem;
    margin-left: 4px;
}

.player-link.alba {
    color: var(--warn);
    font-weight: 700;
}

.ac-name.alba {
    color: var(--warn);
}

/* ---- Form ---- */

.form-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 14px;
}

.form-row:last-of-type {
    margin-bottom: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    position: relative;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.form-group input::placeholder {
    color: var(--text-faint);
}

.btn-group {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.15s var(--ease), background 0.15s var(--ease);
}

.btn:active {
    filter: brightness(0.94);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: #0077ed;
}

.btn-secondary {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #e8e8ed;
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 6px 14px;
}

.btn-ghost:hover {
    background: var(--panel-2);
    color: var(--text);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.82rem;
}

.quick-range-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 4px;
}

.chip-btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 7px 13px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s var(--ease);
    white-space: nowrap;
}

.chip-btn:hover {
    background: rgba(0, 113, 227, 0.08);
    color: var(--accent);
    border-color: rgba(0, 113, 227, 0.3);
}

.chip-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

/* ---- Table ---- */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: var(--panel-2);
    padding: 13px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.th-filterable {
    position: relative;
    padding: 0;
}

.th-filter-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    padding: 13px 16px;
    background: transparent;
    border: none;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: none;
    cursor: pointer;
    transition: color 0.15s;
}

.th-filter-btn:hover {
    color: var(--accent);
}

.th-filter-btn.active {
    color: var(--accent);
}

.th-filter-caret {
    font-size: 0.65rem;
    opacity: 0.7;
}

.th-filter-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 50;
    min-width: 140px;
    overflow: hidden;
}

.th-filter-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    background: var(--panel);
    border: none;
    border-bottom: 1px solid var(--border);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    text-transform: none;
    color: var(--text);
    cursor: pointer;
}

.th-filter-option:last-child {
    border-bottom: none;
}

.th-filter-option:hover {
    background: var(--panel-2);
}

.th-filter-option.active {
    color: var(--accent);
    font-weight: 700;
}

td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

tbody tr {
    transition: background 0.15s var(--ease);
}

tbody tr:hover {
    background: rgba(0, 113, 227, 0.04);
}

tbody tr:last-child td {
    border-bottom: none;
}

.player-link {
    color: var(--text);
    cursor: pointer;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--text-faint);
    text-underline-offset: 3px;
    transition: color 0.15s;
}

.player-link:hover {
    color: var(--accent);
}

.action-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.action-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.action-BREAK {
    background: rgba(255, 59, 48, 0.1);
    color: var(--break);
}

.action-BREAK::before {
    background: var(--break);
}

.action-PLACE {
    background: rgba(52, 199, 89, 0.12);
    color: var(--islander);
}

.action-PLACE::before {
    background: var(--place);
}

.coord {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.83rem;
    color: var(--text-dim);
}

.empty {
    text-align: center;
    color: var(--text-faint);
    padding: 48px !important;
}

.skeleton-cell {
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(90deg, #ececee 25%, #f7f7f8 37%, #ececee 63%);
    background-size: 400% 100%;
    animation: skeleton-pulse 1.4s ease infinite;
}

@keyframes skeleton-pulse {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---- Pagination ---- */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.page-btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.15s var(--ease);
    min-width: 36px;
    text-align: center;
}

.page-btn:hover:not(:disabled):not(.active) {
    background: rgba(0, 113, 227, 0.08);
    border-color: var(--accent);
    color: var(--accent);
}

.page-btn.active {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
    font-weight: 700;
}

.page-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.page-ellipsis {
    color: var(--text-faint);
    padding: 0 4px;
    font-size: 0.85rem;
}

/* ---- Autocomplete ---- */

.autocomplete-wrap {
    position: relative;
}

.autocomplete-list {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: var(--shadow);
}

.autocomplete-item {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 4px 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--panel-2);
}

.ac-name {
    font-weight: 700;
    color: var(--text);
}

.ac-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-size: 0.78rem;
}

.ac-break,
.ac-place,
.ac-total {
    white-space: nowrap;
}

.ac-break {
    color: var(--break);
}

.ac-place {
    color: var(--islander);
}

.ac-total {
    color: var(--text-faint);
}

/* ---- Player Detail Panel ---- */

.player-detail-panel {
    border-color: var(--border-strong);
    animation: panel-in 0.25s var(--ease);
}

@keyframes panel-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.player-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.player-info-card {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.player-info-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}

.player-info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-faint);
    font-size: 0.85rem;
    white-space: nowrap;
}

.info-value {
    color: var(--text);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.83rem;
    word-break: break-all;
    max-width: 60%;
    text-align: right;
}

.player-stat-mini {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.mini-stat {
    flex: 1;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    transition: transform 0.15s var(--ease);
}

.mini-stat:hover {
    transform: translateY(-2px);
}

.mini-stat.break {
    border-color: rgba(255, 59, 48, 0.25);
}

.mini-stat.place {
    border-color: rgba(52, 199, 89, 0.3);
}

.mini-stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
}

.mini-stat.break .mini-stat-value {
    color: var(--break);
}

.mini-stat.place .mini-stat-value {
    color: var(--islander);
}

.mini-stat-label {
    color: var(--text-faint);
    font-size: 0.78rem;
    margin-top: 4px;
}

footer {
    text-align: center;
    padding: 34px 0 16px;
    color: var(--text-faint);
    font-size: 0.82rem;
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .player-detail-grid {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 1.9rem;
    }

    .user-chip {
        position: static;
        margin: 0 auto 16px;
        width: fit-content;
    }

    .table-wrapper {
        border: none;
        overflow-x: visible;
    }

    table, thead, tbody, th, tr, td {
        display: block;
    }

    thead {
        display: none;
    }

    tbody tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 6px 0;
        background: var(--panel-2);
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        padding: 9px 14px;
        border-bottom: 1px solid var(--border);
    }

    tbody tr td:last-child {
        border-bottom: none;
    }

    td::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 700;
        color: var(--text-faint);
        flex-shrink: 0;
    }
}

@media (max-width: 480px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}
