/* ConfigIt styles: well-styled styles that style the style out of things */

:root {
    --ink: #101017;
    --bg: #0f0f15;
    --surface: #17171f;
    --surface-2: #1e1e29;
    --line: #2b2b38;
    --text: #ecebf2;
    --muted: #8b8799;
    --s: #8bd3f0;
    --p: #8fe3ae;
    --d: #f2a7cd;
    --f: #f5b586;
    --good: #4ade80;
    --bad: #ef5d78;
    --accent: #f5c85b;
    --mono:
        ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
    --ease: cubic-bezier(0.2, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: system-ui, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.app {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 8px;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 14px 18px 16px;
    min-height: 100dvh;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 22px;
}

.progress {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.02em;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.link-btn {
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    background: none;
    border: 0;
    padding: 3px 0;
    cursor: pointer;
    text-decoration: none;
}

.link-btn:hover {
    color: var(--text);
}

.link-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.hearts {
    display: flex;
    gap: 4px;
    font-size: 15px;
    line-height: 1;
}

.heart {
    color: var(--bad);
}

.heart.is-empty {
    color: #35323f;
}

/* ---------- configuration strip ---------- */

.config-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    min-height: 62px;
}

.tag {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.tag[data-mode="noble"] {
    color: var(--accent);
    border-color: rgba(245, 200, 91, 0.45);
}

.config-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    min-height: 38px;
}

.chip {
    display: inline-flex;
    align-items: baseline;
    font-family: var(--mono);
    font-size: clamp(16px, 1.5vw, 21px);
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    animation: chip-in 0.18s var(--ease) both;
}

.chip sup {
    font-size: 0.62em;
    margin-left: 1px;
}

.chip.is-noble {
    color: var(--accent);
    border-color: rgba(245, 200, 91, 0.4);
    background: rgba(245, 200, 91, 0.07);
}

.chip.is-revealed {
    color: #edaab6;
    border-style: dashed;
    border-color: rgba(239, 93, 120, 0.5);
    background: transparent;
}

.bracket {
    opacity: 0.6;
}

.caret {
    width: 2px;
    height: 22px;
    background: var(--accent);
    animation: blink 1s steps(2, start) infinite;
}

.timer {
    display: flex;
    align-items: center;
    gap: 9px;
    justify-self: end;
}

.timer-track {
    width: 92px;
    height: 4px;
    border-radius: 2px;
    background: #2a2a36;
    overflow: hidden;
}

.timer-fill {
    height: 100%;
    width: 100%;
    transform-origin: left center;
    background: var(--muted);
    transition: transform 0.08s linear;
}

.timer-fill.is-low {
    background: var(--bad);
}

.timer-num {
    font-family: var(--mono);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    min-width: 42px;
    text-align: right;
    color: var(--muted);
}

/* ---------- board ---------- */

.board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 8px;
    min-height: 0;
}

.table-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    min-width: 0;
}

.ptable {
    display: grid;
    grid-template-columns: repeat(18, minmax(0, 1fr));
    gap: 3px;
    margin: 0;
    padding: 0;
    list-style: none;
    align-content: start;
    min-width: 0;
}

.cell {
    container-type: size;
    position: relative;
    aspect-ratio: 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    background: var(--tile);
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
    overflow: hidden;
}

.cell[data-block="s"] {
    --tile: #8bd3f0;
}
.cell[data-block="p"] {
    --tile: #8fe3ae;
}
.cell[data-block="d"] {
    --tile: #f2a7cd;
}
.cell[data-block="f"] {
    --tile: #f5b586;
}

.cell .num {
    position: absolute;
    top: 5cqw;
    left: 8cqw;
    font-family: var(--mono);
    font-size: 20cqw;
    font-weight: 600;
    opacity: 0.55;
}

.cell .sym {
    font-size: 35cqw;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
}

.cell::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
}

.cell.is-perfect {
    box-shadow:
        inset 0 0 0 2px #2f7d4f,
        inset 0 -2px 0 rgba(0, 0, 0, 0.16);
}

.cell.is-perfect::after {
    content: "\2713";
    inset: auto 4cqw auto auto;
    top: 0;
    width: auto;
    height: auto;
    font-size: 32cqw;
    font-weight: 700;
    color: #14532d;
}

.cell.is-tried {
    box-shadow:
        inset 0 0 0 2px #93641d,
        inset 0 -2px 0 rgba(0, 0, 0, 0.16);
}

.cell.is-tried::after {
    content: "\2713";
    inset: auto 4cqw auto auto;
    top: 0;
    width: auto;
    height: auto;
    font-size: 32cqw;
    font-weight: 700;
    color: #7c2d12;
}

.cell.is-current {
    outline: 2px solid #fff;
    outline-offset: 1px;
    z-index: 2;
}

.cell.series {
    container-type: normal;
    background: transparent;
    box-shadow: none;
    color: #55526a;
    font-family: var(--mono);
    font-size: 9px;
    white-space: nowrap;
}

.spacer {
    grid-column: 1 / -1;
    height: 6px;
    list-style: none;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.swatch {
    width: 9px;
    height: 9px;
    border-radius: 2px;
}

.swatch[data-block="s"] {
    background: var(--s);
}
.swatch[data-block="p"] {
    background: var(--p);
}
.swatch[data-block="d"] {
    background: var(--d);
}
.swatch[data-block="f"] {
    background: var(--f);
}

.legend-tick {
    font-style: normal;
    font-weight: 700;
    color: var(--good);
}

.legend-tick.tried {
    color: #c98a3a;
}

/* ---------- element card ---------- */

.element-card {
    display: flex;
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    min-width: 0;
}

.portrait {
    container-type: size;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    aspect-ratio: 1 / 1;
    align-self: center;
    padding: 9% 8% 7%;
    border-radius: 6px;
    overflow: hidden;
    background: var(--tile);
    color: var(--ink);
}

.portrait[data-block="s"] {
    --tile: #a8dcf3;
}
.portrait[data-block="p"] {
    --tile: #a6e8c0;
}
.portrait[data-block="d"] {
    --tile: #f6bcd8;
}
.portrait[data-block="f"] {
    --tile: #f8c69c;
}

.p-num {
    position: absolute;
    top: 7%;
    left: 8%;
    font-family: var(--mono);
    font-size: max(10px, 6cqw);
    font-weight: 600;
    opacity: 0.5;
    line-height: 1;
}

.eyes {
    width: 62%;
    flex: none;
    overflow: visible;
    pointer-events: none;
}

.p-sym {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(38cqw, 30cqh);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.04em;
}

.p-name {
    font-family: var(--mono);
    font-size: max(9px, 4.4cqw);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.65;
    line-height: 1.2;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* the eyes read the round: brows rise with the clock, pupils follow the pointer */

.pupil {
    animation: look 5.2s ease-in-out infinite;
}

.eye:last-of-type .pupil {
    animation-delay: -1.4s;
}

.brow {
    stroke: #14121b;
    stroke-width: 7;
    stroke-linecap: round;
    opacity: calc(var(--anger, 0) * 0.95);
    transform-box: fill-box;
}

.brow-l {
    transform-origin: 0% 50%;
    transform: rotate(calc(var(--anger, 0) * 22deg));
}

.brow-r {
    transform-origin: 100% 50%;
    transform: rotate(calc(var(--anger, 0) * -22deg));
}

.portrait::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: inset 0 0 38px rgba(239, 93, 120, calc(var(--anger, 0) * 0.5));
}

.portrait.is-angry .pupil {
    animation: none;
    transform: translate(0, 2px);
}

.portrait.is-tracking .pupil {
    animation: none;
    transform: translate(var(--look-x, 0px), var(--look-y, 0px));
}

.portrait.is-hurt {
    animation: wince 0.5s var(--ease);
}

.portrait.is-hurt .eye {
    animation: eyes-wince 0.55s var(--ease);
    transform-box: fill-box;
    transform-origin: center;
}

/* click the card: the eyes close into a grin */

.eye .happy {
    opacity: 0;
}

.portrait.is-happy .eye circle {
    opacity: 0;
}

.portrait.is-happy .eye .happy {
    opacity: 1;
}

.portrait.is-happy .brow {
    opacity: 0;
}

.portrait.is-happy {
    animation: happy-hop 0.6s var(--ease);
}

.portrait.is-happy .eye {
    animation: none;
}

/* ---------- choices ---------- */

.choices {
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.prompt {
    margin: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

.options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.option {
    position: relative;
    font-family: var(--mono);
    font-size: clamp(19px, 1.9vw, 26px);
    font-weight: 600;
    color: var(--text);
    padding: 17px 10px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    cursor: pointer;
    transition:
        border-color 0.12s var(--ease),
        background 0.12s var(--ease),
        transform 0.12s var(--ease);
}

.option sup {
    font-size: 0.62em;
    margin-left: 1px;
}

.option:hover:not(.is-correct):not(.is-wrong) {
    border-color: #4a4a5c;
    background: #242432;
    transform: translateY(-1px);
}

.option:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.opt-key {
    position: absolute;
    top: 6px;
    left: 8px;
    font-size: 9px;
    font-weight: 600;
    color: #5d596e;
}

.option.is-correct {
    border-color: var(--good);
    background: rgba(74, 222, 128, 0.1);
    animation: pop 0.2s var(--ease);
}

.option.is-wrong {
    border-color: var(--bad);
    background: rgba(239, 93, 120, 0.1);
    animation: shake 0.36s var(--ease);
}

/* ---------- pdf viewer ---------- */

.pdf-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    padding: 16px;
    background: rgba(8, 8, 12, 0.88);
}

.pdf-overlay[hidden] {
    display: none;
}

.pdf-card {
    display: flex;
    flex-direction: column;
    width: min(1080px, 100%);
    height: 100%;
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}

.pdf-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
}

.pdf-head h2 {
    margin: 0;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.pdf-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.pdf-close {
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 5px 12px;
    cursor: pointer;
}

.pdf-close:hover {
    border-color: #4a4a5c;
}

.pdf-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.pdf-frame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #fff;
}

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

.overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(8, 8, 12, 0.84);
}

.overlay[hidden] {
    display: none;
}

.overlay-card {
    width: min(420px, 100%);
    padding: 24px 26px 22px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #17171f;
    text-align: left;
}

.overlay-card h1 {
    margin: 0 0 8px;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.overlay-card p {
    margin: 0 0 20px;
    color: var(--muted);
    line-height: 1.55;
    font-size: 13px;
}

.primary-btn {
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    color: var(--ink);
    background: var(--text);
    border: 0;
    border-radius: 6px;
    padding: 10px 22px;
    cursor: pointer;
}

.primary-btn:hover {
    background: #fff;
}

.primary-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- motion ---------- */

@keyframes chip-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes pop {
    0% {
        transform: scale(0.97);
    }
    60% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-6px);
    }
    40% {
        transform: translateX(5px);
    }
    60% {
        transform: translateX(-3px);
    }
    80% {
        transform: translateX(2px);
    }
}

@keyframes wince {
    0% {
        transform: scaleY(1) translateX(0);
    }
    12% {
        transform: scaleY(0.9) translateX(-6px);
    }
    28% {
        transform: scaleY(0.9) translateX(5px);
    }
    46% {
        transform: scaleY(0.95) translateX(-3px);
    }
    64% {
        transform: scaleY(0.98) translateX(2px);
    }
    100% {
        transform: scaleY(1) translateX(0);
    }
}

@keyframes happy-hop {
    0% {
        transform: translateY(0) scale(1);
    }
    28% {
        transform: translateY(-7px) scale(1.025);
    }
    55% {
        transform: translateY(2px) scale(0.995);
    }
    78% {
        transform: translateY(-2px) scale(1.005);
    }
    100% {
        transform: translateY(0) scale(1);
    }
}

@keyframes eyes-wince {
    0%,
    100% {
        transform: scaleY(1);
    }
    18% {
        transform: scaleY(0.25);
    }
    42% {
        transform: scaleY(0.2);
    }
    70% {
        transform: scaleY(0.62);
    }
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

@keyframes look {
    0%,
    100% {
        transform: translate(2px, 1px);
    }
    25% {
        transform: translate(-3px, 2px);
    }
    50% {
        transform: translate(1px, -2px);
    }
    75% {
        transform: translate(4px, 2px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* ---------- narrow screens ---------- */

@media (max-width: 1080px) {
    .board {
        grid-template-columns: minmax(0, 1fr);
    }

    .element-card {
        justify-content: center;
    }

    .portrait {
        width: 180px;
        flex: none;
    }
}

@media (max-width: 820px) {
    .cell.series {
        display: none;
    }
}

@media (max-width: 720px) {
    .app {
        padding: 8px;
    }

    .config-row {
        grid-template-columns: auto minmax(0, 1fr);
        row-gap: 6px;
    }

    .timer {
        grid-column: 1 / -1;
        justify-self: stretch;
        justify-content: flex-end;
    }

    .options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
