/* ── Reset & Base ─────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    color: #f0f0f0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem 1rem;
}

#app {
    max-width: 720px;
    width: 100%;
}

.hidden { display: none !important; }

/* ── Input Phase ─────────────────────────────── */
.logo {
    text-align: center;
    font-size: 2.8rem;
    font-weight: 900;
    margin-bottom: 0.25rem;
    background: linear-gradient(90deg, #f7971e, #ffd200);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    text-align: center;
    color: #aaa;
    margin-bottom: 2rem;
    font-size: 1.05rem;
}

/* Input area */
.input-area {
    background: rgba(255,255,255,0.05);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    transition: border-color 0.2s, background 0.2s;
    border: 2px solid transparent;
}

.input-area.drag-over {
    border-color: #ffd200;
    background: rgba(255,210,0,0.08);
}

.input-row {
    display: flex;
    gap: 0.5rem;
}

.input-row input[type="text"],
.input-row input[type="url"] {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #444;
    border-radius: 10px;
    background: rgba(255,255,255,0.07);
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-row input:focus {
    border-color: #ffd200;
}

.btn-add {
    padding: 0.75rem 1.4rem;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #f7971e, #ffd200);
    color: #1a1a2e;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-add:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255,210,0,0.3);
}


/* Entry list */
#entries-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.entry-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 0.65rem 1rem;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.entry-item .entry-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.entry-item .entry-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem;
}

.entry-item .entry-label-editable {
    cursor: pointer;
    border-bottom: 1px dashed rgba(255,255,255,0.25);
    transition: color 0.15s, border-color 0.15s;
}

.entry-item .entry-label-editable:hover {
    color: #ffd200;
    border-bottom-color: #ffd200;
}

.entry-item .entry-label-input {
    flex: 1;
    min-width: 0;
    padding: 0.2rem 0.4rem;
    border: 1px solid #ffd200;
    border-radius: 6px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
}

.entry-item .entry-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.entry-item .entry-thumb-iframe {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    pointer-events: none;
}

.entry-item .entry-thumb-iframe iframe {
    width: 320px;
    height: 240px;
    border: none;
    transform: scale(0.125);
    transform-origin: top left;
    pointer-events: none;
}

.entry-item .btn-delete {
    background: none;
    border: none;
    color: #f44;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 6px;
    transition: background 0.15s;
    flex-shrink: 0;
}

.entry-item .btn-delete:hover {
    background: rgba(255, 68, 68, 0.15);
}

/* Hover preview (cursor-following) */
#cursor-preview {
    position: fixed;
    background: #1e1e3a;
    border: 2px solid #555;
    border-radius: 12px;
    padding: 0.5rem;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    max-width: 420px;
    width: max-content;
}

#cursor-preview.visible {
    opacity: 1;
    pointer-events: auto;
}

#cursor-preview img {
    display: block;
    max-width: 400px;
    max-height: 350px;
    border-radius: 8px;
    object-fit: contain;
}

.preview-image-label {
    text-align: center;
    color: #ccc;
    font-size: 0.85rem;
    margin-top: 0.4rem;
    font-weight: 600;
}

.preview-url-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.preview-url {
    color: #7eb8ff;
    font-size: 0.8rem;
    word-break: break-all;
}

.not-rendering-link {
    color: #f7971e;
    font-size: 0.8rem;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    flex-shrink: 0;
}

.not-rendering-link:hover {
    text-decoration: underline;
    color: #ffd200;
}

.not-rendering-box {
    position: relative;
    padding: 1.25rem 1.5rem;
    text-align: center;
    min-width: 260px;
}

.not-rendering-close {
    position: absolute;
    top: 0;
    right: 0;
    background: none;
    border: none;
    color: #888;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    line-height: 1;
    border-radius: 6px;
}

.not-rendering-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.not-rendering-msg {
    color: #ccc;
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0;
}

/* Decide button */
.btn-decide {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}

.btn-decide:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-decide:not(:disabled):hover {
    transform: scale(1.03);
    box-shadow: 0 6px 30px rgba(118,75,162,0.45);
}

/* ── Decide Phase ────────────────────────────── */
#decide-phase {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    display: flex;
    flex-direction: row;
    padding: 0;
    overflow: auto;
}

.decide-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 3rem;
    min-width: 0;
}

.round-title {
    text-align: center;
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 0.25rem;
}

.remaining-text {
    text-align: center;
    color: #aaa;
    margin-bottom: 2.5rem;
    font-size: 1.2rem;
}

.versus-container {
    display: flex;
    align-items: stretch;
    gap: 2rem;
    margin-bottom: 2rem;
    position: relative;
    width: 100%;
    max-width: 1200px;
    flex: 1;
    min-height: 0;
}

.choice-card {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 3px solid #444;
    border-radius: 20px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
    outline: none;
    min-height: 300px;
    -webkit-tap-highlight-color: transparent;
}

.choice-card.card-hover {
    border-color: #ffd200;
    transform: scale(1.03);
    box-shadow: 0 8px 40px rgba(255,210,0,0.2);
}

.choice-card.card-tap {
    animation: tap-flash 0.25s ease-out forwards;
}

@keyframes tap-flash {
    0%   { border-color: #ffd200; box-shadow: 0 0 20px rgba(255,210,0,0.4); transform: scale(0.97); }
    100% { border-color: #ffd200; box-shadow: 0 0 10px rgba(255,210,0,0.2); transform: scale(1); }
}

.card-content {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    min-height: 200px;
    word-break: break-word;
}

.card-content .card-text {
    font-size: 2rem;
    font-weight: 700;
}

.card-content .card-url-link {
    color: #7eb8ff;
    text-decoration: underline;
    font-size: 1rem;
    word-break: break-all;
}

.card-content .card-url-preview {
    width: 100%;
    max-height: 300px;
    border-radius: 10px;
    object-fit: cover;
    background: #fff;
    border: none;
}

.card-image-label {
    font-size: 1.1rem;
    color: #ccc;
    font-weight: 600;
    margin-top: 0.5rem;
}

.url-preview-wrapper {
    position: relative;
    width: 100%;
    pointer-events: none;
}

.url-preview-wrapper iframe {
    border: none;
    border-radius: 10px;
    background: #fff;
    max-width: 100%;
    display: block;
    pointer-events: none;
}


.card-content img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: 10px;
    object-fit: contain;
}

.vs-badge {
    align-self: center;
    background: linear-gradient(135deg, #f7971e, #ffd200);
    color: #1a1a2e;
    font-weight: 900;
    font-size: 1.5rem;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 20px rgba(255,210,0,0.35);
}

.pick-btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
    cursor: pointer;
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.choice-card.card-hover .pick-btn {
    transform: scale(1.05);
}

.btn-skip {
    display: block;
    margin: 0 auto 1rem;
    padding: 0.85rem 3rem;
    border: 2px solid #555;
    border-radius: 12px;
    background: transparent;
    color: #ccc;
    font-size: 1.1rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.btn-skip:hover {
    border-color: #ffd200;
    color: #ffd200;
}

.btn-back {
    display: block;
    margin: 0 auto;
    background: none;
    border: none;
    color: #888;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
}

.btn-back:hover { color: #fff; }

/* ── Winner Phase ────────────────────────────── */
#winner-phase {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

#winner-phase.has-rankings {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(-50vw + 50%);
    padding: 0 2rem;
}

.winner-main {
    flex: 1;
    min-width: 0;
}

#winner-phase.has-rankings .winner-main {
    flex: 1;
}

#winner-rankings-sidebar {
    flex: 1;
    background: rgba(0,0,0,0.25);
    border-left: 2px solid rgba(255,255,255,0.1);
    border-radius: 14px;
    padding: 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    margin-left: 2rem;
    max-height: 80vh;
}

#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 999;
}

.winner-place-label {
    text-align: center;
    font-size: 0.95rem;
    color: #888;
    font-weight: 600;
    margin: 0 0 0.5rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.winner-title {
    text-align: center;
    font-size: 2.4rem;
    font-weight: 900;
    margin-bottom: 1.5rem;
    background: linear-gradient(90deg, #ffd200, #f7971e, #ffd200);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.05); }
}

.winner-frame {
    border: 4px solid #ffd200;
    border-radius: 20px;
    padding: 2rem;
    background: rgba(255,210,0,0.06);
    text-align: center;
    box-shadow: 0 0 40px rgba(255,210,0,0.15), inset 0 0 40px rgba(255,210,0,0.05);
    margin-bottom: 2rem;
}

.trophy-row {
    font-size: 2rem;
    letter-spacing: 0.5rem;
    margin: 0.75rem 0;
}

.winner-content {
    padding: 1.5rem 0;
    font-size: 1.6rem;
    font-weight: 700;
}

.winner-content img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 10px;
    object-fit: contain;
}

.winner-content .card-url-link {
    color: #7eb8ff;
    font-size: 0.95rem;
    display: block;
    margin-top: 0.5rem;
}

/* Auto-ranked last place reveal */
.auto-ranked-reveal {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid rgba(255,255,255,0.1);
    animation: slideReveal 0.5s ease;
}

.auto-ranked-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #aaa;
    margin-bottom: 0.75rem;
}

.auto-ranked-content {
    font-size: 1.2rem;
    font-weight: 600;
}

.auto-ranked-content img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
    object-fit: contain;
}

.auto-ranked-content .card-url-link {
    color: #7eb8ff;
    font-size: 0.85rem;
    display: block;
    margin-top: 0.4rem;
}

@keyframes slideReveal {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.winner-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn-restart {
    padding: 0.85rem 2.5rem;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #f7971e, #ffd200);
    color: #1a1a2e;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-restart:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255,210,0,0.35);
}

/* ── Rankings Sidebar ─────────────────────────── */
#rankings-sidebar {
    width: 200px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.3);
    border-left: 2px solid rgba(255,255,255,0.1);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
}

.ranking-item.ranking-deciding {
    border: 2px dashed rgba(255,210,0,0.4);
    background: rgba(255,210,0,0.04);
}

.ranking-badge {
    font-weight: 900;
    font-size: 0.85rem;
    background: linear-gradient(135deg, #f7971e, #ffd200);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex-shrink: 0;
    min-width: 28px;
}

.ranking-preview {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ranking-preview img {
    width: 100%;
    max-height: 80px;
    object-fit: contain;
    border-radius: 6px;
}

.ranking-label {
    font-size: 0.8rem;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.ranking-iframe-thumb {
    width: 100%;
    height: 50px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    pointer-events: none;
    margin-bottom: 0.25rem;
}

.ranking-iframe-thumb iframe {
    width: 320px;
    height: 240px;
    border: none;
    transform: scale(0.125);
    transform-origin: top left;
    pointer-events: none;
}

.ranking-label.deciding {
    color: #ffd200;
    font-style: italic;
    animation: decidePulse 1.5s ease-in-out infinite;
}

@keyframes decidePulse {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

/* ── Runner-up Button ────────────────────────── */
.btn-runner-up {
    padding: 0.85rem 2.5rem;
    border: 2px solid #667eea;
    border-radius: 12px;
    background: transparent;
    color: #667eea;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s, color 0.15s;
}

.btn-runner-up:hover {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-color: transparent;
    transform: scale(1.05);
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
    #decide-phase {
        flex-direction: column;
    }
    .decide-main {
        padding: 1.5rem 1rem;
    }
    #rankings-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        border-left: none;
        border-top: 2px solid rgba(255,255,255,0.1);
        padding: 1rem;
        gap: 0.5rem;
    }
    .ranking-item {
        flex: 0 0 auto;
    }
    #winner-phase, #winner-phase.has-rankings {
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        padding: 0;
    }
    #winner-rankings-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        border-left: none;
        border-top: 2px solid rgba(255,255,255,0.1);
        border-radius: 0;
        margin: 2rem 0 0 0;
        padding: 1rem;
        gap: 0.5rem;
        max-height: none;
    }
    .round-title {
        font-size: 2.2rem;
    }
    .logo { font-size: 2.2rem; }
}

/* Portrait phone: stack cards vertically */
@media (max-width: 768px) and (orientation: portrait) {
    .decide-main {
        padding: 1rem 0.75rem;
    }
    .round-title {
        font-size: 1.6rem;
        margin-bottom: 0.1rem;
    }
    .remaining-text {
        margin-bottom: 0.75rem;
        font-size: 1rem;
    }
    .versus-container {
        flex-direction: column;
        gap: 0.75rem;
    }
    .choice-card {
        min-height: 0;
        padding: 0.75rem;
        flex: 1;
    }
    .card-content {
        min-height: 0;
        margin-bottom: 0.5rem;
        gap: 0.5rem;
    }
    .card-content .card-text {
        font-size: 1.3rem;
    }
    .card-content img {
        max-height: 25vh;
    }
    .card-content .card-url-preview {
        max-height: 20vh;
    }
    .pick-btn {
        padding: 0.6rem;
        font-size: 0.95rem;
    }
    .vs-badge {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
        align-self: center;
    }
    .btn-skip {
        padding: 0.5rem 1.5rem;
        font-size: 0.95rem;
        margin-bottom: 0.5rem;
    }
    .btn-back {
        font-size: 0.85rem;
    }
}

/* Landscape phone: cards side by side, compact */
@media (max-height: 500px) and (orientation: landscape) {
    .decide-main {
        padding: 0.5rem 1rem;
    }
    .round-title {
        font-size: 1.4rem;
        margin-bottom: 0;
    }
    .remaining-text {
        margin-bottom: 0.5rem;
        font-size: 0.9rem;
    }
    .versus-container {
        flex-direction: row;
        gap: 0.75rem;
    }
    .choice-card {
        min-height: 0;
        padding: 0.75rem;
    }
    .card-content {
        min-height: 0;
        margin-bottom: 0.5rem;
        gap: 0.25rem;
    }
    .card-content .card-text {
        font-size: 1.2rem;
    }
    .card-content img {
        max-height: 30vh;
    }
    .card-content .card-url-preview {
        max-height: 25vh;
    }
    .pick-btn {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
    .vs-badge {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    .btn-skip {
        padding: 0.4rem 1.5rem;
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }
    .btn-back {
        font-size: 0.85rem;
    }
}
