/* ============================================
   LEADERBOARD IMAGE GENERATOR + VISUAL EDITOR
   ============================================ */

:root {
    --panel-bg: #0b1320;
    --panel-border: #273248;
    --panel-muted: #9eb0cf;
    --panel-text: #eff6ff;
    --surface: #121a2b;
    --accent: #4fc3f7;
    --accent-strong: #32a6e3;
    --danger: #ef4444;
    --preview-scale: 0.7;
}

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

body {
    min-height: 100vh;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--panel-text);
    background:
        radial-gradient(circle at 5% 0%, rgba(79, 195, 247, 0.2), transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(50, 166, 227, 0.2), transparent 35%),
        linear-gradient(180deg, #060910, #0b1220 50%, #090f1a);
}

.app-shell {
    width: min(1900px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 20px;
    display: grid;
    gap: 20px;
    grid-template-columns: 360px 1fr;
}

/* ============================================
   EDITOR PANEL
   ============================================ */
.editor-panel {
    background: rgba(11, 19, 32, 0.94);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    position: sticky;
    top: 20px;
}

.panel-header h1 {
    font-size: 1.5rem;
    letter-spacing: 0.3px;
}

.panel-header p {
    margin-top: 6px;
    font-size: 0.92rem;
    color: var(--panel-muted);
    line-height: 1.45;
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    background: rgba(19, 30, 49, 0.8);
    border: 1px solid rgba(42, 59, 90, 0.8);
}

.control-section h2 {
    font-size: 0.98rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #b8c9e6;
}

label {
    font-size: 0.8rem;
    color: #b6c8e3;
}

input,
select,
button {
    font: inherit;
}

input[type="text"],
input[type="number"],
select,
input[type="file"] {
    width: 100%;
    border: 1px solid rgba(90, 110, 145, 0.6);
    background: rgba(9, 16, 27, 0.85);
    color: #f4f9ff;
    border-radius: 8px;
    padding: 8px 10px;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
input[type="range"]:focus {
    outline: 2px solid rgba(79, 195, 247, 0.5);
    outline-offset: 1px;
}

input[type="file"] {
    padding: 7px;
}

input[type="range"] {
    width: 100%;
}

button {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.primary-btn {
    background: linear-gradient(180deg, var(--accent), var(--accent-strong));
    color: #031323;
    font-weight: 700;
}

.primary-btn:hover {
    filter: brightness(1.05);
}

.secondary-btn {
    background: rgba(18, 34, 56, 0.9);
    border-color: rgba(106, 138, 185, 0.5);
    color: #e2eeff;
}

.secondary-btn:hover {
    border-color: rgba(79, 195, 247, 0.7);
}

.players-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-editor-row {
    display: grid;
    grid-template-columns: 48px 1fr 1fr;
    gap: 6px;
    align-items: center;
}

.player-editor-row .rank-pill {
    text-align: center;
    font-size: 0.82rem;
    font-weight: 700;
    border-radius: 6px;
    border: 1px solid rgba(91, 123, 168, 0.55);
    background: rgba(17, 28, 44, 0.9);
    padding: 8px 0;
}

.image-control {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.image-control label,
.image-control input[type="file"] {
    grid-column: 1 / -1;
}

.control-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 1fr;
}

.nudge-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.export-buttons {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 1fr;
}

#status-message {
    min-height: 1.1rem;
    font-size: 0.82rem;
    color: #b8d2ff;
}

#status-message.is-error {
    color: #fecaca;
}

/* ============================================
   PREVIEW AREA
   ============================================ */
.preview-panel {
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    background: rgba(10, 18, 30, 0.9);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-header {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(39, 50, 72, 0.95);
}

.preview-header h2 {
    font-size: 1.05rem;
    letter-spacing: 0.03em;
}

.preview-header p {
    margin-top: 4px;
    font-size: 0.84rem;
    color: var(--panel-muted);
}

.preview-stage {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 20px;
    overflow: auto;
    --preview-scale: 1;
}

.preview-frame {
    width: calc(1080px * var(--preview-scale));
    height: calc(1080px * var(--preview-scale));
    position: relative;
}

.preview-scale {
    width: 1080px;
    height: 1080px;
    position: absolute;
    top: 0;
    left: 0;
    transform: scale(var(--preview-scale));
    transform-origin: top left;
}

.leaderboard-canvas {
    width: 1080px;
    height: 1080px;
    position: relative;
    top: 0;
    left: 0;
    overflow: hidden;
    border-radius: 0;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}

/* ============================================
   CANVAS LAYERS
   ============================================ */
.background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.background-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(8px);
    transform: scale(1.05);
}

.content-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
}

/* ============================================
   MOVABLE ELEMENTS
   ============================================ */
.movable {
    --offset-x: 0px;
    --offset-y: 0px;
    --element-scale: 1;
    --element-z: 10;
    transform: translate(var(--offset-x), var(--offset-y)) scale(var(--element-scale));
    transform-origin: center center;
    z-index: var(--element-z);
    cursor: grab;
    touch-action: none;
}

.movable.is-dragging {
    cursor: grabbing;
}

.movable.is-selected {
    outline: 3px dashed rgba(79, 195, 247, 0.9);
    outline-offset: 5px;
}

.leaderboard-canvas.is-exporting .movable.is-selected {
    outline: none;
}

.editable-text {
    cursor: text;
}

.editable-text:hover {
    outline: 2px dashed rgba(255, 255, 255, 0.4);
    outline-offset: 2px;
}

.editable-text.is-editing {
    outline: 2px solid rgba(79, 195, 247, 0.95);
    outline-offset: 2px;
    background: rgba(4, 10, 18, 0.35);
}

.leaderboard-canvas.is-exporting .editable-text {
    outline: none !important;
    background: transparent !important;
}

/* ============================================
   HEADER COMPONENT
   ============================================ */
.header-component {
    position: relative;
    margin-top: 20px;
    margin-bottom: 30px;
}

.header-logo {
    width: 385px;
    height: auto;
    display: block;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.4));
}

.shine-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 800px;
    height: 800px;
    background:
        radial-gradient(ellipse at center,
            rgba(255, 255, 255, 0.4) 0%,
            rgba(255, 255, 255, 0.1) 30%,
            transparent 60%),
        repeating-conic-gradient(from 0deg at 50% 50%,
            rgba(255, 255, 255, 0.15) 0deg,
            transparent 5deg,
            transparent 10deg,
            rgba(255, 255, 255, 0.15) 15deg,
            transparent 20deg,
            transparent 25deg);
    pointer-events: none;
    z-index: -1;
    opacity: 0.9;
    -webkit-mask-image: radial-gradient(ellipse at center,
            black 0%,
            black 20%,
            transparent 70%);
    mask-image: radial-gradient(ellipse at center,
            black 0%,
            black 20%,
            transparent 70%);
}

/* ============================================
   BEST SHOT BADGE
   ============================================ */
.bestshot-badge {
    position: absolute;
    top: 30px;
    right: 30px;
}

.bestshot-logo {
    width: 120px;
    height: auto;
    display: block;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
}

/* ============================================
   LEADERBOARD PANEL
   ============================================ */
.panel-subheader {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 85%;
    max-width: 700px;
    margin-bottom: -15px;
}

.ribbon-image {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
}

.subheader-text {
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: Impact, "Arial Black", Arial, sans-serif;
    font-size: 52px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 4px;
    white-space: nowrap;
    background: linear-gradient(180deg,
            #fef6ae 0%,
            #e8d88a 50%,
            #d4c06a 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-stroke: 1px #5a3d1a;
    filter: drop-shadow(2px 3px 3px rgba(0, 0, 0, 0.4));
}

.leaderboard-panel {
    width: 85%;
    max-width: 700px;
    background: #000000;
    border-radius: 20px 20px 0 0;
    padding: 3px;
    position: relative;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 40px), 50% 100%, 0 calc(100% - 40px));
}

.panel-content {
    background: linear-gradient(180deg, #352fbe 0%, #2a2596 100%);
    padding: 25px 25px 50px 25px;
    border-radius: 17px 17px 0 0;
    width: 100%;
    min-height: 100%;
}

.player-rows {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px 0;
}

.player-row {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 8px 10px;
}

.rank {
    font-family: "Arial Black", Arial, sans-serif;
    font-size: 32px;
    font-weight: 900;
    color: #7dd3fc;
    min-width: 60px;
    flex-shrink: 0;
}

.player-name {
    flex: 1;
    font-family: Arial, sans-serif;
    font-size: 22px;
    font-weight: bold;
    color: white;
}

.player-score {
    font-family: Arial, sans-serif;
    font-size: 20px;
    font-weight: bold;
    color: #7dd3fc;
    text-align: right;
    min-width: 90px;
    position: relative;
}

.score-text {
    white-space: nowrap;
}

.rank-crown {
    position: absolute;
    top: -24px;
    right: -14px;
    width: 32px;
    height: auto;
    transform: rotate(25deg);
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
    z-index: 10;
    pointer-events: none;
}

/* ============================================
   CONFETTI
   ============================================ */
.confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 10;
    filter: blur(1.5px);
}

.confetti {
    position: absolute;
    width: 15px;
    height: 35px;
    opacity: 0.8;
    border-radius: 2px;
}

.confetti.small {
    width: 10px;
    height: 20px;
    opacity: 0.6;
}

.confetti.gold {
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 50%, #cc8800 100%);
}

.confetti.blue {
    background: linear-gradient(135deg, #4fc3f7 0%, #29b6f6 50%, #0288d1 100%);
}

.confetti.silver {
    background: linear-gradient(135deg, #e8e8e8 0%, #c0c0c0 50%, #a0a0a0 100%);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .editor-panel {
        position: static;
        max-height: none;
    }

    .preview-panel {
        min-height: 70vh;
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding: 10px;
        gap: 12px;
    }

    .editor-panel {
        border-radius: 12px;
        padding: 14px;
    }

    .control-grid,
    .export-buttons,
    .nudge-controls {
        grid-template-columns: 1fr;
    }

    .player-editor-row {
        grid-template-columns: 40px 1fr;
    }

    .player-editor-row .player-score-input {
        grid-column: 2;
    }
}
