/* =========================================================================
   The portal shell: an illustrated outdoor scene with the app floating on it.

   The scene is drawn in CSS rather than shipped as artwork. That keeps the page
   self-contained — no image requests, nothing to go stale at another resolution
   — and it scales to any viewport without a set of exports. The trade is that
   it is stylised rather than painted, which suits a word game more than a
   detailed illustration would anyway.
   ========================================================================= */

:root {
    --sky-top: #4db8ff;
    --sky-bottom: #a8e3ff;
    --grass: #6fc44a;
    --grass-dark: #4da333;
    --path: #f0d9a8;

    --sidebar-w: 248px;
    --frame-radius: 28px;
}

/* ---------------------------------------------------------------- the scene */

.scene {
    position: fixed;
    inset: 0;
    z-index: -3;
    background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 58%, #cdeeb0 58%, var(--grass) 72%, var(--grass-dark) 100%);
    overflow: hidden;
}

/* Rolling hills. Two overlapping ellipses read as depth far more cheaply than
   any path drawing would. */
.scene .hill {
    position: absolute;
    border-radius: 50%;
    background: var(--grass);
}

.scene .hill-1 { left: -12%;  bottom: 8%;  width: 62%; height: 34%; background: #7ed158; }
.scene .hill-2 { right: -14%; bottom: 6%;  width: 58%; height: 30%; background: #6fc44a; }
.scene .hill-3 { left: 22%;   bottom: -6%; width: 70%; height: 26%; background: #5cb43c; }

/* Clouds drift across at different speeds, which is what sells parallax. */
.scene .cloud {
    position: absolute;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    filter: blur(0.4px);
    animation: cloud-drift linear infinite;
}

.scene .cloud::before,
.scene .cloud::after {
    content: "";
    position: absolute;
    background: inherit;
    border-radius: 50%;
}

.scene .cloud::before { width: 60%; height: 150%; left: 8%;  top: -62%; }
.scene .cloud::after  { width: 46%; height: 128%; right: 10%; top: -44%; }

.scene .c1 { width: 190px; height: 52px; top: 9%;  left: -22%; animation-duration: 96s; }
.scene .c2 { width: 130px; height: 40px; top: 21%; left: -18%; animation-duration: 132s; animation-delay: -30s; }
.scene .c3 { width: 240px; height: 62px; top: 33%; left: -30%; animation-duration: 168s; animation-delay: -70s; opacity: 0.75; }
.scene .c4 { width: 110px; height: 34px; top: 5%;  left: -14%; animation-duration: 118s; animation-delay: -50s; opacity: 0.85; }

@keyframes cloud-drift {
    from { transform: translateX(0); }
    to   { transform: translateX(150vw); }
}

/* Trees: a trunk with two stacked crowns. Enough to read as a tree at the size
   they appear, and cheap enough to place several. */
.scene .tree {
    position: absolute;
    bottom: 6%;
    width: 96px;
    height: 150px;
}

.scene .tree i {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 50%;
    background: #46a03a;
    box-shadow: inset -6px -8px 0 rgba(0, 0, 0, 0.09);
}

.scene .tree i:nth-child(1) { width: 96px; height: 80px; bottom: 52px; }
.scene .tree i:nth-child(2) { width: 72px; height: 62px; bottom: 92px; background: #56b544; }

.scene .tree b {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 18px;
    height: 62px;
    margin-left: -9px;
    border-radius: 6px;
    background: #9a6b3f;
}

.scene .t1 { left: 2%;  transform: scale(1.15); }
.scene .t2 { left: 11%; transform: scale(0.8); bottom: 12%; }
.scene .t3 { right: 3%; transform: scale(1.05); }
.scene .t4 { right: 12%; transform: scale(0.72); bottom: 13%; }

/* A winding path suggests somewhere to go, which is the whole mood. */
.scene .path {
    position: absolute;
    left: 50%;
    bottom: -8%;
    width: 46%;
    height: 26%;
    transform: translateX(-50%);
    background: var(--path);
    border-radius: 50% 50% 0 0;
    box-shadow: inset 0 6px 0 rgba(255, 255, 255, 0.35);
}

/* Sits above the drawn scene (-3) and below the app frame. */
.scene-photo {
    position: fixed;
    inset: 0;
    z-index: -2;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center bottom;
}

/* ---------------------------------------------------------------- app frame */

.app-frame {
    position: relative;
    display: flex;
    max-width: 1240px;
    /* Deliberately not full height: the scene has to be visible around the frame,
       otherwise it is an expensive backdrop nobody ever sees. */
    min-height: calc(100vh - 96px);
    margin: 48px auto;
    background: rgba(255, 255, 255, 0.96);
    border-radius: var(--frame-radius);
    box-shadow: 0 30px 80px rgba(16, 44, 70, 0.28), 0 2px 6px rgba(16, 44, 70, 0.12);
    overflow: hidden;
}

/* ---------------------------------------------------------------- sidebar */

.sidebar {
    width: var(--sidebar-w);
    flex: none;
    /* Sticky, not static: a rail that scrolls away with the page stops being
       navigation the moment the content gets long. */
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: calc(100vh - 96px);
    overflow-y: auto;
    padding: var(--space-xl) var(--space-lg);
    border-right: 1px solid var(--divider);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    background: #fcfcfd;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--coral);
    text-shadow: 0 2px 0 rgba(255, 84, 54, 0.18);
}

.sidebar .brand .mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(140deg, #ff7a5e, var(--coral));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 12px var(--coral-glow);
}

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 14px;
    color: var(--ink);
    font-weight: 600;
    font-size: 15px;
    transition: background 0.18s, color 0.18s, transform 0.18s var(--ease-out);
}

.nav a:hover { background: #f4f6f8; transform: translateX(2px); }

.nav a.active { background: var(--coral-wash); color: var(--coral); }

.nav a .ico {
    width: 24px;
    text-align: center;
    font-size: 17px;
    flex: none;
}

/* The player card sits at the bottom of the rail, so identity is always visible
   without competing with navigation. */
.me { margin-top: auto; }

.me .row { gap: 10px; }
.me .name { font-weight: 700; font-size: 15px; }
.me .title { font-size: 12px; color: var(--ink-muted); }

.level-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

.level-badge {
    width: 38px;
    height: 38px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(140deg, #ff7a5e, var(--coral));
    /* A hexagon reads as a game rank in a way a circle does not. */
    clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

.xp-track {
    height: 7px;
    border-radius: 999px;
    background: var(--divider);
    overflow: hidden;
}

.xp-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #ffb057, var(--coral));
    transition: width 0.6s var(--ease-out);
}

/* ---------------------------------------------------------------- content */

.content {
    flex: 1;
    min-width: 0;
    padding: var(--space-xl) var(--space-xxl) 48px;
    /* White, not the old grey wash: the frame already separates the app from the
       scene, so a second tone inside it only muddied the cards. */
    background: #fff;
    overflow-x: hidden;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.page-head h1 { font-size: 30px; }
.page-head .sub { color: var(--ink-muted); margin-top: 2px; }

/* ---------------------------------------------------------------- stat cards */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.stat {
    background: #fff;
    border: 1px solid var(--divider);
    border-radius: 18px;
    padding: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    box-shadow: var(--lift-1);
    transition: transform 0.25s var(--ease-spring), box-shadow 0.25s var(--ease-out);
    animation: rise 0.5s var(--ease-out) backwards;
    animation-delay: calc(var(--i, 0) * 70ms);
}

.stat:hover { transform: translateY(-4px); box-shadow: var(--lift-2); }

.stat .ico {
    width: 48px;
    height: 48px;
    flex: none;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

/* One hue per statistic, so the row reads as four things rather than a block. */
.stat.red   .ico { background: #ffe3de; }
.stat.green .ico { background: #dcf6e3; }
.stat.gold  .ico { background: #fff2d1; }
.stat.blue  .ico { background: #dfeeff; }

.stat .label { font-size: 12px; color: var(--ink-muted); }
.stat .value { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .note { font-size: 11px; color: var(--ink-muted); }

/* ---------------------------------------------------------------- panels */

.panel-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    align-items: start;
}

.panel {
    background: #fff;
    border: 1px solid var(--divider);
    border-radius: 20px;
    box-shadow: var(--lift-1);
    overflow: hidden;
    animation: rise 0.5s var(--ease-out) backwards;
    animation-delay: calc(var(--i, 0) * 70ms);
}

.panel > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-lg) var(--space-sm);
}

.panel > header h3 { font-size: 17px; }
.panel .body { padding: var(--space-sm) var(--space-lg) var(--space-lg); }

.list-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 10px;
    border-radius: 14px;
    transition: background 0.2s;
}

.list-row:hover { background: #f7f8fa; }
.list-row .grow { min-width: 0; }
.list-row .title { font-weight: 700; font-size: 15px; }
.list-row .meta { font-size: 12px; color: var(--ink-muted); }

.room-icon {
    width: 46px;
    height: 46px;
    flex: none;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: #fff;
}

/* Medals for the top three, plain numerals after — the podium colours are
   already the language the final results screen uses. */
.medal-badge {
    width: 26px;
    height: 26px;
    flex: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
}

.medal-1 { background: linear-gradient(140deg, #ffd76e, #e8a900); }
.medal-2 { background: linear-gradient(140deg, #d9dde2, #a5abb2); }
.medal-3 { background: linear-gradient(140deg, #e5b183, #bd7f47); }
.medal-n { background: var(--divider); color: var(--ink-muted); }

.empty-note { text-align: center; color: var(--ink-muted); font-size: 13px; padding: var(--space-lg) 0; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px) {
    .app-frame { margin: 0; border-radius: 0; min-height: 100vh; flex-direction: column; }
    .sidebar {
        width: auto;
        border-right: 0;
        border-bottom: 1px solid var(--divider);
        flex-direction: row;
        align-items: center;
        gap: var(--space-md);
        overflow-x: auto;
        padding: var(--space-md);
    }
    .nav { flex-direction: row; }
    .nav a span:not(.ico) { display: none; }
    .me { margin-top: 0; margin-left: auto; }
    .me .level-row, .me .title { display: none; }
    .content { padding: var(--space-lg); }
    .panel-2 { grid-template-columns: 1fr; }
    .scene { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .scene .cloud { animation: none; }
}

/* ---------------------------------------------------------------- circuit */

.circuit-banner {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(20, 24, 30, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
}

/* The framework toggles these classes; it never sets inline display. */
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected { display: flex; }

.circuit-card {
    background: #fff;
    border-radius: var(--radius-card-lg);
    padding: var(--space-xl) var(--space-xxl);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    box-shadow: var(--lift-3);
}

.spinner {
    width: 30px;
    height: 30px;
    margin-bottom: 6px;
    border-radius: 50%;
    border: 3px solid var(--divider);
    border-top-color: var(--coral);
    animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
