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

body {
    background-color: #0f1117;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
header {
    background: linear-gradient(135deg, #1a1d2e 0%, #12151f 100%);
    border-bottom: 1px solid #2a2d3e;
    padding: 24px 40px;
    display: flex;
    align-items: center;
    gap: 16px;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 12px;
}

header h1 img {
    width: 1em;
    height: 1em;
}

.badge {
    background: #3b82f6;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    letter-spacing: 0.4px;
}

/* ── Main content ── */
main {
    flex: 1;
    padding: 40px;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #6b7280;
    margin-bottom: 16px;
}

/* ── Game list ── */
.game-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-card {
    background: #1a1d2e;
    border: 1px solid #2a2d3e;
    border-radius: 12px;
    padding: 18px 24px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 16px;
    transition: border-color 0.2s, background 0.2s;
}

.game-card:hover {
    background: #1e2235;
    border-color: #3b82f6;
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.game-id {
    font-size: 1rem;
    font-weight: 600;
    color: #f3f4f6;
    font-family: 'Courier New', monospace;
}

.game-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.game-type {
    background: #2d3748;
    color: #93c5fd;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.game-time {
    font-size: 0.8rem;
    color: #6b7280;
}

/* ── Buttons ── */
.btn-join {
    background: #3b82f6;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 10px 22px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}

.btn-join:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-join:active {
    transform: translateY(0);
}

.btn-create {
    background: #10b981;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 12px 28px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    letter-spacing: 0.3px;
    transition: background 0.2s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-create:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-create:active {
    transform: translateY(0);
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: #4b5563;
}

.empty-state .icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 1rem;
}

/* ── Footer ── */
footer {
    background: #12151f;
    border-top: 1px solid #2a2d3e;
    padding: 24px 40px;
    display: flex;
    justify-content: flex-end;
}

footer.footer-start {
    justify-content: flex-start;
}

/* ── Favicon background watermark (decorative) ── */
.bg-watermark {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.bg-watermark::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('/favicon.png') no-repeat center center;
    background-size: min(60vw, 60vh);
    opacity: 0.05;
}

/* ── Board page layout ── */
main.board-main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    max-width: unset;
}

#board {
    width: 560px;
    max-width: 90vw;
}

.game-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

/* ── Waiting overlay ── */
#waiting-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 17, 23, 0.82);
    backdrop-filter: blur(4px);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 10;
}

#waiting-overlay.hidden, #link-box.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #2a2d3e;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.waiting-text {
    font-size: 1rem;
    font-weight: 600;
    color: #e0e0e0;
    letter-spacing: 0.3px;
}

.waiting-sub {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: -12px;
}

/* ── Game link box ── */
.game-link-box {
    background: #1a1d2e;
    border: 1px solid #2a2d3e;
    border-radius: 10px;
    padding: 16px 20px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    max-width: 90vw;
}

.game-link-box .link-label {
    color: #6b7280;
    white-space: nowrap;
}

#game-qr, #game-qr img, #game-qr canvas {
    border-radius: 6px;
    display: block;
}

.btn-copy {
    background: #2a2d3e;
    border: 1px solid #3a3d4e;
    border-radius: 6px;
    color: #e0e0e0;
    cursor: pointer;
    padding: 4px 10px;
    font-size: 1rem;
    line-height: 1;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-copy:hover {
    background: #3b82f6;
    border-color: #3b82f6;
}

/* ── Game over modal ── */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fade-in 0.3s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.game-over-box {
    background: #1a1d2e;
    border: 1px solid #2a2d3e;
    border-radius: 16px;
    padding: 48px 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    animation: slide-up 0.3s ease;
}

@keyframes slide-up {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.game-over-emoji {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 8px;
}

.game-over-title {
    font-size: 2rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.5px;
}

.game-over-sub {
    font-size: 0.95rem;
    color: #6b7280;
    margin-bottom: 12px;
}

.resign-progress {
    width: 100%;
    height: 4px;
    background: #2a2d3e;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 8px;
}

.resign-progress-bar {
    height: 100%;
    width: 100%;
    background: #3b82f6;
    border-radius: 999px;
    animation: drain 3s linear forwards;
}

@keyframes drain {
    from { width: 100%; }
    to   { width: 0; }
}

.btn-lobby {
    background: #3b82f6;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 12px 28px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    margin-top: 8px;
}

.btn-lobby:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-lobby:active {
    transform: translateY(0);
}

/* ── Resign button ── */
.btn-resign {
    background: transparent;
    color: #f87171;
    border: 1px solid #f87171;
    border-radius: 8px;
    padding: 10px 24px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, color 0.2s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-resign:hover {
    background: #f87171;
    color: #0f1117;
    transform: translateY(-1px);
}

.btn-resign:active {
    transform: translateY(0);
}

/* ── Responsive ── */
@media (max-width: 600px) {
    main, header, footer { padding: 20px; }

    .game-card {
        grid-template-columns: 1fr;
    }

    #board { width: 92vw; }
}

