/* border-box everywhere so padding/border don't add to a declared width */
*, *::before, *::after {
    box-sizing: border-box;
}

@font-face {
    font-family: 'RimWordFont';
    src: url('fonts/RimWordFont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* 700 weight needed for the /stats page's bold numbers */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column; /* row would put .rectangle + .converter-box side by side */
    align-items: center;
    justify-content: center;
    gap: 0;
    background: linear-gradient(135deg, #1b2838, #1d2b36 60%);
    /* padding leaves room for the nav button and credit without overlapping content */
    padding: 56px 16px 48px;
    box-sizing: border-box;
}

.rectangle {
    background-color: #2a2a2a;
    border: 2px solid #3a3a3a;
    width: 375px;
    max-width: calc(100vw - 40px);
    min-width: 0; /* stops descendant content from stretching the card wider */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 15px 10px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    animation: card-in 0.4s ease-out;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.rectangle:hover {
    box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.7);
    transform: translateY(-2px);
}

.card .rectangle {
    width: 100%;
    max-width: none;
    padding-top: 24px; /* room for .title floating on the top edge */
}

.rectangle.converter-box {
    width: 300px;
    margin-top: 16px;
    animation-delay: 0.08s;
    transition: width 0.3s ease;
}

.rectangle.converter-box.expanded {
    width: min(640px, calc(100vw - 40px));
}

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


/* wraps a .rectangle card and floats its .title on top of the card's edge */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 375px;
    max-width: calc(100vw - 40px);
}

.title {
    display: block; /* <a> is inline by default; text-align:center needs block */
    font-family: 'RimWordFont', sans-serif;
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    text-decoration: none;
    background: linear-gradient(to bottom, #eeeeee, #cccccc, #838383);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.title:hover {
    opacity: 0.8;
}

/* floats the title on the card's edge; scoped to .card so /stats's plain
   .title (no wrapper) stays in flow and can wrap on narrow viewports */
.card .title {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    white-space: nowrap; /* single word, keeps it from ever wrapping in the tight card */
    filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.7));
}

.text {
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    color: #cccccc;
    padding: 0 10px;
    margin-top: 4px;
    line-height: 1.5;
    text-align: justify;
    text-align-last: center;
}

/* fixed to the viewport corner so it never drifts over page content */
.credit {
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.25);
    color: #8f98a0;
    font-family: 'Roboto', sans-serif;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.credit:hover {
    opacity: 1;
    color: #66c0f4;
    text-decoration: none;
}

.credit img {
    width: 16px;
    height: 16px;
    opacity: 0.85;
}

.link-section {
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    color: #dddddd;
    font-weight: bold;
    text-align: center;
    margin-top: -10px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

.link-section a {
    color: #66c0f4;
    text-decoration: none;
}

.link-section a:hover {
    text-decoration: underline;
}

.link-section img {
    max-width: 100%;
    border-radius: 5px;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3);
}

/* countdown pulse, text-only */
#countdown {
    display: inline-block;
    transition: transform 0.15s ease, color 0.15s ease;
}

#countdown.tick {
    transform: scale(1.3);
}

#countdown.urgent {
    color: #ff6b6b;
}


.instructions {
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    color: #cccccc;
    line-height: 1.5;
    text-align: left;
    margin-top: -3px;
    padding: 10px 0;
}
.instructions p {
    margin: 0 0 5px;
}
.instructions code {
    background-color: #444;
    color: #e0e0e0;
    padding: 2px 4px;
    border-radius: 3px;
}

.fast-hint {
    font-size: 11px;
    color: #8f98a0;
    margin-top: 10px;
    line-height: 1.4;
}

.fast-hint a {
    color: #66c0f4;
}

/* numbered step badges */
.instructions .steps {
    list-style: none;
    counter-reset: step;
    margin: 4px 0 0;
    padding: 0;
}

.instructions .steps li {
    counter-increment: step;
    position: relative;
    padding: 4px 0 4px 32px;
    line-height: 1.5;
}

.instructions .steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(102, 192, 244, 0.15);
    border: 1px solid rgba(102, 192, 244, 0.4);
    color: #66c0f4;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* link-converter widget, landing page only */
.converter-label {
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    font-weight: bold;
    color: #dddddd;
    margin-bottom: 8px;
    text-align: center;
}

.converter-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 10px;
}

.converter-input {
    flex: 1 1 auto;
    min-width: 0;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid #444;
    border-radius: 4px;
    color: #e0e0e0;
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    padding: 8px 10px;
}

.converter-input:focus {
    outline: none;
    border-color: #66c0f4;
}

.converter-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 10px;
    margin-bottom: 10px;
}

.converter-error {
    font-family: 'Roboto', sans-serif;
    font-size: 12px;
    color: #ff6b6b;
    text-align: center;
    margin-bottom: 10px;
}

.fast-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    color: #cccccc;
}

.fast-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.fast-toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: #444;
    border-radius: 10px;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.fast-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #ccc;
    border-radius: 50%;
    transition: transform 0.2s ease, background 0.2s ease;
}

.fast-toggle input:checked + .fast-toggle-track {
    background: rgba(76, 175, 130, 0.35);
}

.fast-toggle input:checked + .fast-toggle-track .fast-toggle-thumb {
    transform: translateX(16px);
    background: #4caf82;
}

.fast-toggle input:focus-visible + .fast-toggle-track {
    outline: 2px solid #66c0f4;
    outline-offset: 2px;
}

/* example-URL rows on the landing page, with a copy button */
.code-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.code-row code {
    flex: 1 1 auto;
    min-width: 0;
    display: block;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 8px;
    scrollbar-width: thin; /* Firefox ignores ::-webkit-scrollbar entirely */
    scrollbar-color: rgba(102, 192, 244, 0.4) transparent;
}

.code-row code::-webkit-scrollbar {
    height: 3px;
}

.code-row code::-webkit-scrollbar-track {
    background: transparent;
}

.code-row code::-webkit-scrollbar-thumb {
    background: rgba(102, 192, 244, 0.4);
    border-radius: 2px;
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    background: rgba(102, 192, 244, 0.08);
    border: 1px solid rgba(102, 192, 244, 0.4);
    border-radius: 4px;
    color: #66c0f4;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.copy-btn:hover {
    background: rgba(102, 192, 244, 0.18);
    border-color: #66c0f4;
}

.copy-btn.copied {
    color: #4caf82;
    border-color: #4caf82;
}

/* /stats page, moved out of an inline <style> block in worker.js */

body.stats-body {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    height: 100vh;
    overflow: hidden;
    font-family: 'Roboto', sans-serif;
    box-sizing: border-box;
}

.stats-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
}

.stats-header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.stats-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    margin-bottom: 20px;
    gap: 12px;
    flex-shrink: 0;
}

.stat-card {
    background: rgba(23, 26, 33, 0.8);
    padding: 14px 20px;
    border-radius: 8px;
    text-align: center;
    flex: 1;
    min-width: 100px;
}

.stat-number {
    font-size: 2em;
    font-weight: bold;
    color: #66c0f4;
}

.stat-label {
    color: #c7d5e0;
    margin-top: 4px;
    font-size: 0.9em;
}

.table-wrapper {
    flex: 1;
    /* vendor/simplebar.min.js manages scrolling here via JS; this stays as a
       plain-CSS fallback for before it loads, or if it fails */
    overflow-y: auto;
    border-radius: 8px;
    min-height: 0;
}

/* SimpleBar's .simplebar-wrapper uses height: inherit, which copies the
   parent's computed height ("auto" for a flex item, not its real size), so
   it grew to fit all the content instead of the visible area, and the
   overflow-y: auto above kicked in too, causing a double scrollbar. height:
   100% fixes that by resolving against the actual flex-item box.
   Don't add overflow: hidden on the host itself: SimpleBar reads that as
   "never show a scrollbar" and disables its thumb even when content overflows. */
.table-wrapper > .simplebar-wrapper {
    height: 100%;
}

/* matches the site's blue/navy palette instead of SimpleBar's default black thumb */
.table-wrapper .simplebar-scrollbar:before {
    background: #66c0f4;
    opacity: 0.35;
}

.table-wrapper .simplebar-scrollbar.simplebar-visible:before {
    opacity: 0.65;
}

.table-wrapper .simplebar-track.simplebar-vertical {
    width: 10px;
}

.table-wrapper .simplebar-track.simplebar-horizontal {
    height: 10px;
}

.stats-table {
    width: 100%;
    background: rgba(23, 26, 33, 0.8);
    border-collapse: collapse;
    /* fixed makes the th widths below binding, instead of the browser
       expanding columns to fit content and forcing horizontal scroll */
    table-layout: fixed;
}

.stats-table thead th {
    background: #1b2838;
    color: #c7d5e0;
    padding: 12px 15px;
    text-align: left;
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 1;
}

/* no hover treatment or icon until sorted, stays a "click around and find it" affordance */
.stats-table thead th[data-sort] {
    cursor: pointer;
}

.sort-arrow {
    color: #66c0f4;
    font-size: 0.7em;
}

.stats-table td {
    padding: 10px 15px;
    border-bottom: 1px solid #2a475e;
    color: #c7d5e0;
}

/* faint dividers between the mixed data types, without a full grid look */
.stats-table th:not(:last-child),
.stats-table td:not(:last-child) {
    border-right: 1px solid rgba(42, 71, 94, 0.5);
}

.col-rank {
    width: 50px;
    text-align: center;
}

/* shrinking + graying fixes "Rank" truncating to "Ran-" and reads better as a
   secondary label. text-align repeated here since ".stats-table thead th"
   (two elements) outranks a single class like .col-rank alone. */
.stats-table th.col-rank {
    padding-left: 6px;
    padding-right: 6px;
    font-size: 0.75em;
    font-weight: 600;
    color: #8f98a0;
    white-space: nowrap;
    text-align: center;
}

.col-views {
    width: 76px;
    text-align: center;
}

/* same treatment as .col-rank above, "Views" overflowed for the same reason */
.stats-table th.col-views {
    padding-left: 6px;
    padding-right: 6px;
    font-size: 0.75em;
    font-weight: 600;
    color: #8f98a0;
    white-space: nowrap;
    text-align: center;
}

.col-lastviewed {
    width: 118px;
}

/* gutter for SimpleBar's thumb track so it never overlaps the date/time text.
   Two classes outrank the padding shorthand in the mobile media query below,
   so this survives at every breakpoint without a copy in there too. */
.stats-table .col-lastviewed {
    padding-right: 16px;
}

/* same treatment as Rank and Views above */
.stats-table th.col-lastviewed {
    font-size: 0.75em;
    font-weight: 600;
    color: #8f98a0;
    white-space: nowrap;
    text-align: center;
}

/* long titles truncate with an ellipsis instead of forcing the table wider */
.item-cell {
    overflow: hidden;
}

.item-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.stats-table tr:hover {
    background: rgba(102, 192, 244, 0.1);
}

.stats-table a {
    color: #66c0f4;
    text-decoration: none;
}

.stats-table a:hover {
    text-decoration: underline;
}

.rank {
    font-weight: bold;
    color: #8f98a0;
    text-align: center;
    padding-left: 4px;
    padding-right: 4px;
}

.back-link {
    text-align: center;
    margin-top: 16px;
    flex-shrink: 0;
}

.back-link a {
    color: #66c0f4;
    text-decoration: none;
    font-size: 1.1em;
}

.back-link a:hover {
    text-decoration: underline;
}

.last-viewed {
    font-size: 0.9em;
    color: #8f98a0;
    line-height: 1.3;
    text-align: center; /* mirrors the now-centered header above it */
}

/* filled in client-side from data-iso, using the browser's own timezone */
.last-viewed .lv-date {
    display: block;
    color: #c7d5e0;
}

.last-viewed .lv-time {
    display: block;
    font-size: 0.85em;
    color: #8f98a0;
}

/* pairs with landing/stats nav buttons */
.nav-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(102, 192, 244, 0.08);
    border: 1px solid rgba(102, 192, 244, 0.4);
    border-radius: 6px;
    color: #66c0f4;
    text-decoration: none;
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer; /* also styles a real <button> now, not just <a> */
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.nav-button:hover {
    background: rgba(102, 192, 244, 0.18);
    border-color: #66c0f4;
    transform: translateY(-1px);
    text-decoration: none;
}

.nav-button svg {
    flex-shrink: 0;
}

.stats-corner-link {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 5;
}

/* game filter dropdown, above the stats table */
.stats-filter {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.stats-filter select {
    background: rgba(23, 26, 33, 0.8);
    color: #c7d5e0;
    border: 1px solid #2a475e;
    border-radius: 6px;
    padding: 6px 10px;
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
}

.stats-filter select:focus {
    outline: none;
    border-color: #66c0f4;
}

/* tighter table on phones so "Workshop Item" keeps enough room without scrolling */
@media (max-width: 480px) {
    .stats-container {
        padding: 12px;
    }

    /* must match "thead th", not just "th": the base rule above uses that
       selector too and has higher specificity */
    .stats-table thead th,
    .stats-table td {
        padding: 8px 6px;
        font-size: 0.85em;
    }

    .col-rank {
        width: 38px;
    }

    .col-views {
        width: 54px;
    }

    .col-lastviewed {
        width: 82px;
    }

    .last-viewed {
        font-size: 0.95em; /* relative to the already-reduced cell font-size above */
    }
}