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

:root {
    color-scheme: dark;
    --bg: #0B1220;
    --bg-2: #121A2B;
    --surface: #1A2336;
    --text: #E6ECF3;
    --muted: #94A3B8;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    --accent: #E8834F;

    --red: #D03B2C;
    --yellow: #E8B84F;
    --green: #2FA34A;
    --blue: #2467D6;

    --card-w: 78px;
    --card-h: 116px;
    --card-radius: 10px;
}

@media (max-width: 720px) {
    :root { --card-w: 58px; --card-h: 86px; }
}

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background:
        radial-gradient(ellipse at center, #15263e 0%, #0B1220 70%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.25);
}

.site-logo {
    display: block;
    width: 120px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.site-logo:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-strong, 0 8px 30px rgba(0,0,0,0.45));
}
.site-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

@media (max-width: 720px) {
    .site-logo { width: 80px; height: 44px; }
}

.brand {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--accent);
    font-style: italic;
    text-transform: uppercase;
}

.topbar-actions { display: flex; gap: 12px; align-items: center; }
.topbar-meta { display: flex; gap: 10px; align-items: center; flex: 1; justify-content: center; }
.round-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.5px;
}

.score-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(232, 131, 79, 0.15);
    border: 1px solid rgba(232, 131, 79, 0.4);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.btn {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: #243049; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #1a0e07; border-color: transparent; }
.btn.primary:hover { background: #d4703c; }

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 18px;
    user-select: none;
}

.table {
    flex: 1;
    display: grid;
    grid-template-rows: auto auto auto;
    gap: 12px;
    padding: 16px;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

.opponents {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.opponent-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: center;
}

.opponent {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border-radius: 14px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.opponent.side { gap: 4px; }
.opponent.active {
    border-color: var(--accent);
    background: rgba(232, 131, 79, 0.08);
    box-shadow: 0 0 24px rgba(232, 131, 79, 0.35);
}
.opponent-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.5px;
}
.opponent.active .opponent-name { color: var(--accent); }
.opponent-meta { font-size: 12px; color: var(--muted); }
.opponent-meta .eins-flag {
    color: var(--accent);
    font-weight: 800;
    margin-left: 6px;
    letter-spacing: 1px;
}

.opponent-hand {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
}
.opponent-hand .card { margin-left: -42px; }
.opponent-hand .card:first-child { margin-left: 0; }

.opponent-hand.vertical { flex-direction: column; }
.opponent-hand.vertical .card { margin-left: 0; margin-top: -88px; }
.opponent-hand.vertical .card:first-child { margin-top: 0; }

.center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.direction-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin-bottom: 4px;
    user-select: none;
}
.direction-arrow .arrow-glyph {
    font-size: 56px;
    line-height: 1;
    color: var(--accent);
    text-shadow: 0 0 18px rgba(232, 131, 79, 0.55);
    transition: transform 0.4s ease;
}
.direction-arrow .arrow-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--muted);
    font-weight: 700;
}
@media (max-width: 720px) {
    .direction-arrow .arrow-glyph { font-size: 40px; }
}

.piles { display: flex; gap: 16px; align-items: flex-end; }
.pile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.pile-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.draw-pile { cursor: pointer; }
.draw-pile.disabled { cursor: not-allowed; opacity: 0.6; }

.current-color {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
    padding: 14px 36px;
    min-width: 240px;
    border-radius: 14px;
    background: var(--surface);
    border: 3px solid var(--border);
    font-size: 22px;
    font-weight: 900;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: white;
    box-shadow: var(--shadow);
    transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}
.current-color .swatch {
    display: inline-block;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.85);
    background: #888;
    box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.current-color.red {
    background: var(--red); border-color: var(--red);
    box-shadow: 0 0 28px rgba(208, 59, 44, 0.6), var(--shadow);
}
.current-color.yellow {
    background: var(--yellow); border-color: var(--yellow); color: #1a0e07;
    box-shadow: 0 0 28px rgba(232, 184, 79, 0.6), var(--shadow);
}
.current-color.green {
    background: var(--green); border-color: var(--green);
    box-shadow: 0 0 28px rgba(47, 163, 74, 0.6), var(--shadow);
}
.current-color.blue {
    background: var(--blue); border-color: var(--blue);
    box-shadow: 0 0 28px rgba(36, 103, 214, 0.6), var(--shadow);
}
.current-color.red .swatch,
.current-color.green .swatch,
.current-color.blue .swatch { background: white; }
.current-color.yellow .swatch { background: #1a0e07; border-color: rgba(26,14,7,0.85); }
@media (max-width: 720px) {
    .current-color {
        font-size: 16px;
        letter-spacing: 3px;
        padding: 10px 22px;
        min-width: 0;
    }
    .current-color .swatch { width: 22px; height: 22px; }
}

.status-bar {
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    padding: 6px;
    min-height: 24px;
}
.status-bar #status.alert { color: var(--accent); font-weight: 600; }

.player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.player-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.5px;
}
.player.active .player-name { color: var(--accent); }
.player-hand {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    padding: 10px;
    min-height: calc(var(--card-h) + 20px);
    width: 100%;
    max-width: 980px;
    border-radius: 16px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.player.active .player-hand {
    border-color: var(--accent);
    background: rgba(232, 131, 79, 0.08);
    box-shadow: 0 0 24px rgba(232, 131, 79, 0.35);
}
.player-actions {
    display: flex;
    gap: 10px;
    min-height: 36px;
    margin-top: 4px;
}
#eins-button, #challenge-button {
    border-color: transparent;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    transition: background 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
}
#eins-button {
    background: rgba(232, 131, 79, 0.35);
    color: rgba(255, 255, 255, 0.5);
}
#eins-button.armed {
    background: var(--accent);
    color: #1a0e07;
    animation: pulse 1.4s ease infinite;
}
#eins-button.armed:hover { background: #d4703c; }

#challenge-button {
    background: rgba(185, 40, 31, 0.35);
    color: rgba(255, 255, 255, 0.5);
}
#challenge-button.armed {
    background: #b9281f;
    color: white;
    animation: pulse 1.4s ease infinite;
}
#challenge-button.armed:hover { background: #911f17; }
#challenge-button.disabled,
#eins-button.disabled {
    cursor: not-allowed;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* --- Card --- */

.card {
    width: var(--card-w);
    height: var(--card-h);
    border-radius: var(--card-radius);
    background: white;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    user-select: none;
    flex-shrink: 0;
    border: 2px solid white;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card.placeholder {
    background: rgba(255,255,255,0.04);
    border: 2px dashed rgba(255,255,255,0.15);
    box-shadow: none;
}

.card.playable {
    cursor: pointer;
    box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}
.card.playable:hover { transform: translateY(-8px); }

.card.unplayable { opacity: 0.55; }

/* Card back: dark navy with diagonal "Eins" */
.card.back {
    background: linear-gradient(135deg, #1E3A8A 0%, #0F1E4D 100%);
    border-color: #060E2D;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.card.back::before {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.18);
    background:
        repeating-linear-gradient(
            45deg,
            rgba(255,255,255,0.04) 0 6px,
            transparent 6px 12px
        );
}
.card.back .back-text {
    position: relative;
    color: white;
    font-style: italic;
    font-weight: 800;
    font-size: calc(var(--card-w) * 0.32);
    letter-spacing: 1px;
    text-transform: uppercase;
    transform: rotate(-20deg);
    text-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

/* Card fronts */
.card.face {
    background: white;
    display: block;
    padding: 6px;
    border: 2px solid white;
}

.card.face .inner {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.card.face.red .inner { background: var(--red); }
.card.face.yellow .inner { background: var(--yellow); }
.card.face.green .inner { background: var(--green); }
.card.face.blue .inner { background: var(--blue); }

.card.face .center-shape {
    position: absolute;
    top: 22%;
    left: 12%;
    width: 76%;
    height: 56%;
    background: white;
    border-radius: 50% / 50%;
    transform: rotate(-22deg);
    z-index: 1;
}

.card.face .glyph {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(22deg);
    font-weight: 900;
    font-size: calc(var(--card-w) * 0.5);
    line-height: 1;
    color: var(--red);
    text-shadow: 2px 2px 0 rgba(0,0,0,0.15);
    font-family: 'Trebuchet MS', sans-serif;
    z-index: 2;
}
.card.face.red .glyph { color: var(--red); }
.card.face.yellow .glyph { color: var(--yellow); }
.card.face.green .glyph { color: var(--green); }
.card.face.blue .glyph { color: var(--blue); }
.card.face.wild .glyph { color: white; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; }

/* Number cards 3-9 use an N-gon shape behind the digit. */
.card.face.shape-3 .center-shape,
.card.face.shape-4 .center-shape,
.card.face.shape-5 .center-shape,
.card.face.shape-6 .center-shape,
.card.face.shape-7 .center-shape,
.card.face.shape-8 .center-shape,
.card.face.shape-9 .center-shape {
    top: 50%;
    left: 50%;
    width: 96%;
    height: auto;
    aspect-ratio: 1;
    border-radius: 0;
    transform: translate(-50%, -50%);
}
.card.face.shape-3 .glyph,
.card.face.shape-4 .glyph,
.card.face.shape-5 .glyph,
.card.face.shape-6 .glyph,
.card.face.shape-7 .glyph,
.card.face.shape-8 .glyph,
.card.face.shape-9 .glyph {
    transform: none;
    font-size: calc(var(--card-w) * 0.38);
}
.card.face.shape-3 .center-shape { clip-path: polygon(50% 0%, 93.3% 75%, 6.7% 75%); }
.card.face.shape-4 .center-shape { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.card.face.shape-5 .center-shape { clip-path: polygon(50% 0%, 97.55% 34.55%, 79.39% 90.45%, 20.61% 90.45%, 2.45% 34.55%); }
.card.face.shape-6 .center-shape { clip-path: polygon(50% 0%, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%); }
.card.face.shape-7 .center-shape { clip-path: polygon(50% 0%, 89.09% 18.83%, 98.75% 61.13%, 71.69% 95.05%, 28.31% 95.05%, 1.25% 61.13%, 10.91% 18.83%); }
.card.face.shape-8 .center-shape { clip-path: polygon(50% 0%, 85.36% 14.64%, 100% 50%, 85.36% 85.36%, 50% 100%, 14.64% 85.36%, 0% 50%, 14.64% 14.64%); }
.card.face.shape-9 .center-shape { clip-path: polygon(50% 0%, 82.14% 11.7%, 99.24% 41.32%, 93.3% 75%, 67.1% 96.98%, 32.9% 96.98%, 6.7% 75%, 0.76% 41.32%, 17.86% 11.7%); }

.card.face .corner {
    position: absolute;
    color: white;
    font-weight: 800;
    font-size: calc(var(--card-w) * 0.18);
    line-height: 1;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.25);
    z-index: 2;
}
.card.face .corner.tl { top: 8px; left: 10px; }
.card.face .corner.br { bottom: 8px; right: 10px; transform: rotate(180deg); }

/* Wild cards: rainbow quadrants */
.card.face.wild .inner {
    background:
        conic-gradient(
            from 90deg at 50% 50%,
            var(--red) 0deg 90deg,
            var(--blue) 90deg 180deg,
            var(--green) 180deg 270deg,
            var(--yellow) 270deg 360deg
        );
}

.card.face.action .glyph { font-size: calc(var(--card-w) * 0.4); }

/* Modal */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 22px;
    min-width: 280px;
    max-width: 90vw;
    text-align: center;
}
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 14px; color: var(--accent); }
.modal-body {
    margin-bottom: 18px;
    color: var(--text);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 13px;
    text-align: left;
    white-space: pre-wrap;
    line-height: 1.6;
    background: rgba(0,0,0,0.2);
    padding: 12px 16px;
    border-radius: 8px;
    max-width: 420px;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.color-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.color-btn {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.2);
    cursor: pointer;
    transition: transform 0.05s ease;
}
.color-btn:hover { transform: scale(1.04); }
.color-btn.red { background: var(--red); }
.color-btn.yellow { background: var(--yellow); }
.color-btn.green { background: var(--green); }
.color-btn.blue { background: var(--blue); }

/* Action toast (Skip / Reverse / Draw 2 / Draw 4) */

#toast-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
}
.toast {
    background: rgba(15, 23, 42, 0.92);
    border: 2px solid var(--accent);
    color: white;
    padding: 18px 36px;
    border-radius: 14px;
    font-size: 36px;
    font-weight: 900;
    letter-spacing: 4px;
    text-transform: uppercase;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    animation: toast-pop 1.1s ease forwards;
}
.toast.color-red    { border-color: var(--red); }
.toast.color-yellow { border-color: var(--yellow); color: #1a0e07; background: rgba(232,184,79,0.95); }
.toast.color-green  { border-color: var(--green); }
.toast.color-blue   { border-color: var(--blue); }
@keyframes toast-pop {
    0%   { transform: scale(0.4); opacity: 0; }
    20%  { transform: scale(1.15); opacity: 1; }
    35%  { transform: scale(1); opacity: 1; }
    80%  { transform: scale(1); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

/* Animations */
@keyframes flash {
    0% { box-shadow: 0 0 0 0 var(--accent); }
    50% { box-shadow: 0 0 0 6px rgba(232,131,79,0.0); }
    100% { box-shadow: 0 0 0 0 var(--accent); }
}
.flash { animation: flash 0.6s ease; }

.fly-ghost {
    box-shadow: 0 12px 30px rgba(0,0,0,0.55);
}

/* Version footer */
.version-footer {
    text-align: center;
    padding: 12px 16px 18px;
    font-size: 11px;
    color: var(--muted);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

/* Play log under the human's hand */
.play-log {
    width: 100%;
    max-width: 600px;
    margin: 8px auto 0;
    padding: 10px 14px 12px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.play-log-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 4px;
}
.play-log-list {
    font-size: 13px;
    color: var(--muted);
    max-height: 110px;
    overflow-y: auto;
    line-height: 1.5;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.play-log-list .entry { padding: 1px 0; }
.play-log-list .entry.latest {
    color: var(--text);
    font-weight: 600;
}

/* About / How-to-Play */
.about {
    max-width: 720px;
    margin: 32px auto 8px;
    padding: 24px 20px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
    border-top: 1px solid var(--border);
}
.about h2 {
    color: var(--text);
    font-size: 16px;
    margin-top: 18px;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}
.about h2:first-of-type { margin-top: 0; }
.about p, .about ol, .about ul { margin-bottom: 12px; }
.about ol, .about ul { padding-left: 22px; }
.about li { margin-bottom: 4px; }
.about strong { color: var(--text); }

/* Visually-hidden noscript notice when JS is off */
.noscript-banner {
    margin: 60px auto;
    max-width: 600px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 12px;
    text-align: center;
    color: var(--text);
    font-size: 16px;
    line-height: 1.6;
}
.noscript-banner strong { display: block; margin-bottom: 8px; color: var(--accent); }
