/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* --- Login --- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.user-select {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.user-option {
    cursor: pointer;
}

.user-option input { display: none; }

.user-option span {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.user-option input:checked + span {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.user-option:hover span {
    border-color: var(--accent);
}

.login-card input[type="password"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.login-card button {
    width: 100%;
    padding: 0.6rem;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.login-card button:hover { background: var(--accent-hover); }

.error {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
    padding: 0.5rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.setup-link {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.setup-back {
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* --- Header --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.3rem;
    letter-spacing: 0.05em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-badge {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.9rem;
}

.logout-btn {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: all 0.15s;
}

.logout-btn:hover {
    color: var(--red);
    border-color: var(--red);
    text-decoration: none;
}

.gorilla-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.2rem 0.5rem;
    transition: all 0.15s;
}

.gorilla-btn:hover {
    border-color: var(--accent);
    background: rgba(88, 166, 255, 0.1);
}

.gorilla-back-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    transition: all 0.15s;
}

.gorilla-back-btn:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.score-form select {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    overflow-x: auto;
}

.tab {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem 1.2rem;
    cursor: pointer;
    font-size: 0.95rem;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}

.tab:hover { color: var(--text); }

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* --- Main content --- */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-content h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    text-align: center;
}

/* Today tab two-column layout */
.today-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}
.today-main {
    flex: 1 1 0;
    min-width: 0;
}
.today-sidebar {
    width: 291px;
    flex-shrink: 0;
    position: sticky;
    top: 1rem;
}
@media (max-width: 700px) {
    .today-layout { flex-direction: column; }
    .today-sidebar { width: 100%; position: static; }
}

/* Awards feed */
#awards-feed {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 70vh;
    overflow-y: auto;
}
.award-entry {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
}
.award-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}
.award-body {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}
.award-line {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.award-player {
    font-weight: 700;
    font-size: 0.85rem;
    background: none;
    border: none;
    color: var(--text);
    padding: 0;
    cursor: pointer;
    position: relative;
    z-index: 1;
}
.award-player:hover { color: var(--accent); }
.award-period-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}
.award-entry {
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.award-entry:hover { background: var(--border); border-color: var(--accent); }
.award-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.medal-legend {
    margin-top: 1.25rem;
    border-top: 1px solid var(--border);
    padding-top: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.medal-legend-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.medal-legend-icon { font-size: 1rem; width: 1.4rem; text-align: center; flex-shrink: 0; }
.medal-legend-label { line-height: 1.2; }

.submit-heading {
    margin-top: 2rem;
}

.loading, .empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.puzzle-num {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

/* --- Score tables --- */
.score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.score-table th,
.score-table td {
    padding: 0.5rem 0.6rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.score-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.score-table th.sortable:hover {
    color: var(--text);
}

.score-table th.sort-active {
    color: var(--accent);
}

.score-table .player-name {
    text-align: left;
    font-weight: 600;
}

.score-table .final-score {
    font-weight: 700;
    font-size: 1.05rem;
}

.score-table tr.is-me {
    background: rgba(88, 166, 255, 0.08);
}

.score-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.del-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    transition: all 0.15s;
}

.del-btn:hover {
    color: var(--red);
    background: rgba(248, 81, 73, 0.15);
}

/* --- Score form --- */
.score-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-left: 20%;
    margin-right: 20%;
}

.score-form label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.score-form input[type="number"],
.score-form input[type="date"] {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row > label { flex: 1; }

.rounds {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.rounds legend {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0 0.4rem;
}

.rounds-row {
    display: flex;
    gap: 0.5rem;
}

.rounds-row label {
    flex: 1;
    text-align: center;
    font-size: 0.8rem;
}

.rounds-row input {
    text-align: center;
}

.score-form button[type="submit"] {
    width: 100%;
    padding: 0.7rem;
    border: none;
    border-radius: 6px;
    background: var(--green);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background 0.15s;
}

.score-form button[type="submit"]:hover { background: #2ea043; }
.score-form button:disabled { opacity: 0.6; cursor: not-allowed; }

.paste-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.paste-input {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    font-family: monospace;
    resize: vertical;
    transition: border-color 0.15s;
}

.paste-input:focus {
    outline: none;
    border-color: var(--accent);
}

.msg { margin-top: 0.75rem; font-size: 0.9rem; text-align: center; }
.msg.success { color: var(--green); }
.msg.error { color: var(--red); }

/* --- Leaderboard --- */
.leaderboard-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.leaderboard-controls h2 { margin-bottom: 0; }

.period-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.period-btn {
    background: var(--bg);
    border: none;
    color: var(--text-muted);
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
    border-right: 1px solid var(--border);
}

.period-btn:last-child { border-right: none; }

.period-btn.active {
    background: var(--accent);
    color: #fff;
}

.period-btn:hover:not(.active) {
    background: var(--surface);
    color: var(--text);
}

.streaks { margin-top: 0.5rem; }

/* Award leaderboard */
#award-leaderboard { margin-top: 0.5rem; }
.award-lb-table th { text-align: center; }
.award-lb-table td { text-align: center; }
.award-lb-table td:nth-child(2) { text-align: left; } /* player name */
.award-lb-cell { color: var(--text-muted); }
.award-lb-has { color: var(--text); font-weight: 600; }

/* --- History --- */
.history-day {
    margin-bottom: 2rem;
}

.history-day h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3rem;
}

/* --- Period winner banners --- */
.winner-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    margin: 0.25rem 0 1.75rem;
    font-size: 0.9rem;
}

.winner-banner-week {
    background: rgba(88, 166, 255, 0.07);
    border: 1px solid rgba(88, 166, 255, 0.25);
}

.winner-banner-month {
    background: rgba(210, 153, 34, 0.1);
    border: 1px solid rgba(210, 153, 34, 0.35);
}

.winner-banner-clickable {
    cursor: pointer;
    transition: filter 0.12s;
}
.winner-banner-clickable:hover { filter: brightness(1.15); }

.winner-chevron {
    margin-left: auto;
    font-size: 1.1rem;
    color: var(--text-muted);
    line-height: 1;
}

.winner-trophy {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.winner-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.winner-entries {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-top: 0.2rem;
}

.winner-entry {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
}

.we-icon { flex-shrink: 0; font-size: 0.9rem; }

.we-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.we-score {
    color: var(--text-muted);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.we-games {
    color: var(--text-muted);
    font-size: 0.7rem;
    opacity: 0.75;
    flex-shrink: 0;
    cursor: help;
}

.is-non-qualifier {
    opacity: 0.65;
}

.we-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex: 1;
    opacity: 0.7;
}

.winner-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.winner-banner-week  .winner-label { color: #79c0ff; }
.winner-banner-month .winner-label { color: #e3b341; }

.winner-name {
    font-weight: 700;
    color: var(--text);
}

.winner-score {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    header { padding: 0.75rem 1rem; }
    header h1 { font-size: 1.1rem; }
    main { padding: 1rem; }
    .tabs { padding: 0 0.5rem; }
    .tab { padding: 0.6rem 0.8rem; font-size: 0.85rem; }
    .form-row { flex-direction: column; gap: 0; }
    .rounds-row { flex-wrap: wrap; }
    .rounds-row label { flex: 0 0 calc(33% - 0.35rem); }
    .score-table { font-size: 0.8rem; }
    .score-table th, .score-table td { padding: 0.4rem 0.3rem; }
    .leaderboard-controls { flex-direction: column; align-items: flex-start; }
}

/* --- Player name link --- */
.player-link {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    padding: 0;
    transition: color 0.12s;
}
.player-link:hover { color: var(--accent); text-decoration: underline; }

/* --- Season divider --- */
.season-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.5rem 0 1.75rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.season-divider::before,
.season-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* --- Profile modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
    overflow-y: auto;
}
.modal-overlay.is-open { display: flex; }

/* Period results modal stacks above the profile modal */
.results-modal-overlay { z-index: 110; background: rgba(0,0,0,0.55); }

/* --- Global tooltip --- */
.app-tooltip {
    position: fixed;
    z-index: 9999;
    background: #1c2026;
    color: #e6edf3;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 6px;
    padding: 0.28rem 0.6rem;
    font-size: 0.78rem;
    font-family: inherit;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45);
    max-width: 220px;
    white-space: normal;
    line-height: 1.35;
}
.app-tooltip[hidden] { display: none; }

.modal-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.75rem;
    width: 100%;
    max-width: 680px;
    margin: auto;
}

.modal-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    transition: all 0.12s;
}
.modal-close:hover { color: var(--red); background: rgba(248,81,73,0.12); }

/* --- Profile content --- */
.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.profile-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.profile-name {
    font-size: 1.3rem;
    margin-bottom: 0.3rem;
}

.profile-medals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.medal-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.medal-chip-week  { background: rgba(88,166,255,0.12); color: #79c0ff; border: 1px solid rgba(88,166,255,0.3); }
.medal-chip-month { background: rgba(210,153,34,0.12); color: #e3b341; border: 1px solid rgba(210,153,34,0.3); }

.profile-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-box {
    flex: 1;
    min-width: 70px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.5rem;
    text-align: center;
}
.stat-val { font-size: 1.1rem; font-weight: 700; }
.stat-lbl { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.1rem; }

.profile-section { margin-bottom: 1.25rem; }
.profile-section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
}

.pb-table td { text-align: center; }

.medals-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.medal-tag {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.12s;
    font-family: inherit;
}
.medal-tag:hover { filter: brightness(1.2); }
.medal-tag-week  { background: rgba(88,166,255,0.1);  color: #79c0ff; border: 1px solid rgba(88,166,255,0.25); }
.medal-tag-month { background: rgba(210,153,34,0.1);  color: #e3b341; border: 1px solid rgba(210,153,34,0.25); }
.medal-tag-puzzle { background: rgba(63,185,80,0.1);  color: #3fb950; border: 1px solid rgba(63,185,80,0.25); }

.profile-history-scroll {
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.profile-history-scroll .score-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

@media (max-width: 600px) {
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-card { border-radius: 14px 14px 0 0; max-height: 90vh; overflow-y: auto; }
    .profile-stats { gap: 0.4rem; }
    .stat-box { min-width: 55px; }
}
