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

:root {
    --bg-1: #0f172a;
    --bg-2: #1e293b;
    --panel: rgba(30, 41, 59, 0.8);
    --border: #334155;
    --text: #e2e8f0;
    --text-bright: #f1f5f9;
    --text-dim: #94a3b8;
    --blue: #3b82f6;
    --blue-light: #60a5fa;
    --purple: #8b5cf6;
    --green: #10b981;
    --green-light: #6ee7b7;
    --yellow: #f59e0b;
    --yellow-light: #fcd34d;
    --red: #ef4444;
    --red-light: #fca5a5;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 100%);
    color: var(--text);
    min-height: 100vh;
    padding: 20px;
}

.container { max-width: 1200px; margin: 0 auto; }

button { font-family: inherit; }

/* ---------- Header ---------- */

.header { text-align: center; margin-bottom: 24px; }

h1 {
    font-size: 2.1rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle { font-size: 1.05rem; color: var(--text-dim); }

/* ---------- Start screen ---------- */

.rules {
    background: rgba(59, 130, 246, 0.08);
    border-left: 4px solid var(--blue);
    border-radius: 0 10px 10px 0;
    padding: 18px 22px;
    margin-bottom: 28px;
    color: #cbd5e1;
    font-size: 0.95rem;
    line-height: 1.65;
}
.rules strong { color: var(--blue-light); }

/* Ghost-drag onboarding demo */

.drag-demo {
    position: relative;
    display: flex;
    align-items: center;
    gap: 28px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(148, 163, 184, 0.15);
    min-height: 84px;
    overflow: hidden;
}

.demo-card, .demo-ghost {
    width: 150px;
    text-align: center;
    background: rgba(51, 65, 85, 0.95);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-bright);
    white-space: nowrap;
    flex-shrink: 0;
}
.demo-card { border-style: dashed; opacity: 0.35; }

.demo-grid {
    display: grid;
    grid-template-columns: 48px 48px;
    grid-template-rows: 34px 34px;
    gap: 5px;
    flex-shrink: 0;
}
.demo-grid span { border-radius: 6px; border: 1px solid; }
.demo-grid span:nth-child(1) { background: rgba(245, 158, 11, 0.15); border-color: rgba(245, 158, 11, 0.4); }
.demo-grid span:nth-child(2) { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); }
.demo-grid span:nth-child(3) { background: rgba(16, 185, 129, 0.15); border-color: rgba(16, 185, 129, 0.4); }
.demo-grid span:nth-child(4) { background: rgba(245, 158, 11, 0.15); border-color: rgba(245, 158, 11, 0.4); }

.demo-ghost {
    position: absolute;
    left: 0;
    top: 50%;
    margin-top: -32px;
    opacity: 0;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    animation: demoDrag 5s ease-in-out infinite;
}
@keyframes demoDrag {
    0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10%  { transform: translate(4px, -3px) rotate(-2deg); opacity: 1; }
    55%  { transform: translate(127px, 44px) rotate(0deg); opacity: 1; }
    62%  { transform: translate(127px, 44px); opacity: 0; }
    100% { opacity: 0; }
}

.demo-check {
    position: absolute;
    left: 196px;
    top: 50%;
    margin-top: 4px;
    color: var(--green-light);
    font-weight: 800;
    font-size: 1.05rem;
    opacity: 0;
    animation: demoCheck 5s ease infinite;
}
@keyframes demoCheck {
    0%, 58% { opacity: 0; transform: scale(0.6); }
    66%     { opacity: 1; transform: scale(1.25); }
    78%     { opacity: 1; transform: scale(1); }
    92%, 100% { opacity: 0; transform: scale(1); }
}

.domain-heading {
    text-align: center;
    font-size: 1.15rem;
    color: var(--text-bright);
    margin-bottom: 16px;
}

.domain-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.domain-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    transition: all 0.2s ease;
}
.domain-card:hover {
    transform: translateY(-3px);
    border-color: var(--blue);
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.15);
}
.domain-card .emoji { font-size: 1.8rem; display: block; margin-bottom: 8px; }
.domain-card .name { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; color: var(--text-bright); }
.domain-card .desc { font-size: 0.85rem; color: var(--text-dim); line-height: 1.4; }
.domain-card .best { margin-top: 10px; font-size: 0.78rem; color: var(--green-light); }

/* ---------- Game top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.topbar .back-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--blue-light);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}
.topbar .back-btn:hover { border-color: var(--blue-light); }

.topbar .domain-badge {
    font-weight: 700;
    color: var(--text-bright);
    font-size: 1.05rem;
}

.scoreboard { display: flex; gap: 10px; }

.score-chip {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 16px;
    text-align: center;
}
.score-chip .value { font-weight: 800; font-size: 1.1rem; color: var(--text-bright); }
.score-chip .label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); }
.score-chip.score .value { color: var(--green-light); }

/* ---------- Board layout ---------- */

.board {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    align-items: start;
}

/* Card tray */

.tray {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    max-height: 640px;
    overflow-y: auto;
}

.tray-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#trayCount {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: var(--blue-light);
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 0.7rem;
    letter-spacing: 0.3px;
}

.cards-scroller { display: flex; flex-direction: column; }

.tray-hint { font-size: 0.75rem; color: #7c8aa0; margin-top: 10px; line-height: 1.5; text-transform: none; letter-spacing: 0; }

.mini-card {
    background: rgba(51, 65, 85, 0.6);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: border-color 0.15s ease, transform 0.15s ease, opacity 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}
.mini-card:hover { border-color: var(--blue-light); }
.mini-card:focus-visible {
    outline: 2px solid var(--blue-light);
    outline-offset: 2px;
}
.mini-card.selected {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
    transform: scale(1.02);
}
.mini-card.dragging { opacity: 0.4; }

.mini-card .card-title {
    flex: 1;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-bright);
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    color: var(--text-dim);
    padding: 4px;
    border-radius: 6px;
    flex-shrink: 0;
}
.icon-btn:hover { color: var(--blue-light); background: rgba(59, 130, 246, 0.12); }

/* Result badges on cards */

.badge {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}
.badge.correct { background: var(--green); }
.badge.wrong { background: var(--red); animation: pulseWrong 1.5s ease-out infinite; }
.badge:hover { transform: scale(1.15); }

@keyframes pulseWrong {
    0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    70%  { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* The 2x2 grid */

.grid-area { min-width: 0; }

.grid-wrapper {
    position: relative;
    display: grid;
    grid-template-columns: 44px 1fr 1fr;
    grid-template-rows: 1fr 1fr 44px;
    gap: 10px;
}

/* Faint 1px cross in the gap between quadrants, like a real 2x2 */
.grid-lines {
    position: absolute;
    left: 54px;
    right: 0;
    top: 0;
    bottom: 54px;
    pointer-events: none;
    background:
        linear-gradient(rgba(148, 163, 184, 0.3), rgba(148, 163, 184, 0.3)) center / 100% 1px no-repeat,
        linear-gradient(rgba(148, 163, 184, 0.3), rgba(148, 163, 184, 0.3)) center / 1px 100% no-repeat;
}

.axis-label {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.axis-y { grid-row: 1 / 3; gap: 7px; }
.axis-y .axis-text { writing-mode: vertical-rl; transform: rotate(180deg); }
.axis-y .axis-track {
    align-self: stretch;
    width: 2px;
    margin: 14px 0 4px;
    border-radius: 1px;
    background: linear-gradient(to top, rgba(148, 163, 184, 0.12), rgba(148, 163, 184, 0.6));
    position: relative;
}
.axis-y .axis-track::before {
    content: '';
    position: absolute;
    top: -9px;
    left: -4px;
    border: 5px solid transparent;
    border-top: none;
    border-bottom: 9px solid rgba(148, 163, 184, 0.7);
}

.axis-x { grid-column: 2 / 4; flex-direction: column; gap: 7px; }
.axis-x .axis-track {
    align-self: stretch;
    height: 2px;
    margin: 2px 18px 0 4px;
    border-radius: 1px;
    background: linear-gradient(to right, rgba(148, 163, 184, 0.12), rgba(148, 163, 184, 0.6));
    position: relative;
}
.axis-x .axis-track::before {
    content: '';
    position: absolute;
    right: -9px;
    top: -4px;
    border: 5px solid transparent;
    border-right: none;
    border-left: 9px solid rgba(148, 163, 184, 0.7);
}

.quadrant {
    border-radius: 14px;
    padding: 14px;
    border: 2px solid transparent;
    min-height: 220px;
    transition: border-color 0.2s ease, background 0.2s ease;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 0 30px rgba(0, 0, 0, 0.12);
}
.quadrant.green { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.4); }
.quadrant.yellow { background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.4); }
.quadrant.red { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); }

.quadrant.drop-ready { border-style: dashed; border-color: rgba(255, 255, 255, 0.55); }
.quadrant.drag-over {
    border-color: #fff;
    border-style: solid;
    outline: 2px dashed rgba(255, 255, 255, 0.9);
    outline-offset: 4px;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
    transform: scale(1.01);
}

.quadrant-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 4px;
}
.quadrant-title { font-size: 0.98rem; font-weight: 700; line-height: 1.3; }
.quadrant.green .quadrant-title { color: var(--green-light); }
.quadrant.yellow .quadrant-title { color: var(--yellow-light); }
.quadrant.red .quadrant-title { color: var(--red-light); }
.quadrant-sub {
    align-self: flex-start;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    padding: 2px 9px;
    margin-bottom: 10px;
}

.quadrant .cards {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.quadrant .mini-card { margin-bottom: 0; padding: 8px 10px; }
.quadrant .mini-card.locked { cursor: default; }
.quadrant .mini-card.locked:hover { border-color: var(--border); }

/* ---------- Feedback toast ---------- */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 0.92rem;
    color: var(--text-bright);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 60;
    max-width: 90vw;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.correct { border-color: var(--green); }
.toast.wrong { border-color: var(--red); }

/* ---------- Modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.2s ease; }

.modal {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    max-width: 540px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    animation: popIn 0.25s ease;
}
.modal.green { border-color: rgba(16, 185, 129, 0.5); }
.modal.yellow { border-color: rgba(245, 158, 11, 0.5); }
.modal.red { border-color: rgba(239, 68, 68, 0.5); }

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}
.modal-close:hover { color: var(--text-bright); }

.modal h3 { font-size: 1.2rem; margin-bottom: 4px; color: var(--text-bright); }
.modal .modal-kicker {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    color: var(--blue-light);
    margin-bottom: 8px;
}
.modal p { color: #cbd5e1; line-height: 1.65; font-size: 0.95rem; margin-bottom: 12px; }
.modal ul { margin: 0 0 12px 20px; color: #cbd5e1; line-height: 1.65; font-size: 0.92rem; }
.modal .rule-line { font-size: 0.88rem; color: var(--text-dim); font-style: italic; }

/* ---------- Results overlay ---------- */

.results-card { text-align: center; max-width: 620px; }

.score-big {
    font-size: 3.6rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 6px;
}
.score-caption { color: var(--text-dim); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 14px; }
.results-msg { color: #cbd5e1; line-height: 1.7; margin-bottom: 20px; text-align: left; }

.recap { text-align: left; margin-bottom: 20px; }
.recap-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 0.88rem;
}
.recap-row:nth-child(odd) { background: rgba(51, 65, 85, 0.35); }
.recap-row .mark { font-weight: 800; width: 20px; text-align: center; }
.recap-row .mark.ok { color: var(--green-light); }
.recap-row .mark.miss { color: var(--red-light); }
.recap-row .r-title { flex: 1; color: var(--text-bright); }
.recap-row .r-quad { color: var(--text-dim); font-size: 0.8rem; }

.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.primary-btn, .secondary-btn {
    padding: 13px 30px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    color: #fff;
}
.primary-btn { background: linear-gradient(135deg, var(--green), #059669); }
.secondary-btn { background: linear-gradient(135deg, var(--blue), #1d4ed8); }
.primary-btn:hover, .secondary-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); }

/* ---------- Animations ---------- */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
    from { opacity: 0; transform: scale(0.94) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
.mini-card.shake { animation: shake 0.3s ease; }

@keyframes popCorrect {
    0% { transform: scale(1); }
    50% { transform: scale(1.06); }
    100% { transform: scale(1); }
}
.mini-card.pop { animation: popCorrect 0.35s ease; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
    body { padding: 12px; }
    .board { grid-template-columns: 1fr; }

    .tray { max-height: none; overflow: visible; }
    .tray .cards-scroller {
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 6px;
        scroll-snap-type: x proximity;
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
        mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    }
    .tray .mini-card { min-width: 170px; margin-bottom: 0; scroll-snap-align: start; }

    .grid-wrapper { grid-template-columns: 34px 1fr 1fr; }
    .grid-lines { left: 44px; }
    .quadrant { min-height: 170px; padding: 10px; }
    .quadrant-title { font-size: 0.85rem; }
    .quadrant-sub { font-size: 0.62rem; padding: 2px 7px; }
    h1 { font-size: 1.6rem; }

    .drag-demo { gap: 16px; }
    .demo-card, .demo-ghost { width: 130px; font-size: 0.7rem; }
    @keyframes demoDrag {
        0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
        10%  { transform: translate(4px, -3px) rotate(-2deg); opacity: 1; }
        55%  { transform: translate(105px, 44px) rotate(0deg); opacity: 1; }
        62%  { transform: translate(105px, 44px); opacity: 0; }
        100% { opacity: 0; }
    }
    .demo-check { left: 162px; }
}

@media (prefers-reduced-motion: reduce) {
    .demo-ghost { animation: none; opacity: 0; }
    .demo-check { animation: none; opacity: 1; }
    .badge.wrong { animation: none; }
    .mini-card.shake, .mini-card.pop { animation: none; }
}
