/* ============================================================
   Friendometer — main.css
   Dark-themed NES.css integration. Mobile-first, max-width 480px.
   NES.css provides the pixel-art component base; we dark-theme it.
   ============================================================ */

/* ---------- CSS Variables (dark NES palette) ---------- */
:root {
    --bg:            #212529;   /* NES.css dark */
    --bg-soft:       #2a2f35;
    --card-bg:       #343a40;
    --card-border:   #495057;
    --primary:       #209cee;   /* NES.css blue */
    --primary-dark:  #108de0;
    --primary-light: #6bbfff;
    --success:       #92cc41;   /* NES.css green */
    --success-dark:  #76c442;
    --error:         #e76e55;   /* NES.css red */
    --error-dark:    #ce372b;
    --warning:       #f7d51d;   /* NES.css yellow */
    --warning-dark:  #d9a400;
    --text:          #ffffff;
    --text-dim:      #adb5bd;
    --text-faint:    #6c757d;
    --transition:    0.1s step-end;
}

/* ---------- CRT Scanline overlay ---------- */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.06) 2px,
        rgba(0,0,0,0.06) 4px
    );
}

/* ---------- Base ---------- */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.8;
    overflow-x: hidden;
    font-size: 0.625rem;
}

/* ---------- Layout ---------- */
#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 1.25rem 0.75rem 3rem;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    z-index: 1;
}

/* ---------- Screens ---------- */
.screen { display: none; animation: fadeIn 0.2s step-end; }
.screen.active { display: block; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Typography ---------- */
h1, h2, h3 { line-height: 1.4; font-size: 0.75rem; text-transform: uppercase; }
.screen-title { font-size: 0.7rem; color: var(--warning); }

/* ============================================================
   NES.CSS DARK OVERRIDES
   ============================================================ */

/* --- Pixel border: use light SVG for dark backgrounds --- */
.nes-btn,
.nes-input,
.nes-progress,
.nes-textarea,
.nes-select select,
.nes-table.is-bordered,
.nes-table.is-dark.is-bordered {
    border-image-source: url('data:image/svg+xml;utf8,%3Csvg%20version%3D%221.1%22%20width%3D%225%22%20height%3D%225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M2%201%20h1%20v1%20h-1%20z%20M1%202%20h1%20v1%20h-1%20z%20M3%202%20h1%20v1%20h-1%20z%20M2%203%20h1%20v1%20h-1%20z%22%20fill%3D%22rgb%28173%2C181%2C189%29%22%2F%3E%3C%2Fsvg%3E');
}

/* --- NES Containers (dark theme) --- */
/* Containers use solid borders (not pixel-art), matching the NES.css demo.
   is-dark gives us white border + ::after outline. We override bg for depth. */
.nes-container.is-dark {
    background: var(--card-bg);
    color: var(--text);
}
/* Make the ::after outline visible on dark pages (default #212529 blends in) */
.nes-container.is-dark::after {
    background-color: var(--card-border);
}
.nes-container.is-dark.with-title > .title {
    background: var(--card-bg);
    color: var(--text);
}

/* --- NES Buttons — dark variants --- */
.nes-btn {
    font-family: 'Press Start 2P', monospace;
    border-image-repeat: stretch;
    color: var(--text);
    background: var(--card-bg);
}
.nes-btn::after {
    box-shadow: inset -4px -4px var(--card-border);
}
.nes-btn:hover {
    color: var(--text);
    background: var(--bg-soft);
}
.nes-btn:hover::after {
    box-shadow: inset -6px -6px var(--card-border);
}

.nes-btn.is-primary {
    color: #fff;
    background: var(--primary);
}
.nes-btn.is-primary::after {
    box-shadow: inset -4px -4px var(--primary-dark);
}
.nes-btn.is-primary:hover {
    background: var(--primary-dark);
}

.nes-btn.is-success {
    color: #212529;
    background: var(--success);
}
.nes-btn.is-success::after {
    box-shadow: inset -4px -4px var(--success-dark);
}
.nes-btn.is-success:hover {
    background: var(--success-dark);
}

.nes-btn.is-error {
    color: #fff;
    background: var(--error);
}
.nes-btn.is-error::after {
    box-shadow: inset -4px -4px var(--error-dark);
}
.nes-btn.is-error:hover {
    background: var(--error-dark);
}

.nes-btn.is-warning {
    color: #212529;
    background: var(--warning);
}
.nes-btn.is-warning::after {
    box-shadow: inset -4px -4px var(--warning-dark);
}
.nes-btn.is-warning:hover {
    background: var(--warning-dark);
}

.nes-btn:disabled, .nes-btn.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- NES Inputs --- */
.nes-input, .nes-textarea {
    font-family: 'Press Start 2P', monospace;
    background: var(--bg);
    color: var(--text);
    border-image-repeat: stretch;
}
.nes-input::placeholder, .nes-textarea::placeholder {
    color: var(--text-faint);
}
.nes-input:focus, .nes-textarea:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary);
    border-color: var(--primary);
}

/* --- NES Badges --- */
.nes-badge {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.4rem;
}
.nes-badge span.is-dark {
    background: var(--card-bg);
    color: var(--text-dim);
}
.nes-badge span.is-primary {
    background: var(--primary);
}
.nes-badge span.is-success {
    background: var(--success);
    color: #212529;
}
.nes-badge span.is-warning {
    background: var(--warning);
    color: #212529;
}
.nes-badge span.is-error {
    background: var(--error);
}

/* Badge inside a full-width button: float right */
.nes-btn .nes-badge {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}
.nes-btn {
    position: relative;
}
.nes-progress {
    height: 16px;
    border-image-repeat: stretch;
}
.nes-progress::-webkit-progress-bar {
    background: var(--bg);
}
.nes-progress::-webkit-progress-value {
    background: var(--primary);
}
.nes-progress::-moz-progress-bar {
    background: var(--primary);
}
.nes-progress.is-primary::-webkit-progress-value { background: var(--primary); }
.nes-progress.is-primary::-moz-progress-bar { background: var(--primary); }
.nes-progress.is-success::-webkit-progress-value { background: var(--success); }
.nes-progress.is-success::-moz-progress-bar { background: var(--success); }
.nes-progress.is-error::-webkit-progress-value { background: var(--error); }
.nes-progress.is-error::-moz-progress-bar { background: var(--error); }

/* --- NES Icons — force white for dark bg --- */
.nes-icon.is-large { transform: scale(1.5); }

/* --- NES Balloons — dark bg --- */
.nes-balloon {
    background: var(--card-bg);
    color: var(--text);
}
.nes-balloon::before {
    background: var(--card-bg);
}

/* ============================================================
   CUSTOM COMPONENTS (not covered by NES.css)
   ============================================================ */

/* --- Buttons — full-width + icon alignment --- */
.nes-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    width: 100%;
    min-height: 48px;
    padding: 0.5rem 0.75rem;
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.nes-btn:active:not(:disabled) {
    transform: translate(2px, 2px);
}
.nes-btn:active:not(:disabled)::after {
    box-shadow: none !important;
}

.btn-icon {
    display: inline-block;
    font-size: 0.75rem;
    line-height: 1;
    vertical-align: middle;
    position: relative;
    top: -1px;
}
.btn-sm {
    width: auto;
    min-height: 40px;
    padding: 0.375rem 0.625rem;
    font-size: 0.5rem;
}
.btn-row {
    display: flex;
    gap: 0.5rem;
}
.btn-row .nes-btn { flex: 1; }

/* --- Back button --- */
.back-btn {
    flex-shrink: 0;
    width: 42px !important;
    height: 42px;
    min-height: 42px !important;
    font-size: 0.7rem !important;
}

/* --- Screen header --- */
.screen-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* --- Form fields --- */
.field { margin-bottom: 0.75rem; }
.nes-input, .nes-textarea, select {
    width: 100%;
    min-height: 48px;
    padding: 0.5rem 0.75rem;
    font-size: 0.55rem;
}
label {
    display: block;
    font-size: 0.5rem;
    font-weight: 400;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

/* ---------- Home ---------- */
.home-logo {
    display: block;
    max-width: 100%;
    max-height: 30vh;
    width: auto;
    height: auto;
    margin: 0 auto;
    padding: 1rem 0.5rem 0.5rem;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.home-tagline {
    text-align: center;
    color: var(--warning);
    font-size: 0.5rem;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.home-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.home-footer {
    text-align: center;
    color: var(--text-faint);
    font-size: 0.4rem;
    margin-top: 2rem;
}
.home-footer .nes-icon {
    transform: scale(0.45);
    transform-origin: center center;
    margin-right: 4px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

/* ---------- Game code display ---------- */
.code-display {
    text-align: center;
    margin: 1.5rem 0;
}
.code-display .code {
    font-size: 1.2rem;
    font-weight: 400;
    letter-spacing: 0.5em;
    color: var(--warning);
    text-shadow: 2px 2px 0 #000, 0 0 10px rgba(247,213,29,0.3);
    padding: 0.75rem;
    background: var(--bg);
    border: 4px dashed var(--card-border);
    border-radius: 0;
    display: inline-block;
    padding-left: calc(0.75rem + 0.5em);
    font-family: 'Press Start 2P', monospace;
}

/* ---------- Player list ---------- */
.player-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.player-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-soft);
    border: 4px solid var(--card-border);
    border-radius: 0;
    cursor: pointer;
}
.player-item:hover {
    border-color: var(--primary);
    background: var(--card-bg);
}
.player-item.claimed {
    opacity: 0.5;
    cursor: default;
}
.player-item.claimed:hover {
    border-color: var(--card-border);
    background: var(--bg-soft);
}
.player-item.me { border-color: var(--success); box-shadow: 0 0 4px var(--success); }

/* ---------- Avatars ---------- */
.avatar {
    width: 48px;
    height: 48px;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-family: 'Press Start 2P', monospace;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--primary);
    border: 4px solid var(--primary-light);
    image-rendering: pixelated;
    object-fit: cover;
}
.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: pixelated;
}
.avatar-lg { width: 80px; height: 80px; font-size: 1.1rem; }
.avatar-sm { width: 32px; height: 32px; font-size: 0.5rem; }
.player-name {
    font-size: 0.5rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.player-status {
    font-size: 0.4rem;
    color: var(--success);
    white-space: nowrap;
}
.player-status.pending { color: var(--text-faint); }

/* ---------- Messages ---------- */
.msg {
    padding: 0.5rem 0.75rem;
    border-radius: 0;
    font-size: 0.45rem;
    margin-bottom: 0.75rem;
    text-align: center;
    text-transform: uppercase;
}
.msg-error { background: rgba(231,110,85,0.15); border: 4px solid rgba(231,110,85,0.5); color: #f0a090; }
.msg-success { background: rgba(146,204,65,0.15); border: 4px solid rgba(146,204,65,0.5); color: #aadd66; }
.msg-info { background: rgba(32,156,238,0.15); border: 4px solid rgba(32,156,238,0.5); color: var(--primary-light); }

/* ---------- Spinner ---------- */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--card-border);
    border-top-color: var(--primary-light);
    border-radius: 0;
    animation: spin 0.6s steps(8) infinite;
    image-rendering: pixelated;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap {
    text-align: center;
    padding: 2rem;
    color: var(--text-dim);
    font-size: 0.45rem;
}
.loading-wrap .spinner { margin-bottom: 0.5rem; }

/* ---------- Toasts ---------- */
#toast-container {
    position: fixed;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    pointer-events: none;
    width: 100%;
    max-width: 440px;
    padding: 0 0.75rem;
}
.toast {
    padding: 0.5rem 0.75rem;
    border-radius: 0;
    font-size: 0.45rem;
    font-family: 'Press Start 2P', monospace;
    text-align: center;
    animation: toastIn 0.15s step-end;
    pointer-events: auto;
    text-transform: uppercase;
    border: 4px solid;
}
.toast-error { background: #440000; color: var(--error); border-color: var(--error); }
.toast-success { background: #003300; color: var(--success); border-color: var(--success); }
.toast-info { background: #003344; color: var(--primary-light); border-color: var(--primary); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.toast.hide { animation: toastOut 0.15s step-end forwards; }
@keyframes toastOut {
    to { opacity: 0; transform: translateY(-10px); }
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
.game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--card-bg);
    border: 4px solid var(--card-border);
    border-radius: 0;
    margin-bottom: 1rem;
    font-size: 0.5rem;
}
.game-score { color: var(--warning); }
.game-hints { color: var(--primary-light); }

.question-card { text-align: center; margin-bottom: 1rem; }
.question-about {
    color: var(--text-dim);
    font-size: 0.45rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}
.question-about-name { color: var(--success); }
.question-photo {
    margin: 0 auto 0.75rem;
    width: 96px !important;
    height: 96px !important;
    border-radius: 0;
    border: 3px solid var(--primary);
    font-size: 1.5rem;
    image-rendering: pixelated;
}
.question-text {
    font-size: 0.6rem;
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

/* Answer result */
.answer-result {
    padding: 0.75rem;
    border-radius: 0;
    text-align: center;
    margin-bottom: 0.75rem;
    animation: fadeIn 0.15s step-end;
    font-size: 0.45rem;
    text-transform: uppercase;
}
.answer-correct { background: rgba(146,204,65,0.12); border: 4px solid var(--success); color: #aadd66; }
.answer-wrong { background: rgba(231,110,85,0.12); border: 4px solid var(--error); color: #f0a090; }
.answer-wrong .reveal { margin-top: 0.5rem; font-size: 0.4rem; color: var(--text-dim); }
.answer-wrong .reveal b { color: var(--text); }

/* Hints */
.hints-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.hint-btn {
    flex: 1;
    min-height: 40px;
    padding: 0.375rem;
    font-size: 0.45rem;
    font-family: 'Press Start 2P', monospace;
    color: var(--text);
    background: var(--card-bg);
    border: 4px solid var(--card-border);
    border-radius: 0;
    cursor: pointer;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
}
.hint-btn:hover:not(:disabled) { border-color: var(--primary); transform: translate(1px, 1px); }
.hint-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.hint-display {
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 4px dashed var(--card-border);
    border-radius: 0;
    font-size: 0.45rem;
    color: var(--primary-light);
    margin-bottom: 0.5rem;
    text-align: center;
    text-transform: uppercase;
}

/* Progress */
.progress-wrap { margin-top: 1rem; }
.progress-label {
    font-size: 0.4rem;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
    text-align: center;
}

/* Game complete */
.game-complete { text-align: center; padding: 2rem 0.75rem; }
.game-complete h2 { font-size: 0.65rem; margin-bottom: 1rem; color: var(--warning); text-transform: uppercase; }

/* ============================================================
   RANKING
   ============================================================ */
.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0.25rem;
    margin: 1.5rem 0;
}
.podium-spot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
}
.podium-spot .medal { font-size: 1.5rem; }
.podium-spot .avatar {
    border-width: 3px;
    border-style: solid;
    image-rendering: pixelated;
}
.podium-spot.pos-1 .avatar { border-color: var(--warning); width: 72px; height: 72px; font-size: 1.2rem; }
.podium-spot.pos-2 .avatar { border-color: var(--text-dim); width: 56px; height: 56px; font-size: 0.9rem; }
.podium-spot.pos-3 .avatar { border-color: #cd7f32; width: 48px; height: 48px; font-size: 0.75rem; }
.podium-spot.pos-1 { order: 2; }
.podium-spot.pos-2 { order: 1; }
.podium-spot.pos-3 { order: 3; }
.podium-spot .name { font-size: 0.4rem; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-spot .score { font-size: 0.45rem; color: var(--warning); }
.podium-bar {
    width: 100%;
    border-radius: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.25rem;
    color: rgba(255,255,255,0.12);
    font-size: 1.2rem;
    font-family: 'Press Start 2P', monospace;
}
.podium-bar.pos-1 { height: 60px; background: rgba(247,213,29,0.25); border: 4px solid var(--warning); }
.podium-bar.pos-2 { height: 44px; background: rgba(173,181,189,0.18); border: 4px solid var(--text-dim); }
.podium-bar.pos-3 { height: 32px; background: rgba(205,127,50,0.18); border: 4px solid #cd7f32; }
.ranking-rest { margin-top: 1rem; }
.ranking-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-soft);
    border: 4px solid var(--card-border);
    border-radius: 0;
    margin-bottom: 0.25rem;
    font-size: 0.45rem;
}
.ranking-row.me { border-color: var(--success); box-shadow: 0 0 4px rgba(146,204,65,0.3); }
.ranking-row .position { width: 28px; text-align: center; color: var(--text-dim); }
.ranking-row .score { margin-left: auto; color: var(--warning); }
.my-position-banner {
    text-align: center;
    padding: 0.75rem;
    background: var(--card-bg);
    border: 4px solid var(--primary);
    border-radius: 0;
    margin: 1rem 0;
    font-size: 0.45rem;
}
.my-position-banner .num { font-size: 1.2rem; color: var(--warning); }

/* ============================================================
   PROFILE / PERSONAL QUESTIONS
   ============================================================ */
.profile-question { margin-bottom: 0.75rem; }
.profile-question .q-text { margin-bottom: 0.25rem; font-size: 0.45rem; }
.my-question-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-soft);
    border: 4px solid var(--card-border);
    border-radius: 0;
    margin-bottom: 0.25rem;
}
.my-question-item .q-info { flex: 1; min-width: 0; }
.my-question-item .q-text-sm { font-size: 0.45rem; margin-bottom: 0.25rem; }
.my-question-item .q-stats { font-size: 0.4rem; color: var(--text-dim); }
.delete-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    min-height: 32px;
    background: transparent;
    border: 4px solid var(--card-border);
    border-radius: 0;
    color: var(--error);
    cursor: pointer;
    font-size: 0.6rem;
    font-family: 'Press Start 2P', monospace;
}
.delete-btn:hover { background: rgba(231,110,85,0.15); }
.delete-btn:active { transform: translate(1px, 1px); }

.section { margin-top: 1rem; }
.section-title {
    font-size: 0.55rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    text-transform: uppercase;
}

/* ---------- Utilities ---------- */
.text-center { text-align: center; }
.text-dim { color: var(--text-dim); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.hidden { display: none !important; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.center { display: flex; align-items: center; justify-content: center; }
.flex-col { flex-direction: column; }

/* Flashes */
.flash-correct { animation: flashGreen 0.4s steps(2); }
.flash-wrong { animation: flashRed 0.4s steps(2); }
@keyframes flashGreen {
    0%, 100% { background: var(--card-bg); }
    50% { background: rgba(146,204,65,0.2); }
}
@keyframes flashRed {
    0%, 100% { background: var(--card-bg); }
    50% { background: rgba(231,110,85,0.2); }
}

/* Photo preview */
.photo-preview {
    width: 80px;
    height: 80px;
    border-radius: 0;
    object-fit: cover;
    border: 3px solid var(--primary);
    margin: 0 auto 0.5rem;
    display: block;
    image-rendering: pixelated;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2rem 0.75rem;
    color: var(--text-dim);
    font-size: 0.45rem;
}
.empty-state .nes-icon { margin: 0 auto 0.5rem; display: block; }
