/* ==========================================================================
   Design Tokens & Modern Dark Mode Base
   ========================================================================== */

:root {
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    /* Color System */
    --bg-base: #090a0f;
    --bg-surface: #12141c;
    --bg-surface-elevated: #1a1d29;
    --bg-surface-hover: rgba(255, 255, 255, 0.04);

    --primary: #e63946;
    --primary-hover: #c92a37;
    --primary-glow: rgba(230, 57, 70, 0.25);
    --accent-cyan: #4cc9f0;

    --text-main: white;
    --text-muted: #94a3b8;

    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(230, 57, 70, 0.5);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);

    --transition: 0.2s ease;
}

/* Base Resets */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    color-scheme: dark;
}

body {
    font-family: var(--font-sans);
    font-size: 1.25em;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* Accessibility Utility */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3 {
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
}

h2 {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
}

a {
    color: inherit;
    text-decoration: none;
    transition: color var(--transition);
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */

header {
    top: 0;
    z-index: 100;
    background: rgba(18, 20, 28, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
}

.header_container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem .5rem;
}

.nav_bar {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mode_links {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-left: auto; /* Pushes the links to the far right */
}

.logo_link {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.logo {
    width: 2.75rem;
    height: 2.75rem;
    transition: transform var(--transition);
    filter: drop-shadow(0 2px 8px var(--primary-glow));
}

.logo_link:hover .logo {
    transform: scale(1.08) rotate(-2deg);
}

/* ==========================================================================
   Search Container & Box
   ========================================================================== */

.search_container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 1rem 0 2.5rem 0;
    width: 100%;
    padding: 2rem 1.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.search_box {
    width: 100%;
    max-width: 480px;
}

#search_form {
    display: flex;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#search_form:has(input:focus) {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

#player_search {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.65rem 1rem;
    color: var(--text-main);
    outline: none;
    width: 25ch;
}

#player_search::placeholder {
    color: var(--text-muted);
}

#search_form input[type="submit"] {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    cursor: pointer;
    transition: background var(--transition);
}

#search_form input[type="submit"]:hover {
    background: var(--primary-hover);
}

/* ==========================================================================
   SPA Views & Signatures
   ========================================================================== */
h1.sitename {
    font-family: monospace;
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.card_signature {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
}

/* Custom formatting for the player stats table */
.player_header_title {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
    text-align: center;
}

.player_header_title .rank {
    font-size: .85rem;
    color: var(--text-muted);
}

.player_stats_table {
    width: 100%;
}

/* Left-align titles, right-align values */
.player_stats_table td.stat_name {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
}

.player_stats_table td.stat_val {
    text-align: right;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}

.player_details {
    padding: 2em;
}

.leaderboard_header {
    text-align: center;
    padding: 1.25rem;
}

.last_updated {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Prompts & Empty States */
.player_info_prompt,
.leaderboard_prompt,
.skills_prompt,
.activities_prompt {
    display: grid;
    place-content: center;
    min-height: 180px;
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* ==========================================================================
   Tables & Data Presentation
   ========================================================================== */

.table_container {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.data_table {
    width: 100%;
    border-collapse: collapse;
    text-align: center;
}

th {
    background: var(--bg-surface-elevated);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

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

tr {
    transition: background-color var(--transition);
}

tr:hover td {
    background-color: var(--bg-surface-hover);
}

/* Category Accent Border Classes */
tr[class$="-row"] {
    border-left: 3px solid var(--category-color, transparent);
}
tr.combat-row { --category-color: var(--primary); }
tr.skilling-row { --category-color: var(--text-muted); }
tr.achievement-row { --category-color: var(--accent-cyan); }
tr.activity-row { --category-color: #2ecc71; }

.max-player {
    background: rgba(46, 204, 113, 0.5);
}

/* ==========================================================================
   Tabs
   ========================================================================== */

.tabs_container {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.tabs {
    display: flex;
    background: var(--bg-surface-elevated);
    border-bottom: 1px solid var(--border-subtle);
}

.tab_button {
    flex: 1;
    padding: 1rem;
    background: transparent;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: none;
    cursor: pointer;
    transition: color var(--transition), background-color var(--transition);
    position: relative;
}

.tab_button:hover {
    color: var(--text-main);
    background-color: var(--bg-surface-hover);
}

.tab_button.active {
    color: var(--primary);
}

.tab_button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    box-shadow: 0 -2px 8px var(--primary-glow);
}

.tab_content {
    display: none;
}

.tab_content.active {
    display: block;
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
    margin-top: auto;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    padding: 1.5rem 1rem;
    text-align: center;
}

.madeby {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 1rem 0;
}

.madeby a {
    color: var(--primary);
    font-weight: 600;
}

.madeby a:hover {
    text-decoration: underline;
}

.copyright_disclaimer {
    max-width: 600px;
    margin: 0 auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.75;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 500px) {
    .nav_bar {
        flex-direction: row;
        align-items: center;
    }

    .logo {
        width: 35px;
        height: 35px;
    }

    .logo_link {
        margin: 0;
    }

    /* Update mode links for small screens so they don't break layout */
    .mode_links {
        font-size: 0.85rem;
        gap: 0.75rem;
    }

    /* Expand search bar nicely on mobile now that it's in main */
    #player_search {
        width: 100%;
        font-size: 0.85rem;
    }

    #search_form {
        height: 35px;
    }

    #search_form input[type="submit"] {
        font-size: 0.75rem;
    }

    /* Table Mobile Formatting */
    .table_container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    th, td {
        padding: 0.5rem 0.375rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    .data_table th {
        letter-spacing: 0;
        font-size: 0.85rem;
    }
}