:root {
    --bg: #0b0710;
    --card: #0f1222;
    --accent: #b98eff;
    --title: #ffffff;
    --muted: #cfc9e6;
    --glass: rgba(255, 255, 255, 0.04);
    --card-back: linear-gradient(135deg, #0d0a18 0%, #221b34 100%);
    --sidebar-w: 420px;
    --gap: 24px;
}

/* ========== Base / Mobile-first ========== */
* {
    box-sizing: border-box
}

html, body {
    height: 100%;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    /* background:
        radial-gradient(ellipse at 10% 10%, rgba(185, 142, 255, 0.06), transparent 10%),
        radial-gradient(ellipse at 90% 90%, rgba(0, 190, 255, 0.03), transparent 10%),
        var(--bg); */
    color: var(--muted)
}

body{
    background-image: url('bg.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    background-attachment: fixed;
}

.container {
    max-width: 1100px;
    margin: 100px auto;
    padding: 20px;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(21, 1, 134, 0.3), rgba(21, 1, 134, 0.1));
    box-shadow: 0 6px 40px rgba(0, 0, 0, 0.7);
    display: grid;
    grid-template-columns: 1fr;
    /* mobile: single column */
    gap: var(--gap);
}

/* header stays compact on mobile */
header {
    display: flex;
    gap: 12px;
    align-items: center;
}

header>div:first-child {
    width: 54px;
    height: 54px;
    border-radius: 10px;
    background: linear-gradient(135deg, #30163f, #6b39a9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: white;
}

header h1 {
    margin: 0;
    font-size: 18px
}

header p {
    margin: 0;
    color: #bfb6e9;
    font-size: 13px
}

/* controls (mobile): below header and full width */
.controls {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
}

/* board (grid of 3x3) */
.board {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0.005));
    padding: 14px;
    border-radius: 12px;
    display: grid;
    grid-template-rows: repeat(3, 150px);
    gap: 14px;
    align-items: center;
    justify-items: center;
}

/* rows */
.row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}

/* card */
.card {
    width: 100%;
    height: 280px;
    border-radius: 10px;
    perspective: 1000px;
    display: flex;
    cursor: pointer;
    max-width: 340px;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform .9s cubic-bezier(.2, .9, .3, 1);
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.face {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-shadow: inset 0 -10px 30px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    background-size: cover;
    background-position: center;
}

.back {
    background: var(--card-back);
    border: 1px solid rgba(255, 255, 255, 0.02);
    color: transparent;
}

.front {
    transform: rotateY(180deg);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
    border: 1px solid rgba(255, 255, 255, 0.03);
    display: block;
}

/* image wrapper inside card faces */
.card .img-wrap {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    overflow: hidden;
}

.card .img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    user-select: none;
}

/* caption overlay at bottom of front */
.card .caption {
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 10px 12px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.6));
    color: var(--muted);
    box-sizing: border-box;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

.card .card-title {
    font-weight: 700;
    color: var(--title);
    margin: 0;
    font-size: 15px;
}

.card .card-sub {
    font-size: 12px;
    color: #d6cff0;
    margin-top: 6px;
}

/* sidebar */
.sidebar {
    padding: 16px;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0.005));
    max-height: 720px;
    overflow: auto;
}

.reading h2 {
    margin: 0 0 10px 0;
    font-size: 18px
}

.reading .summary {
    font-size: 14px;
    color: #e6e0ff;
    margin-bottom: 12px
}

.card-meaning {
    background: var(--glass);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 10px;
    border: 1px solid rgba(255, 255, 255, 0.02)
}

.position {
    font-weight: 700;
    color: #fff;
    margin-bottom: 6px
}

/* buttons */
.btn {
    background: linear-gradient(90deg, var(--accent), #6ad1ff);
    border: none;
    padding: 10px 14px;
    border-radius: 8px;
    color: #0b0710;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(88, 19, 145, 0.2)
}

.btn.ghost {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--muted)
}

/* footer */
footer {
    color: #9b91c7;
    font-size: 13px
}

/* stars */
.stars {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    mix-blend-mode: screen
}

.stars::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(1px 1px at 10% 10%, rgba(255, 255, 255, 0.03), transparent 0), radial-gradient(1px 1px at 70% 20%, rgba(255, 255, 255, 0.02), transparent 0);
    opacity: 0.6
}

/* small screens tweak: reduce font + card rows */
@media (max-width:420px) {
    .board {
        grid-template-rows: repeat(3, 120px);
        gap: 10px
    }

    .card .card-title {
        font-size: 13px
    }

    .card .card-sub {
        font-size: 11px
    }
}

/* ========== Desktop / larger screens ========== */
@media (min-width: 981px) {

    /* two-column layout */
    .container {
        grid-template-columns: 1fr var(--sidebar-w);
        align-items: start;
    }

    /* place header full width */
    header {
        grid-column: 1 / 2;
    }

    /* place controls in the right column (even though it's a sibling in DOM)
     using grid placement so visual position is in top-right */
    .controls {
        grid-column: 2 / 3;
        justify-self: end;
        align-self: start;
        margin-top: 6px;
    }

    /* board in left column */
    .board {
        grid-column: 1 / 2;
        padding: 20px;
        grid-template-rows: repeat(3, 180px);
        gap: 18px
    }

    /* sidebar fixed in right column */
    .sidebar {
        grid-column: 2 / 3;
        max-height: 760px
    }

    /* header occupies full width above both columns */
    header {
        grid-column: 1 / -1;
        display: flex;
        align-items: center;
        gap: 16px
    }

    /* enlarge typography on desktop */
    header h1 {
        font-size: 20px
    }

    header p {
        font-size: 14px
    }

    /* allow cards to be larger on desktop but keep max width */
    .card {
        max-width: 280px
    }

    .row {
        gap: 16px
    }

    /* make controls inline and slightly larger */
    .controls {
        gap: 12px
    }

    /* ensure footer spans both columns */
    footer {
        grid-column: 1 / -1;
        margin-top: 8px;
    }
}

/* accessibility focus */
.btn:focus, .card:focus {
    outline: 3px solid rgba(185, 142, 255, 0.18);
    outline-offset: 2px;
}


@media(max-width: 750px) {
    .board {
        gap: 5px;
    }

    .card {
        height: 150px;
    }
}