/* Relay World — revived. One stylesheet, mobile-first, OG pixel flavor. */
:root {
    --green-dark: #0f380f;
    --green: #306850;
    --green-light: #8bac0f;
    --gold: #d9c86a;
    --panel: rgba(15, 30, 15, 0.92);
    --font-pixel: 'Press Start 2P', monospace;
    --font-body: system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: var(--font-body);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.hide { display: none !important; }

#world-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#label-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 5;
}

/* ---- projected labels ---- */
.name-label {
    position: absolute;
    left: 0; top: 0;
    display: none;
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    padding: 3px 6px;
    border-radius: 3px;
    white-space: nowrap;
    align-items: center;
    gap: 4px;
}
.name-label img {
    width: 16px; height: 16px;
    border-radius: 2px;
    object-fit: cover;
    vertical-align: -4px;
    margin-right: 4px;
    image-rendering: pixelated;
}
.name-label.player { color: #7ff7ff; border: 1px solid #2aa; }
.name-label.follow { color: var(--gold); border: 1px solid var(--gold); }
.sign-label {
    position: absolute;
    left: 0; top: 0;
    display: none;
    font-family: var(--font-pixel);
    font-size: 11px;
    color: var(--gold);
    text-shadow: 2px 2px 0 #000;
    white-space: nowrap;
}
.speech-bubble {
    position: absolute;
    left: 0; top: 0;
    display: none;
    max-width: 190px;
    font-size: 11px;
    line-height: 1.35;
    color: #1a1a1a;
    background: #fffbe8;
    border: 2px solid #1a1a1a;
    border-radius: 8px;
    padding: 6px 8px;
    overflow-wrap: break-word;
}
.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px; left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: #1a1a1a;
}

/* ---- login ---- */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f380f 0%, #071807 100%);
    overflow-y: auto;
    padding: 16px;
}
#login-panel {
    position: relative;
    width: min(440px, 94vw);
    background: var(--panel);
    border: 4px solid var(--green-light);
    padding: 28px 22px;
    text-align: center;
    color: #d8e8c8;
}
.pixel-corner { position: absolute; width: 10px; height: 10px; background: var(--gold); }
.corner-tl { top: -7px; left: -7px; }
.corner-tr { top: -7px; right: -7px; }
.corner-bl { bottom: -7px; left: -7px; }
.corner-br { bottom: -7px; right: -7px; }
#login-panel h1 {
    font-family: var(--font-pixel);
    font-size: clamp(18px, 5.5vw, 26px);
    color: var(--green-light);
    margin: 14px 0 12px;
    text-shadow: 3px 3px 0 #000;
}
.tagline { font-family: var(--font-pixel); font-size: 8px; color: var(--gold); margin-bottom: 12px; line-height: 1.7; }
.sub { font-size: 13px; line-height: 1.5; margin-bottom: 18px; color: #b8d0a8; }
.triforce-container { display: flex; justify-content: center; gap: 0; height: 26px; }
.triforce {
    width: 0; height: 0;
    border-left: 13px solid transparent;
    border-right: 13px solid transparent;
    border-bottom: 22px solid var(--gold);
    animation: pulse 2s infinite;
}
.triforce.top { position: relative; top: -0px; }
.triforce.left, .triforce.right { margin-top: 0; }
@keyframes pulse { 50% { opacity: 0.6; } }

#login-options { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.primary-button, .secondary-button {
    font-family: var(--font-pixel);
    font-size: 12px;
    padding: 14px 12px;
    cursor: pointer;
    border: 3px solid #000;
    box-shadow: 3px 3px 0 #000;
    transition: transform 0.05s;
}
.primary-button { background: var(--green-light); color: var(--green-dark); }
.secondary-button { background: #444; color: #eee; }
.primary-button:active, .secondary-button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
#login-status { min-height: 18px; font-size: 12px; color: var(--gold); margin-bottom: 10px; }
.instructions { text-align: left; font-size: 11px; color: #9ab88a; line-height: 1.8; border-top: 2px solid #2a4a2a; padding-top: 10px; }

/* ---- HUD ---- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#top-bar {
    position: absolute;
    top: env(safe-area-inset-top, 8px);
    left: 8px; right: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
}
#relay-pill, #online-pill, .pill-button {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #d8e8c8;
    background: var(--panel);
    border: 2px solid var(--green-light);
    padding: 7px 9px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#relay-pill { flex-shrink: 1; min-width: 0; cursor: pointer; }
#online-pill { margin-left: auto; }
.pill-button { cursor: pointer; font-size: 12px; padding: 5px 8px; }

#interact-prompt {
    position: absolute;
    bottom: 34%;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--green-dark);
    background: var(--gold);
    border: 3px solid #000;
    padding: 10px 14px;
    white-space: nowrap;
    animation: pulse 1.2s infinite;
}

#chat-box {
    position: absolute;
    left: 8px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
    width: min(340px, 62vw);
}
#chat-log {
    max-height: 26vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 3px;
    margin-bottom: 6px;
    mask-image: linear-gradient(to bottom, transparent, black 18%);
}
.chat-row {
    font-size: 12px;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    padding: 4px 8px;
    width: fit-content;
    max-width: 100%;
    overflow-wrap: break-word;
}
.chat-row .chat-name { color: var(--green-light); font-weight: 700; }
.chat-row.self .chat-name { color: var(--gold); }
#chat-input-row input {
    width: 100%;
    font-family: var(--font-body);
    font-size: 16px; /* prevents iOS zoom */
    padding: 10px;
    background: var(--panel);
    color: #fff;
    border: 2px solid var(--green-light);
    border-radius: 4px;
    outline: none;
}

/* mobile controls */
#joystick {
    position: absolute;
    left: 18px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
    width: 110px; height: 110px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.25);
    border: 2px solid rgba(139, 172, 15, 0.5);
    display: none;
}
#joystick-knob {
    position: absolute;
    left: 50%; top: 50%;
    width: 46px; height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 50%;
    background: rgba(139, 172, 15, 0.65);
    border: 2px solid #000;
}
#action-button {
    position: absolute;
    right: 22px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 110px);
    width: 66px; height: 66px;
    border-radius: 50%;
    font-family: var(--font-pixel);
    font-size: 18px;
    background: var(--gold);
    color: var(--green-dark);
    border: 3px solid #000;
    box-shadow: 3px 3px 0 #000;
    cursor: pointer;
}
#fire-button {
    position: absolute;
    right: 100px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 110px);
    width: 66px; height: 66px;
    border-radius: 50%;
    font-size: 26px;
    background: #c0392b;
    border: 3px solid #000;
    box-shadow: 3px 3px 0 #000;
    cursor: pointer;
}
#fire-button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
#hp-pill {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #ff9b9b;
    background: var(--panel);
    border: 2px solid #a33;
    padding: 7px 9px;
    border-radius: 4px;
    white-space: nowrap;
}
#weapon-pill {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--gold);
    background: var(--panel);
    border: 2px solid var(--gold);
    padding: 7px 9px;
    border-radius: 4px;
    white-space: nowrap;
}
#round-bar {
    position: absolute;
    top: calc(env(safe-area-inset-top, 8px) + 40px);
    right: 8px;
    display: flex;
    gap: 8px;
}
#block-pill, #kills-pill {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #f7c873;
    background: var(--panel);
    border: 2px solid #b8862e;
    padding: 7px 9px;
    border-radius: 4px;
    white-space: nowrap;
    cursor: pointer;
}
#kills-pill { color: #ff9b9b; border-color: #a33; }

#kill-feed {
    position: absolute;
    top: calc(env(safe-area-inset-top, 8px) + 76px);
    right: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    pointer-events: none;
}
.kill-row {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    border-right: 3px solid #c0392b;
    padding: 5px 8px;
    border-radius: 3px;
    white-space: nowrap;
    max-width: 78vw;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.5s;
}
.kill-row.fade { opacity: 0; }

#round-splash {
    position: fixed;
    top: 24%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    text-align: center;
    pointer-events: none;
    animation: splash-in 0.35s ease-out;
}
@keyframes splash-in {
    from { transform: translateX(-50%) scale(1.6); opacity: 0; }
    to { transform: translateX(-50%) scale(1); opacity: 1; }
}
#splash-block {
    font-family: var(--font-pixel);
    font-size: clamp(16px, 4.5vw, 28px);
    color: var(--gold);
    text-shadow: 3px 3px 0 #000;
    margin-bottom: 12px;
}
#splash-winner {
    font-family: var(--font-pixel);
    font-size: clamp(11px, 3vw, 18px);
    color: #fff;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 10px;
}
#splash-sub {
    font-family: var(--font-pixel);
    font-size: 9px;
    color: #b8d0a8;
    text-shadow: 2px 2px 0 #000;
}

#score-overlay {
    position: fixed;
    inset: 0;
    z-index: 38;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
}
#score-panel {
    width: min(420px, 94vw);
    max-height: 80vh;
    overflow-y: auto;
    background: var(--panel);
    border: 3px solid var(--gold);
    padding: 18px 16px;
    color: #d8e8c8;
}
#score-panel h3 {
    font-family: var(--font-pixel);
    font-size: 13px;
    color: var(--gold);
    text-align: center;
    margin-bottom: 8px;
}
#score-block {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #f7c873;
    text-align: center;
    margin-bottom: 14px;
}
.score-row {
    display: grid;
    grid-template-columns: 28px 1fr 70px;
    gap: 8px;
    align-items: center;
    font-family: var(--font-pixel);
    font-size: 9px;
    padding: 8px 6px;
    border-bottom: 1px solid rgba(139, 172, 15, 0.25);
}
.score-row .score-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row.me { color: var(--gold); background: rgba(217, 200, 106, 0.08); }
.score-head { color: #8a9a7a; font-size: 7px; border-bottom: 2px solid var(--green-light); }
.score-foot { font-size: 11px; color: #9ab88a; line-height: 1.5; margin-top: 12px; text-align: center; }

.pickup-label {
    position: absolute;
    left: 0; top: 0;
    display: none;
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--gold);
    padding: 3px 6px;
    border-radius: 3px;
    white-space: nowrap;
}
#chat-open-button {
    position: absolute;
    right: 22px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 42px);
    width: 46px; height: 46px;
    border-radius: 50%;
    font-size: 18px;
    background: var(--panel);
    border: 2px solid var(--green-light);
    cursor: pointer;
    display: none;
}
@media (pointer: coarse) {
    #joystick { display: block; }
    #chat-open-button { display: block; }
}

/* ---- panels ---- */
.panel {
    position: fixed;
    z-index: 30;
    background: var(--panel);
    border: 3px solid var(--green-light);
    color: #d8e8c8;
    padding: 16px;
}
#profile-popup {
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(380px, 92vw);
    max-height: 80vh;
    overflow-y: auto;
}
.popup-close {
    position: absolute;
    top: 6px; right: 8px;
    background: none;
    border: none;
    color: var(--gold);
    font-size: 22px;
    cursor: pointer;
}
.profile-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
#profile-pic { width: 56px; height: 56px; border-radius: 4px; object-fit: cover; border: 2px solid var(--green-light); }
#profile-name { font-family: var(--font-pixel); font-size: 11px; color: var(--green-light); margin-bottom: 6px; }
#profile-npub { font-size: 11px; color: #8a9a7a; word-break: break-all; }
#profile-about { font-size: 13px; line-height: 1.5; margin-bottom: 10px; color: #b8d0a8; }
.note-card {
    font-size: 13px;
    line-height: 1.5;
    background: rgba(255, 251, 232, 0.08);
    border-left: 3px solid var(--gold);
    padding: 8px 10px;
    margin-bottom: 12px;
    overflow-wrap: break-word;
}
.profile-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.pixel-button {
    font-family: var(--font-pixel);
    font-size: 9px;
    padding: 10px 12px;
    background: var(--green-light);
    color: var(--green-dark);
    border: 2px solid #000;
    box-shadow: 2px 2px 0 #000;
    text-decoration: none;
    cursor: pointer;
    display: inline-block;
}

#fade-veil {
    position: fixed;
    inset: 0;
    background: #000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 60;
}
#fade-veil.on { opacity: 1; }

/* first-person crosshair */
#crosshair {
    position: fixed;
    left: 50%; top: 50%;
    width: 18px; height: 18px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 5;
}
#crosshair::before, #crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.9);
}
#crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::after { top: 8px; left: 0; height: 2px; width: 18px; }

/* red vignette pulse when you take a hit */
#hit-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 40;
    box-shadow: inset 0 0 120px 40px rgba(200, 16, 16, 0.75);
    opacity: 0;
    transition: opacity 0.35s ease;
}
#hit-flash.on { opacity: 1; transition: opacity 0.05s ease; }

/* GTA-style death card */
#wasted-overlay {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: radial-gradient(ellipse at center, rgba(20, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.88) 100%);
    animation: wasted-in 0.5s ease;
}
#wasted-overlay.hide { display: none; }
@keyframes wasted-in { from { opacity: 0; } to { opacity: 1; } }
#wasted-text {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(34px, 9vw, 72px);
    color: #c81616;
    letter-spacing: 0.12em;
    text-shadow: 4px 4px 0 #000, 0 0 34px rgba(200, 22, 22, 0.7);
    transform: scale(0.6);
    animation: wasted-zoom 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}
@keyframes wasted-zoom { to { transform: scale(1); } }
#wasted-by {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2.4vw, 14px);
    color: #e8e0d0;
    text-shadow: 2px 2px 0 #000;
}

/* ---- relay picker ---- */
#relay-panel {
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(340px, 92vw);
}
#relay-panel h3 { font-family: var(--font-pixel); font-size: 11px; color: var(--green-light); margin-bottom: 10px; }
.relay-hint { font-size: 12px; color: #9ab88a; line-height: 1.5; margin-bottom: 12px; }
#relay-list { display: flex; flex-direction: column; gap: 8px; }
.relay-row {
    font-family: var(--font-pixel);
    font-size: 9px;
    text-align: left;
    padding: 11px 12px;
    background: rgba(139, 172, 15, 0.12);
    color: #d8e8c8;
    border: 2px solid #2a4a2a;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.relay-row:hover { border-color: var(--green-light); }
.relay-row.active { border-color: var(--gold); color: var(--gold); cursor: default; }
.relay-row .relay-url { font-family: inherit; font-size: 7px; color: #8a9a7a; overflow: hidden; text-overflow: ellipsis; }

/* ---- arcade ---- */
#arcade-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
}
#arcade-frame-wrap {
    width: min(1100px, 96vw);
    height: min(760px, 92vh);
    display: flex;
    flex-direction: column;
    border: 4px solid var(--gold);
    background: #000;
}
#arcade-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--green-dark);
}
#arcade-title { font-family: var(--font-pixel); font-size: 10px; color: var(--gold); }
#arcade-iframe { flex: 1; width: 100%; border: none; }

/* ---- map ---- */
#map-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
#map-canvas {
    width: min(90vw, 90vh, 640px);
    height: min(90vw, 90vh, 640px);
    border: 4px solid var(--green-light);
    image-rendering: pixelated;
}
.overlay-hint { font-family: var(--font-pixel); font-size: 9px; color: #9ab88a; }

/* ---- feed panel ---- */
#feed-panel {
    position: fixed;
    top: 60px;
    right: 8px;
    z-index: 20;
    width: min(320px, 88vw);
    max-height: 70vh;
    overflow-y: auto;
    background: var(--panel);
    border: 3px solid #2a94c4;
    padding: 12px;
    color: #d8e8f8;
}
#feed-panel h3 { font-family: var(--font-pixel); font-size: 10px; color: #7fd7ff; margin-bottom: 10px; }
.feed-row { border-bottom: 1px solid rgba(127, 215, 255, 0.2); padding: 7px 0; font-size: 12px; }
.feed-author { font-weight: 700; color: #7fd7ff; margin-right: 6px; }
.feed-age { color: #6a8a9a; font-size: 10px; }
.feed-text { margin-top: 3px; line-height: 1.4; color: #c8d8e8; overflow-wrap: break-word; }

/* ---- toasts ---- */
#toast-container {
    position: fixed;
    top: calc(env(safe-area-inset-top, 8px) + 46px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}
.toast {
    font-size: 13px;
    color: #fff;
    background: #306850;
    border: 2px solid #000;
    padding: 9px 14px;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
    max-width: 88vw;
    transition: opacity 0.5s;
}
.toast.success { background: #10B981; color: #06281c; }
.toast.error { background: #EF4444; }
.toast.fade { opacity: 0; }
