/* ========================================
   SLICELAND — Atlas Noir Theme
   ======================================== */

:root {
    /* Core palette */
    --bg:               #0a0e17;
    --bg-warm:          #0e1220;
    --bg-card:          #0f1525;
    --bg-card-alt:      #131b2b;

    /* Text */
    --text:             #e8e2d6;
    --text-dim:         #7a8baa;
    --text-faint:       #3a4a62;
    --text-stroke:      #000;

    /* Accent for shape */
    --color-main:       #1E3A5F;
    --color-main-a:     rgba(30, 58, 95, 0.5);

    /* Blue accent (Sliceland's signature color) */
    --blue:             #1E3A5F;
    --blue-light:       #5B9CF5;
    --blue-dim:         rgba(30, 58, 95, 0.3);
    --blue-mid:         rgba(30, 58, 95, 0.55);
    --blue-bright:      #5B9CF5;

    /* Ring / chrome */
    --ring-stroke:      rgba(255, 255, 255, 0.22);
    --shape-stroke:     #5B9CF5;

    /* Status */
    --win:              #4ade80;
    --win-dim:          rgba(74, 222, 128, 0.2);
    --error:            #ef4444;
    --error-dim:        rgba(239, 68, 68, 0.15);

    /* UI */
    --overlay-bg:       rgba(5, 7, 14, 0.88);
    --btn-share-bg:     rgba(91, 156, 245, 0.1);
    --btn-share-border: rgba(91, 156, 245, 0.3);
    --distr-bg:         #141c2e;
    --distr-border:     #222e44;

    /* Animation tokens */
    --anim-osc-dur:     2s;
    --anim-osc-amt:     4px;
    --ease-out-expo:    cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-back:    cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ========================================
   RESET & BASE
   ======================================== */

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

html {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

html::-webkit-scrollbar {
    display: none;
}

body {
    min-height: 100%;
    overflow: visible;
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 400;
    color: var(--text);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}


/* ========================================
   HEADER
   ======================================== */

#header {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    padding: 16px 16px 4px;
    flex-shrink: 0;
}

#title {
    font-family: 'Cinzel', serif;
    font-size: clamp(22px, 5vw, 32px);
    font-weight: 700;
    letter-spacing: 0.15em;
    text-align: center;
    user-select: none;
    line-height: 1;
}

.title-slice {
    color: var(--text);
}

.title-land {
    color: var(--blue-light);
}

.header-btn {
    background: none;
    border: 1.5px solid var(--text-faint);
    color: var(--text-dim);
    width: 44px;
    height: 44px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.header-btn:hover {
    border-color: rgba(91, 156, 245, 0.35);
    color: var(--blue-light);
    background: rgba(91, 156, 245, 0.1);
}

.header-btn:active {
    transform: scale(0.92);
}

/* ========================================
   GAME CONTAINER
   ======================================== */

#game-container {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    --_max-game: min(600px, calc(100vw - 90px), calc(100vh - 200px));
    --_max-game: min(600px, calc(100vw - 90px), calc(100dvh - 200px));
    width: var(--_max-game);
    height: var(--_max-game);
    flex: 0 0 auto;
    aspect-ratio: 1;
    touch-action: none;
    -webkit-touch-callout: none;
    user-select: none;
}

#game-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* ========================================
   RESULT DISPLAY
   ======================================== */

/* Below canvas area */
#below-canvas {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 4px 0 12px;
    flex-shrink: 0;
}

#default-prompt {
    text-align: center;
}

.prompt-text {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 400;
    color: var(--text-dim);
}

.prompt-text.error-flash {
    color: var(--error);
}

.prompt-link {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    color: var(--text-dim);
    opacity: 0.75;
    text-decoration: none;
    transition: color 0.2s;
}

.prompt-link:hover {
    color: var(--blue-light);
}

#result-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#result-display.hidden {
    display: none;
}

#result-display .reveal-item {
    opacity: 0;
    transition: opacity 0.4s ease;
}

#result-display .reveal-item.visible {
    opacity: 1;
}

#result-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.result-emoji {
    font-size: 24px;
    line-height: 1;
    font-weight: 700;
}

.result-emoji.check {
    color: var(--text);
}

.result-emoji.cross {
    color: var(--text);
}

.result-ratio {
    font-family: 'Cinzel', serif;
    font-size: clamp(32px, 8vw, 48px);
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    letter-spacing: 0.05em;
    -webkit-text-stroke: 3px var(--text-stroke);
    paint-order: stroke fill;
    cursor: pointer;
    user-select: none;
    animation: verticalShaking 0.4s ease both;
    transition: color 0.2s;
}

.result-ratio:hover {
    opacity: 0.85;
}

.result-ratio.win {
    color: var(--text);
}

.ratio-first {
    color: var(--blue-light);
}

#country-reveal {
    display: flex;
    align-items: center;
    gap: 8px;
}

#country-name {
    font-family: 'Cinzel', serif;
    font-size: clamp(16px, 4vw, 22px);
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.btn-share {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 28px;
    border: 1.5px solid var(--btn-share-border);
    background: var(--btn-share-bg);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.06em;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-share:hover {
    background: rgba(91, 156, 245, 0.18);
    border-color: var(--blue-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(91, 156, 245, 0.12);
}

.btn-share:active {
    transform: scale(0.96);
}

.btn-share.copied {
    border-color: var(--win);
    color: var(--win);
    background: var(--win-dim);
}

/* ========================================
   ERROR DISPLAY
   ======================================== */

#error-display {
    position: relative;
    z-index: 10;
    text-align: center;
    padding: 8px 20px;
    flex-shrink: 0;
}

#error-display.hidden {
    display: none;
}

#error-msg {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 500;
    color: var(--error);
    animation: horizontalShaking 0.35s ease;
}

/* ========================================
   OVERLAYS
   ======================================== */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    animation: fadeIn 0.25s ease;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: var(--bg-card);
    border: 1px solid rgba(91, 156, 245, 0.1);
    border-radius: 16px;
    padding: 28px 32px 32px;
    max-width: 420px;
    width: 100%;
    max-height: 90dvh;
    overflow-y: auto;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 80px rgba(91, 156, 245, 0.04);
    animation: scaleIn 0.3s var(--ease-out-back);
}

.overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.overlay-header h2 {
    font-family: 'Cinzel', serif;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.1em;
}

.overlay-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.overlay-close:hover {
    color: var(--text);
    background: rgba(255,255,255,0.05);
}

/* ========================================
   TUTORIAL
   ======================================== */

.tutorial-body {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.tutorial-visual {
    display: flex;
    justify-content: center;
}

.tutorial-demo {
    width: 240px;
    height: 240px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: var(--bg);
}

#tutorial-canvas {
    display: block;
    width: 240px;
    height: 240px;
}

.tutorial-rules {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tutorial-rules li {
    font-size: 20px;
    line-height: 1.5;
    color: var(--text);
    padding-left: 4px;
}

.tutorial-rules strong {
    color: var(--text);
    font-weight: 600;
}


/* ========================================
   STATISTICS
   ======================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 28px;
}

.stat-box {
    text-align: center;
    padding: 12px 4px;
    background: var(--bg-card-alt);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-value {
    font-family: 'Cinzel', serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    margin-top: 4px;
    text-transform: uppercase;
}

.distribution-section {
    margin-bottom: 24px;
}

.distribution-section h3 {
    font-family: 'Cinzel', serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 0.08em;
    margin-bottom: 14px;
}

.distr-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.distr-label {
    width: 28px;
    text-align: right;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.distr-bar-track {
    flex: 1;
    height: 22px;
    background: var(--distr-bg);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--distr-border);
}

.distr-bar-fill {
    height: 100%;
    background: var(--text-dim);
    border-radius: 3px;
    min-width: 0;
    transition: width 0.5s var(--ease-out-expo);
    position: relative;
}

.distr-bar-fill.win-bar {
    background: var(--win);
}

.distr-bar-fill.loss-bar {
    background: var(--blue-light);
    opacity: 0.5;
}

.distr-count {
    width: 24px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    text-align: left;
    font-variant-numeric: tabular-nums;
}

.countdown-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 0 0;
}

.countdown-label {
    font-size: 20px;
    color: var(--text-dim);
    font-weight: 500;
}

.countdown-timer {
    font-family: 'Cinzel', serif;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.08em;
    width: 8ch;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes verticalShaking {
    0% { transform: translateY(0); }
    15% { transform: translateY(-6px); }
    30% { transform: translateY(4px); }
    45% { transform: translateY(-3px); }
    60% { transform: translateY(2px); }
    75% { transform: translateY(-1px); }
    100% { transform: translateY(0); }
}

@keyframes horizontalShaking {
    0% { transform: translateX(0); }
    15% { transform: translateX(-8px); }
    30% { transform: translateX(6px); }
    45% { transform: translateX(-4px); }
    60% { transform: translateX(3px); }
    75% { transform: translateX(-1px); }
    100% { transform: translateX(0); }
}

@keyframes oscillate {
    from { transform: translateY(calc(var(--anim-osc-amt) * -1)); }
    to { transform: translateY(var(--anim-osc-amt)); }
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
    #header {
        padding: 12px 12px 2px;
    }

    .overlay-content {
        padding: 22px 20px 26px;
        border-radius: 14px;
    }

    .stats-grid {
        gap: 6px;
    }

    .stat-value {
        font-size: 20px;
    }

    .btn-share {
        padding: 10px 24px;
    }

    .tutorial-rules li {
        font-size: 17px;
    }
}

@media (max-width: 380px) {
    .result-ratio {
        font-size: 28px !important;
    }

    .prompt-text,
    .prompt-link {
        font-size: 17px;
    }
}

/* Landscape phones: limit canvas height so it doesn't consume entire viewport */
@media (max-height: 500px) and (orientation: landscape) {
    #game-container {
        width: min(400px, 70vh);
        height: min(400px, 70vh);
    }
}

/* ========================================
   UTILITY
   ======================================== */

.hidden {
    display: none !important;
}

::selection {
    background: rgba(91, 156, 245, 0.3);
    color: var(--text);
}

/* Hide scrollbar on overlay content */
.overlay-content::-webkit-scrollbar {
    width: 0;
    display: none;
}

.overlay-content {
    scrollbar-width: none;
}

/* ========================================
   DEV VIEW (temporary)
   ======================================== */

#dev-toggle {
    display: none;
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 200;
    padding: 6px 12px;
    background: rgba(91, 156, 245, 0.2);
    border: 1px solid rgba(91, 156, 245, 0.4);
    color: var(--blue-light);
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    border-radius: 6px;
    cursor: pointer;
}

#dev-toggle.dev-visible {
    display: block;
}

#dev-panel {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: var(--bg);
    overflow-y: auto;
    padding: 20px;
}

#dev-panel .dev-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

#dev-panel .dev-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    background: var(--bg-card);
    border: 1px solid var(--text-faint);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}

#dev-panel .dev-card:hover {
    border-color: var(--blue-light);
}

#dev-panel .dev-card canvas {
    display: block;
}

#dev-panel .dev-card .dev-name {
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    text-align: center;
    word-break: break-word;
}

#dev-panel .dev-card .dev-id {
    font-size: 10px;
    color: var(--text-dim);
}

#dev-panel .dev-header {
    text-align: center;
    margin-bottom: 16px;
    font-family: 'Cinzel', serif;
    font-size: 18px;
    color: var(--text);
}

#dev-panel .dev-loading {
    text-align: center;
    color: var(--text-dim);
    padding: 40px;
}
