:root {
    --gold: #f5c400;
    --gold-deep: #d99b00;
    --black: #050505;
    --ink: #111111;
    --charcoal: #1a2024;
    --steel: #6f767c;
    --mist: #f4f4f1;
    --white: #ffffff;
    --danger: #d73232;
    --success: #1f9d5a;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    font-family: Impact, Haettenschweiler, "Arial Black", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(245, 196, 0, 0.4), transparent 35%),
        linear-gradient(145deg, #101010 0%, #1d2327 54%, #060606 100%);
    color: var(--white);
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 22px 22px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), transparent 85%);
}

button,
input {
    font: inherit;
}

button,
a {
    touch-action: manipulation;
}

button {
    border: 0;
    cursor: pointer;
}

img {
    max-width: 100%;
    display: block;
}

.noscript {
    margin: 24px;
    padding: 18px;
    background: var(--danger);
    border-radius: var(--radius-md);
}

.app-shell {
    min-height: 100svh;
    width: min(100%, 520px);
    margin: 0 auto;
    position: relative;
    padding: 14px 14px calc(18px + var(--safe-bottom));
}

.screen {
    min-height: calc(100svh - 28px - var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: screenIn 0.28s ease both;
}

@keyframes screenIn {
    from { opacity: 0; transform: translateY(10px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.game-topbar {
    position: sticky;
    top: 8px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 2px solid rgba(245, 196, 0, 0.55);
    border-radius: 22px;
    background: rgba(5, 5, 5, 0.8);
    backdrop-filter: blur(14px);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.35);
}

.topbar-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
}

.topbar-brand strong {
    display: block;
    font-size: clamp(0.9rem, 4vw, 1.15rem);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.topbar-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 50%;
    background: var(--gold);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold);
}

.topbar-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(58px, 1fr));
    gap: 6px;
}

.topbar-stats div {
    padding: 7px 8px;
    min-width: 60px;
    text-align: center;
    border-radius: 14px;
    background: linear-gradient(180deg, var(--gold), var(--gold-deep));
    color: var(--black);
    box-shadow: inset 0 -2px rgba(0, 0, 0, 0.18);
}

.topbar-stats span {
    display: block;
    font-size: 1.05rem;
    line-height: 1;
}

.topbar-stats small {
    display: block;
    font-family: system-ui, sans-serif;
    font-size: 0.62rem;
    font-weight: 900;
    text-transform: uppercase;
}

.hero-card,
.game-card,
.result-card,
.leaderboard-card,
.admin-card {
    border: 2px solid rgba(245, 196, 0, 0.7);
    border-radius: var(--radius-xl);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
        rgba(8, 8, 8, 0.88);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.hero-card {
    margin-top: auto;
    margin-bottom: auto;
}

.hero-art {
    position: relative;
    min-height: 290px;
    padding: 22px 18px 0;
    background:
        radial-gradient(circle at 50% 18%, rgba(245, 196, 0, 0.24), transparent 38%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.2));
}

.brand-logo-main {
    width: min(92%, 400px);
    margin: 0 auto;
    filter: drop-shadow(0 14px 0 rgba(0, 0, 0, 0.3));
}

.hero-fan {
    width: min(82%, 360px);
    margin: 12px auto 0;
    transform-origin: 50% 42%;
    animation: fanFloat 3s ease-in-out infinite;
    filter: drop-shadow(0 22px 26px rgba(0, 0, 0, 0.48));
}

@keyframes fanFloat {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-7px) rotate(1deg); }
}

.hero-copy,
.card-copy {
    padding: 20px;
}

.hero-title,
.game-title,
.result-title {
    margin: 0;
    font-size: clamp(2.25rem, 12vw, 4.8rem);
    line-height: 0.88;
    letter-spacing: -0.04em;
    text-transform: uppercase;
}

.hero-title span,
.game-title span,
.result-title span {
    color: var(--gold);
    text-shadow: 3px 4px 0 var(--black);
}

.hero-copy p,
.card-copy p,
.result-card p,
.leaderboard-card p {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.82);
    line-height: 1.45;
}

.name-form {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.name-form label,
.admin-form label,
.clear-form label {
    display: grid;
    gap: 8px;
    font-family: system-ui, sans-serif;
    font-size: 0.82rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.76);
}

.name-form input,
.admin-form input,
.clear-form input {
    width: 100%;
    min-height: 54px;
    padding: 14px 16px;
    border: 2px solid rgba(245, 196, 0, 0.55);
    border-radius: 16px;
    outline: 0;
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
}

.name-form input:focus,
.admin-form input:focus,
.clear-form input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 5px rgba(245, 196, 0, 0.16);
}

.primary-btn,
.secondary-btn,
.danger-btn,
.tool-btn,
.part-btn,
.step-btn,
.choice-btn,
.wire-btn,
.speed-btn {
    min-height: 54px;
    padding: 13px 16px;
    border-radius: 16px;
    font-weight: 950;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    box-shadow: 0 9px 0 rgba(0, 0, 0, 0.4), 0 18px 35px rgba(0, 0, 0, 0.28);
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
}

.primary-btn {
    background: linear-gradient(180deg, #ffe45d, var(--gold) 52%, var(--gold-deep));
    color: var(--black);
}

.secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.12);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.danger-btn {
    background: linear-gradient(180deg, #ff6565, var(--danger));
    color: var(--white);
}

.primary-btn:active,
.secondary-btn:active,
.danger-btn:active,
.tool-btn:active,
.part-btn:active,
.step-btn:active,
.choice-btn:active,
.wire-btn:active,
.speed-btn:active {
    transform: translateY(5px);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.42), 0 10px 20px rgba(0, 0, 0, 0.2);
}

.full {
    width: 100%;
}

.link-row,
.admin-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.game-card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.game-card-inner {
    padding: 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stage-banner {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 14px;
    align-items: center;
    padding: 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.stage-avatar {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 50%;
    background: var(--gold);
}

.stage-banner h2,
.leaderboard-card h2,
.admin-card h1 {
    margin: 0;
    font-size: clamp(1.6rem, 8vw, 2.6rem);
    line-height: 0.92;
    letter-spacing: -0.03em;
    text-transform: uppercase;
}

.stage-banner p {
    margin: 4px 0 0;
    font-family: system-ui, sans-serif;
    font-weight: 750;
    color: rgba(255, 255, 255, 0.74);
}

.progress-track {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.12);
}

.progress-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--gold), #fff1a8);
    transition: width 0.22s ease;
}

.job-card {
    padding: 16px;
    border-radius: 22px;
    background:
        linear-gradient(160deg, rgba(245, 196, 0, 0.2), transparent 54%),
        rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(245, 196, 0, 0.36);
}

.job-card h3 {
    margin: 0 0 8px;
    font-size: 1.8rem;
    line-height: 1;
    color: var(--gold);
}

.job-card ul {
    margin: 12px 0 0;
    padding-left: 20px;
    font-family: system-ui, sans-serif;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.8);
}

.hud-message {
    min-height: 46px;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-family: system-ui, sans-serif;
    font-weight: 850;
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.part-btn,
.step-btn,
.tool-btn,
.choice-btn,
.wire-btn,
.speed-btn {
    position: relative;
    min-height: 76px;
    background: rgba(255, 255, 255, 0.11);
    color: var(--white);
    border: 2px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 7px 0 rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.part-btn .icon,
.tool-btn .icon,
.step-btn .icon,
.choice-btn .icon,
.wire-btn .icon,
.speed-btn .icon {
    display: block;
    font-size: 1.75rem;
    margin-bottom: 5px;
}

.part-btn.correct,
.step-btn.correct,
.wire-btn.correct,
.speed-btn.correct,
.tool-btn.correct,
.choice-btn.correct {
    background: linear-gradient(180deg, var(--gold), var(--gold-deep));
    color: var(--black);
    border-color: rgba(0, 0, 0, 0.2);
}

.part-btn.wrong,
.step-btn.wrong,
.wire-btn.wrong,
.tool-btn.wrong,
.choice-btn.wrong {
    animation: shake 0.28s ease;
    background: linear-gradient(180deg, #ff7070, var(--danger));
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.fan-workbench {
    min-height: 230px;
    display: grid;
    place-items: center;
    border-radius: 24px;
    background:
        radial-gradient(circle at center, rgba(245, 196, 0, 0.22), transparent 42%),
        rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.ceiling-fan-img {
    width: min(96%, 360px);
    max-height: 230px;
    object-fit: contain;
    filter: drop-shadow(0 24px 28px rgba(0, 0, 0, 0.6));
    transform-origin: 50% 46%;
}

.ceiling-fan-img.spin-slow { animation: fanSpin 2s linear infinite; }
.ceiling-fan-img.spin-fast { animation: fanSpin 0.55s linear infinite; }
.ceiling-fan-img.wobble { animation: fanWobble 0.18s ease-in-out infinite alternate; }

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

@keyframes fanWobble {
    from { transform: rotate(-2.5deg) translateX(-3px); }
    to { transform: rotate(2.5deg) translateX(3px); }
}

.safety-panel {
    padding: 18px;
    border-radius: 24px;
    background: linear-gradient(180deg, #222, #080808);
    border: 2px solid rgba(245, 196, 0, 0.5);
}

.breaker {
    height: 126px;
    width: 88px;
    margin: 0 auto 14px;
    padding: 14px;
    border-radius: 20px;
    background: #2a2a2a;
    box-shadow: inset 0 0 0 3px #000, 0 20px 35px rgba(0, 0, 0, 0.38);
}

.breaker-switch {
    height: 96px;
    border-radius: 16px;
    background: linear-gradient(180deg, #f84242 0 48%, #111 48% 100%);
    transition: background 0.2s ease;
}

.breaker.off .breaker-switch {
    background: linear-gradient(180deg, #111 0 48%, #22b56b 48% 100%);
}

.wire-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.wire-column {
    display: grid;
    gap: 10px;
}

.wire-btn {
    min-height: 64px;
}

.wire-btn.selected {
    outline: 4px solid rgba(245, 196, 0, 0.42);
    background: rgba(245, 196, 0, 0.18);
}

.wire-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    margin-right: 7px;
    border: 2px solid rgba(255, 255, 255, 0.52);
}

.wire-black { background: #050505; }
.wire-white { background: #ffffff; }
.wire-green { background: #18a957; }

.blade-build {
    position: relative;
    width: 230px;
    height: 230px;
    margin: 0 auto;
}

.blade-hub {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 76px;
    height: 76px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    z-index: 4;
    background: radial-gradient(circle, #333, #000);
    border: 8px solid var(--gold);
    box-shadow: 0 18px 30px rgba(0, 0, 0, 0.4);
}

.build-blade {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 108px;
    height: 28px;
    transform-origin: 0 50%;
    border-radius: 999px 24px 24px 999px;
    background: linear-gradient(90deg, #111, #2e3437);
    opacity: 0.15;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.build-blade.active {
    opacity: 1;
    background: linear-gradient(90deg, var(--gold), #262626 34%, #050505);
}

.balance-meter {
    display: grid;
    gap: 10px;
}

.balance-track {
    position: relative;
    height: 34px;
    border-radius: 999px;
    background: linear-gradient(90deg, #d73232, var(--gold), #1f9d5a, var(--gold), #d73232);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.3);
}

.balance-needle {
    position: absolute;
    top: -7px;
    left: 50%;
    width: 10px;
    height: 48px;
    border-radius: 999px;
    background: var(--white);
    transform: translateX(-50%);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.42);
    transition: left 0.16s ease;
}

.result-card,
.leaderboard-card {
    padding: 20px;
}

.score-hero {
    display: grid;
    place-items: center;
    min-height: 190px;
    border-radius: 24px;
    margin: 14px 0;
    background:
        radial-gradient(circle at center, rgba(245, 196, 0, 0.38), transparent 50%),
        rgba(255, 255, 255, 0.06);
}

.big-score {
    font-size: clamp(4rem, 22vw, 7rem);
    line-height: 0.85;
    color: var(--gold);
    text-shadow: 5px 6px 0 #000;
}

.stars {
    font-size: 2rem;
    letter-spacing: 0.08em;
    color: var(--gold);
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.result-grid div {
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.result-grid strong {
    display: block;
    font-size: 1.45rem;
}

.result-grid small {
    display: block;
    font-family: system-ui, sans-serif;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
}

.leaderboard-list {
    display: grid;
    gap: 9px;
    margin-top: 14px;
}

.leader-row {
    display: grid;
    grid-template-columns: 42px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.leader-row .place {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--gold);
    color: var(--black);
}

.leader-row strong,
.leader-row span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leader-row small {
    display: block;
    font-family: system-ui, sans-serif;
    color: rgba(255, 255, 255, 0.65);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + var(--safe-bottom));
    z-index: 50;
    width: min(calc(100% - 28px), 480px);
    padding: 14px 16px;
    transform: translateX(-50%) translateY(120px);
    border-radius: 18px;
    background: var(--gold);
    color: var(--black);
    font-family: system-ui, sans-serif;
    font-weight: 950;
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: 0.22s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.tiny-note {
    margin: 10px 0 0;
    font-family: system-ui, sans-serif;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.62);
}

/* Admin */
.admin-body {
    display: grid;
    place-items: start center;
    min-height: 100svh;
    padding: 20px;
}

.admin-shell {
    width: min(1100px, 100%);
}

.admin-card {
    padding: 18px;
}

.admin-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.admin-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 50%;
    background: var(--gold);
}

.admin-form,
.clear-form {
    display: grid;
    gap: 12px;
}

.clear-form {
    grid-template-columns: 1fr auto;
    align-items: end;
    margin: 16px 0;
    padding: 12px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
}

.notice {
    padding: 12px 14px;
    border-radius: 14px;
    font-family: system-ui, sans-serif;
    font-weight: 900;
}

.notice.success { background: rgba(31, 157, 90, 0.22); border: 1px solid rgba(31, 157, 90, 0.5); }
.notice.error { background: rgba(215, 50, 50, 0.22); border: 1px solid rgba(215, 50, 50, 0.5); }

.table-wrap {
    overflow: auto;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.13);
}

.score-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    font-family: system-ui, sans-serif;
    background: rgba(0, 0, 0, 0.28);
}

.score-table th,
.score-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
}

.score-table th {
    color: var(--gold);
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
}

.danger-link {
    color: #ffb5b5;
}

@media (max-width: 380px) {
    .grid.three {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .game-topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .clear-form {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
    }
}
