/* ==========================================================================
   The Mystery Book (/play): the daily guessing game, on the site's paper and ink
   (paper.css). A closed cloth-bound book that opens to the day's cover, clue
   slips, a guess box and the result. Logical properties only: one sheet for
   Hebrew (RTL) and the left-to-right languages.
   ========================================================================== */

.play {
    --cloth: #7d2620;
    --cloth-deep: #5d1a15;
    --foil: #ecd9a8;
    --right: #2e6b3f;
    --near: #c9962a;
    --wrong: #b3372f;
    --skip: #8b857a;
    --spine-side: 90deg; /* the spine is where the lines begin: see the RTL rule below */
    max-width: 1040px;
    margin: 0 auto;
    padding-block: 1.5rem 3rem;
}

/* --------------------------------------------------------------------------
   Masthead
   -------------------------------------------------------------------------- */

.play-page .main-content {
    padding-top: 1.5rem;
}

[dir="rtl"] .play {
    --spine-side: 270deg;
}

.play-head {
    text-align: center;
    margin-bottom: 1.5rem;
}

.play-kicker {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem 0.9rem;
    margin: 0 0 0.4rem;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

.play-kicker > * + *::before {
    content: "·";
    margin-inline-end: 0.9rem;
    color: var(--ink-soft);
}

.play-title {
    font-family: var(--display);
    font-weight: 900;
    font-size: clamp(2.3rem, 7vw, 4.25rem);
    line-height: 1.05;
    margin: 0 0 0.6rem;
}

.play-lead {
    max-width: 34rem;
    margin: 0 auto;
    font-size: 1.1rem;
    line-height: 1.5;
    color: var(--ink-soft);
}

.play-archive-note {
    margin: 0.9rem 0 0;
    font-size: 0.95rem;
    color: var(--ink-soft);
}

.play-archive-note a {
    color: var(--accent);
    font-weight: 700;
}

/* --------------------------------------------------------------------------
   Board: the book beside the clues (stacked on a phone)
   -------------------------------------------------------------------------- */

.play-board {
    display: grid;
    gap: 1.5rem;
    justify-items: center;
}

.play-main {
    width: 100%;
    max-width: 40rem;
}

.play-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
}

@media (min-width: 900px) {
    .play-board {
        grid-template-columns: 300px minmax(0, 1fr);
        gap: 3.5rem;
        align-items: start;
        justify-items: stretch;
        margin-top: 2.5rem;
    }

    .play-stage {
        position: sticky;
        top: 6.5rem;
    }
}

/* --------------------------------------------------------------------------
   The book: cloth cover with a foil question mark; turns over to the real cover
   -------------------------------------------------------------------------- */

.play-book {
    width: clamp(132px, 36vw, 250px);
    aspect-ratio: 2 / 3;
    perspective: 1400px;
    scroll-margin-top: 5.5rem; /* clear of the sticky header when the round ends */
    filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.28));
    transition: width 0.7s var(--ease-out);
}

.play-book-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 1.25s cubic-bezier(0.3, 1.25, 0.4, 1);
    animation: play-float 6s ease-in-out infinite;
}

.play-book-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
    border-radius: 4px;
}

.play-book-front {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--foil);
    background:
        linear-gradient(var(--spine-side), rgba(0, 0, 0, 0.38) 0, rgba(0, 0, 0, 0) 7%, rgba(255, 255, 255, 0.09) 9%, rgba(0, 0, 0, 0) 13%),
        radial-gradient(120% 90% at 30% 20%, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0) 60%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
        linear-gradient(160deg, var(--cloth), var(--cloth-deep));
}

/* Double foil frame pressed into the cloth */
.play-book-front::before,
.play-book-front::after {
    content: "";
    position: absolute;
    inset-block: 7%;
    inset-inline: 12% 8%;
    border: 2px solid var(--foil);
    opacity: 0.85;
    pointer-events: none;
}

.play-book-front::after {
    inset-block: 9.5%;
    inset-inline: 15% 11%;
    border-width: 1px;
    opacity: 0.6;
}

.play-book-mark {
    font-family: var(--display);
    font-weight: 900;
    font-size: clamp(4.5rem, 20vw, 9rem);
    line-height: 1;
    margin-inline-start: 4%;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
    animation: play-glint 3.2s ease-in-out infinite;
}

.play-book-site {
    position: absolute;
    inset-block-end: 13%;
    inset-inline: 16% 12%;
    text-align: center;
    font-family: var(--display);
    font-size: clamp(0.55rem, 1.9vw, 0.85rem);
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    opacity: 0.85;
}

.play-book-back {
    transform: rotateY(180deg);
    background: var(--paper-deep);
    border: var(--frame);
    border-radius: 2px;
}

.play-book-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.play-book.is-open {
    width: clamp(190px, 56vw, 300px);
}

.play-book.is-open .play-book-inner {
    transform: rotateY(180deg);
    animation: none;
}

.play-book.is-instant,
.play-book.is-instant .play-book-inner {
    transition: none;
}

.play-book.is-shaking .play-book-inner {
    animation: play-shake 0.5s ease;
}

@keyframes play-float {
    0%, 100% { transform: translateY(0) rotateY(-9deg); }
    50% { transform: translateY(-7px) rotateY(9deg); }
}

@keyframes play-glint {
    0%, 100% { opacity: 0.86; }
    50% { opacity: 1; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 0 22px rgba(236, 217, 168, 0.65); }
}

@keyframes play-shake {
    0%, 100% { transform: translateX(0) rotate(0); }
    20% { transform: translateX(-10px) rotate(-3deg); }
    40% { transform: translateX(9px) rotate(3deg); }
    60% { transform: translateX(-6px) rotate(-2deg); }
    80% { transform: translateX(4px) rotate(1deg); }
}

/* --------------------------------------------------------------------------
   Pips: one square per clue, stamped with what the guess was
   -------------------------------------------------------------------------- */

.play-pips {
    display: flex;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.play-pips li,
.play-pip {
    width: 1.6rem;
    height: 1.6rem;
    border: var(--frame);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 900;
    line-height: 1;
    color: #fff;
    transition: background-color 0.3s ease, transform 0.35s var(--ease-out);
}

.play-pips li.is-next {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.is-wrong { --pip: var(--wrong); }
.is-author { --pip: var(--near); }
.is-skip { --pip: var(--skip); }
.is-right { --pip: var(--right); }

.play-pips li[class*="is-"]:not(.is-next),
.play-pip {
    background: var(--pip);
    border-color: var(--pip);
}

.play-pips li.is-new {
    animation: play-stamp 0.45s var(--ease-out);
}

@keyframes play-stamp {
    from { transform: scale(2.1) rotate(-14deg); opacity: 0; }
    to { transform: none; opacity: 1; }
}

/* --------------------------------------------------------------------------
   Clue slips
   -------------------------------------------------------------------------- */

.play-clue {
    position: relative;
    border: var(--frame);
    background: var(--paper);
    padding: 1.1rem 1.4rem 1.3rem;
}

.play-clue.is-current {
    box-shadow: 0 0 0 4px var(--paper), 0 0 0 5px var(--rule);
    margin: 5px;
    padding: 1.3rem 1.5rem 1.6rem;
    min-height: 9.5rem;
}

.play-clue.is-new {
    animation: play-unfold 0.6s var(--ease-out) both;
    transform-origin: 50% 0;
}

@keyframes play-unfold {
    from { opacity: 0; transform: perspective(900px) rotateX(-55deg) translateY(-8px); }
    to { opacity: 1; transform: none; }
}

.play-clue-label {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.75rem;
    margin: 0 0 0.65rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.play-clue-no {
    color: var(--accent);
}

.play .play-clue-text {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    font-family: var(--display);
    font-size: clamp(1.3rem, 3.4vw, 1.7rem);
    line-height: 1.45;
    color: var(--ink);
    text-align: start;
    text-wrap: pretty;
}

.play-clue-text::before { content: open-quote; }
.play-clue-text::after { content: close-quote; }

.play-facts {
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: var(--display);
    font-size: clamp(1.15rem, 3vw, 1.4rem);
}

.play-facts li {
    padding-block: 0.4rem;
}

.play-facts li + li {
    border-top: 1px solid var(--rule-soft);
}

.play-author {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    font-family: var(--display);
    font-weight: 900;
    font-size: clamp(1.5rem, 4.4vw, 2.1rem);
    line-height: 1.2;
}

.play-author img {
    width: 5.25rem;
    height: 6.5rem;
    object-fit: cover;
    border: var(--frame);
    filter: grayscale(1) contrast(1.05);
    flex: none;
}

/* --------------------------------------------------------------------------
   Guess box
   -------------------------------------------------------------------------- */

.play-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.6rem;
    margin-top: 1.2rem;
}

.play-combo {
    position: relative;
}

.play-input {
    width: 100%;
    height: 100%;
    min-height: 3.1rem;
    border: var(--frame);
    border-radius: 0;
    background: var(--paper);
    color: var(--ink);
    padding: 0.6rem 0.9rem;
    font-size: 1.1rem;
    font-family: inherit;
}

.play-input::placeholder {
    color: var(--ink-soft);
    opacity: 0.8;
}

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

.play-guess-btn {
    cursor: pointer;
    font-size: 1.05rem;
}

.play-options {
    position: absolute;
    z-index: 20;
    inset-inline: 0;
    inset-block-start: calc(100% + 4px);
    max-height: 17rem;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
    background: var(--paper);
    border: var(--frame);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

.play-options li {
    padding: 0.5rem 0.9rem;
    cursor: pointer;
    line-height: 1.3;
    border-bottom: 1px solid var(--rule-soft);
}

.play-options li:last-child {
    border-bottom: 0;
}

.play-options li strong {
    display: block;
    font-family: var(--display);
    font-size: 1.1rem;
}

.play-options li span {
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.play-options li:hover,
.play-options li[aria-selected="true"] {
    background: var(--ink);
    color: var(--paper);
}

.play-options li:hover span,
.play-options li[aria-selected="true"] span {
    color: var(--paper);
    opacity: 0.8;
}

.play-options .play-options-empty {
    cursor: default;
    color: var(--ink-soft);
    background: none !important;
}

.play-skip {
    grid-column: 1 / -1;
    justify-self: start;
    border: 0;
    background: none;
    padding: 0.2rem 0;
    color: var(--ink-soft);
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.play-skip:hover,
.play-skip:focus-visible {
    color: var(--accent);
}

.play-status {
    grid-column: 1 / -1;
    min-height: 1.5rem;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
}

.play.is-busy .play-form {
    opacity: 0.6;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Earlier turns: the guess, what it told, and the clue it was made on
   -------------------------------------------------------------------------- */

.play-feed {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.9rem;
}

.play-feed .play-clue {
    padding: 0.8rem 1rem 0.9rem;
    border-color: var(--rule-soft);
}

.play-feed .play-clue-text,
.play-feed .play-facts {
    font-size: 1.08rem;
    color: var(--ink-soft);
}

.play-feed .play-author {
    font-size: 1.3rem;
}

.play-feed .play-author img {
    width: 3rem;
    height: 3.7rem;
}

.play-clue.is-unused {
    border-style: dashed;
}

.play-guess {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
    margin-top: 0.7rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--rule-soft);
    font-size: 0.95rem;
    line-height: 1.3;
}

.play-guess-mark {
    width: 1.35rem;
    height: 1.35rem;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--pip);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 900;
}

.play-guess-title {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.08rem;
}

.play-guess.is-wrong .play-guess-title,
.play-guess.is-author .play-guess-title {
    text-decoration: line-through;
    text-decoration-color: var(--wrong);
    text-decoration-thickness: 2px;
}

.play-chip {
    border: 1px solid var(--rule-soft);
    padding: 0.08rem 0.5rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink-soft);
    white-space: nowrap;
}

.play-chip.is-hit {
    background: var(--near);
    border-color: var(--near);
    color: #1c1b19;
}

.play-chip.is-year {
    border-color: var(--ink);
    color: var(--ink);
}

/* --------------------------------------------------------------------------
   The result
   -------------------------------------------------------------------------- */

.play-result {
    text-align: center;
    border: 3px double var(--rule);
    background: var(--paper-deep);
    padding: 1.6rem 1.4rem 1.5rem;
    margin-bottom: 1.5rem;
}

.play-result.is-new {
    animation: play-rise 0.7s var(--ease-out) both;
}

@keyframes play-rise {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: none; }
}

.play-result-title {
    font-family: var(--display);
    font-weight: 900;
    font-size: clamp(2.2rem, 7vw, 3.4rem);
    line-height: 1.05;
    margin: 0 0 0.3rem;
    color: var(--accent) !important;
}

.play-result-sub {
    margin: 0 0 1rem;
    font-weight: 700;
    color: var(--ink-soft);
}

.play-squares {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin: 0 0 1.2rem;
    padding: 0;
    list-style: none;
}

.play-squares li {
    width: 2.1rem;
    height: 2.1rem;
    border: var(--frame);
    background: var(--pip, transparent);
    border-color: var(--pip, var(--rule-soft));
}

.play-result-book {
    font-family: var(--display);
    font-weight: 900;
    font-size: clamp(1.7rem, 5vw, 2.4rem);
    line-height: 1.15;
    margin: 0;
}

.play-result-book a {
    text-decoration: none;
}

.play-result-book a:hover {
    color: var(--accent);
}

.play-result-by {
    margin: 0.3rem 0 0.9rem;
    color: var(--ink-soft);
    font-weight: 600;
}

.play-result-intro {
    max-width: 34rem;
    margin: 0 auto 1.3rem;
    font-size: 1.02rem;
    line-height: 1.6;
    text-align: start;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.play-result-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
}

.play-result-actions .ink-btn {
    cursor: pointer;
    font-size: 1rem;
    padding: 0.65rem 1.2rem;
}

.play-result-actions .ink-btn.is-done {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
}

.play-result-actions .play-read {
    flex-basis: 100%;
    font-size: 1.2rem;
    padding: 0.9rem 1.4rem;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff !important;
}

.play-result-actions .play-read:hover,
.play-result-actions .play-read:focus-visible {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper) !important;
}

.play-note,
.play-read-note {
    margin: 0.7rem 0 0;
    font-size: 0.9rem;
    color: var(--ink-soft);
}

.play-next {
    margin: 1.2rem 0 0;
    padding-top: 1rem;
    border-top: 1px solid var(--rule-soft);
    font-weight: 600;
    color: var(--ink-soft);
}

.play-next strong {
    display: block;
    font-family: var(--display);
    font-size: 2rem;
    line-height: 1.2;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    direction: ltr;
}

/* --------------------------------------------------------------------------
   Record, how to play, earlier puzzles
   -------------------------------------------------------------------------- */

.play-section-title {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-family: var(--display);
    font-weight: 900;
    font-size: 1.6rem;
    margin: 3rem 0 1.1rem;
}

.play-section-title::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--rule);
}

.play-record,
.play-how,
.play-archive {
    max-width: 40rem;
    margin-inline: auto;
}

.play-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin: 0 0 1.2rem;
    border: var(--frame);
    text-align: center;
}

.play-stats div {
    padding: 0.8rem 0.3rem;
}

.play-stats div + div {
    border-inline-start: 1px solid var(--rule-soft);
}

.play-stats dd {
    margin: 0;
    font-family: var(--display);
    font-weight: 900;
    font-size: 2rem;
    line-height: 1.1;
}

.play-stats dt {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-soft);
    line-height: 1.25;
}

.play-bars {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.3rem;
}

.play-bars li {
    display: grid;
    grid-template-columns: 1.4rem 1fr;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 0.9rem;
}

.play-bars span {
    min-width: 1.7rem;
    width: calc(var(--share, 0) * 100%);
    padding: 0.05rem 0.45rem;
    background: var(--ink-soft);
    color: var(--paper);
    text-align: end;
    transition: width 0.6s var(--ease-out);
}

.play-bars li.is-now span {
    background: var(--right);
    color: #fff;
}

.play-how ol {
    margin: 0;
    padding-inline-start: 1.4rem;
    line-height: 1.6;
}

.play-how li + li {
    margin-top: 0.4rem;
}

.play-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.4rem;
    margin: 1.1rem 0 0;
    padding: 0;
    list-style: none;
    font-size: 0.92rem;
    color: var(--ink-soft);
}

.play-legend li {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.play-legend .play-pip {
    width: 1.1rem;
    height: 1.1rem;
}

.play-archive ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.play-archive a.is-won::after {
    content: " ✓";
    color: var(--right);
}

.play-archive a.is-lost::after {
    content: " ✕";
    color: var(--wrong);
}

/* Paper confetti over the page when the book is named */
.play-confetti {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2000;
}

@media (max-width: 480px) {
    .play {
        padding-block-start: 0.75rem;
    }

    .play-head {
        margin-bottom: 1rem;
    }

    .play-kicker {
        gap: 0.2rem 0.6rem;
        font-size: 0.72rem;
        letter-spacing: 0.07em;
    }

    .play-kicker > * + *::before {
        margin-inline-end: 0.6rem;
    }

    .play-lead {
        font-size: 1rem;
    }

    .play-clue.is-current {
        padding: 1rem 1.1rem 1.25rem;
    }

    .play-stats dd {
        font-size: 1.6rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .play-book-inner,
    .play-book-mark,
    .play-clue.is-new,
    .play-result.is-new,
    .play-pips li.is-new {
        animation: none;
    }

    .play-book,
    .play-book-inner {
        transition: none;
    }
}
