.binary-main { width: 100%; padding: 0 0 54px; }

.binary-page-header {
    padding: 20px 22px;
    color: #fff;
    background: var(--color-brand);
    border-bottom: 4px solid var(--color-accent);
}

.binary-header-inner {
    width: min(1200px, 100%);
    margin: 0 auto;
    display: block;
}

.binary-heading h1 { margin: 0; color: #fff; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.binary-heading p { margin: 7px 0 0; color: #f3dfce; }
.binary-page-header .back-link { display: inline-block; margin-bottom: 9px; color: #fff; font-size: .88rem; font-weight: 700; text-underline-offset: 3px; }

.difficulty-panel,
.board-section {
    width: min(760px, calc(100% - 40px));
    margin-inline: auto;
    padding: 26px;
    text-align: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
}

.difficulty-panel h2 { margin: 0 0 10px; font-size: 1.05rem; }
.board-section { margin-top: 22px; }
.board-section > h2 { margin-top: 0; }
.difficulty-buttons,
.game-options { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.game-options { margin: 0 0 18px; }

.difficulty-panel button,
.board-section button,
.celebration button {
    min-width: 112px;
    padding: 11px 16px;
    color: var(--color-ink);
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.difficulty-panel button:hover,
.board-section button:hover,
.celebration button:hover { background: #f7ead9; border-color: #c8a47f; }
.difficulty-panel button:disabled,
.board-section button:disabled { cursor: default; opacity: .5; }
.difficulty-buttons button.active { color: #fff; background: var(--color-brand-strong); border-color: var(--color-brand-strong); }
#status { margin: 10px 0 0; min-height: 1.5em; color: var(--color-muted); line-height: 1.5; }
#status.success-status { color: #246b3f; font-weight: 700; }
#status.error-status { color: #8b2f2f; font-weight: 700; }

.board-section .difficulty-panel {
    width: min(540px, 100%);
    margin: 0 auto 16px;
    padding: 14px 16px;
    background: #fffaf2;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: none;
}

.board-section .difficulty-panel h3 { margin: 0; font-size: 1rem; }
.board-section .difficulty-buttons { margin: 10px 0 7px; gap: 7px; }
.board-section .difficulty-buttons button { min-width: 0; flex: 1 1 100px; padding: 9px 12px; }
.board-section .difficulty-panel #status { margin: 0; font-size: .86rem; }

.binary-board {
    width: min(100%, 540px);
    aspect-ratio: 1;
    margin: 18px auto 0;
    display: grid;
    grid-template-columns: repeat(var(--grid-size, 6), minmax(0, 1fr));
    grid-template-rows: repeat(var(--grid-size, 6), minmax(0, 1fr));
    overflow: hidden;
    background: #fff;
    border: 3px solid var(--color-brand-strong);
    border-radius: 3px;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.binary-cell,
.board-section .binary-cell {
    min-width: 0;
    width: auto;
    min-height: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-right: 1px solid #bcae9e;
    border-bottom: 1px solid #bcae9e;
    border-radius: 0;
    background: #fff;
    font-size: clamp(1rem, 5vw, 1.8rem);
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.binary-cell.last-column { border-right: 0; }
.binary-cell.last-row { border-bottom: 0; }
.board-section .binary-cell.fixed { color: var(--color-ink); background: #f7f0e7; font-weight: 800; opacity: 1; cursor: default; }
.binary-cell.user-value { color: var(--color-brand); font-weight: 700; }
.binary-cell.selected { background: #fff1d8; outline: 3px solid var(--color-accent); outline-offset: -3px; }
.binary-cell:focus-visible { outline: 3px solid var(--color-accent); outline-offset: -3px; z-index: 1; }
.tap-help { margin: 14px 0 0; color: var(--color-muted); font-size: .92rem; }

.rules-card { width: min(100%, 540px); margin: 20px auto 0; text-align: left; border: 1px solid var(--color-border); border-radius: 10px; background: #fff; }
.rules-card summary { padding: 13px 15px; font-weight: 800; cursor: pointer; }
.rules-content { padding: 0 16px 14px; line-height: 1.55; }
.rules-content p { margin-top: 0; }
.rules-content ul { margin-bottom: 0; padding-left: 22px; }
.rules-content li + li { margin-top: 7px; }
.video-tutorial { width: min(100%, 640px); margin: 24px auto 0; text-align: left; }
.video-tutorial h2 { margin: 0 0 7px; font-size: 1.25rem; text-align: center; }
.video-tutorial p { margin: 0 0 12px; color: var(--color-muted); line-height: 1.5; text-align: center; }
.video-frame { aspect-ratio: 16 / 9; overflow: hidden; border: 1px solid var(--color-border); border-radius: 10px; background: #000; box-shadow: var(--shadow-card); }
.video-frame iframe { width: 100%; height: 100%; display: block; border: 0; }
.print-credit, .print-instructions { display: none; }

.binary-board.is-incorrect { animation: board-wobble .38s ease-in-out; }
@keyframes board-wobble { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }

.celebration[hidden] { display: none; }
.celebration { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; background: rgba(37, 22, 14, .62); }
.celebration-card { position: relative; z-index: 2; width: min(420px, 100%); padding: 30px; text-align: center; background: #fffaf2; border: 3px solid var(--color-accent); border-radius: 18px; box-shadow: 0 18px 60px rgba(0, 0, 0, .35); }
.celebration-kicker { margin: 0; color: var(--color-brand); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.celebration-card h2 { margin: 8px 0; }
.confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-layer i { position: absolute; top: -20px; left: var(--left); width: 9px; height: 14px; background: var(--color); animation: confetti-fall var(--duration) linear var(--delay) forwards; }
@keyframes confetti-fall { to { transform: translate3d(var(--drift), 110vh, 0) rotate(720deg); } }

@media (max-width: 760px) {
    .binary-page-header { padding: 14px; }
}

@media (max-width: 600px) {
    .binary-main { padding-bottom: 36px; }
    .difficulty-panel, .board-section { width: calc(100% - 20px); padding: 18px 10px; }
    .board-section { padding-inline: 4px; }
    .board-section .difficulty-panel { padding: 12px 10px; }
    .difficulty-buttons { flex-direction: column; gap: 7px; }
    .difficulty-buttons button { width: 100%; }
    .game-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
    .game-options button { min-width: 0; width: 100%; padding: 11px 5px; }
    .binary-cell, .board-section .binary-cell { font-size: clamp(.95rem, 7vw, 1.55rem); }
}

@media (prefers-reduced-motion: reduce) {
    .binary-board.is-incorrect, .confetti-layer i { animation: none; }
}

@page { size: Letter portrait; margin: .5in; }

@media print {
    html, body, body.site-frame { width: 100%; height: auto; min-height: 0; overflow: visible; background: #fff; }
    body.site-frame { display: block; }
    #site-header, #site-footer, .binary-page-header, .difficulty-panel, .game-options,
    .tap-help, .rules-card, .video-tutorial, .celebration, .board-section > h2 { display: none !important; }
    .site-main, .binary-main { display: block; width: 100%; height: auto; margin: 0; padding: 0; overflow: visible; }
    .board-section { width: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; background: #fff; box-shadow: none; }
    .binary-board { width: 6.5in; max-width: 100%; margin: 0 auto; border-color: #000; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .binary-cell, .board-section .binary-cell { background: #fff !important; border-color: #777; font-size: 22pt; }
    .board-section .binary-cell.fixed { color: #000 !important; background: #f1f1f1 !important; }
    /* The printable grid always matches the starting clues, even after play. */
    .board-section .binary-cell:not(.fixed) { color: transparent !important; }
    .binary-cell.selected { outline: none; }
    .print-instructions {
        display: block;
        width: 6.5in;
        max-width: 100%;
        margin: .3in auto 0;
        color: #222;
        font-size: 10pt;
        line-height: 1.35;
        text-align: left;
        break-inside: avoid;
    }
    .print-instructions h2 { margin: 0 0 .1in; font-size: 12pt; }
    .print-instructions ul { margin: 0; padding-left: .25in; }
    .print-instructions li + li { margin-top: .04in; }
    .print-credit { display: block; margin: .18in 0 0; color: #555; font-size: 8pt; text-align: center; }
}
