/* ==========================================================================
   Porlock's Book Cipher — app page (app.php) and description-page worked
   example (inline.php). Builds on the shared Cipher Bureau blocks in
   tools.css (.cipher-tabs, .cipher-block, .cipher-label …). Colours come
   only from the theme variables so all eight site themes work.
   ========================================================================== */

.bc-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.2rem;
    max-width: 1300px;
    margin: 0 auto;
    align-items: start;
}
.bc-col { min-width: 0; }
.bc-col-key { position: sticky; top: 3.4rem; }

.bc-select {
    width: 100%;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    font: inherit;
    font-size: 0.95rem;
}
.bc-select:focus { outline: none; border-color: var(--accent); }
.bc-select-inline { width: auto; padding: 0.35rem 0.5rem; font-size: 0.88rem; }
.bc-num-input {
    width: 4rem;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.3rem 0.4rem;
    font: inherit;
}
.cipher-block select + #bc-custom-wrap textarea { margin-top: 0.2rem; }
.bc-controls { gap: 0.8rem 1.2rem; }
.bc-opt { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; cursor: pointer; }
.bc-opt input { accent-color: var(--accent); }
.bc-key-info, .bc-stats { margin: 0.5rem 0 0; font-size: 0.85rem; color: var(--text-dim); min-height: 1.1em; }
.bc-stats.bc-ok { color: var(--accent); }
.bc-stats.bc-bad { color: var(--text-dim); font-style: italic; }
.bc-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
.bc-actions .button-primary,
.bc-actions .button-secondary { padding: 0.45rem 0.85rem; font-size: 0.88rem; }
.cipher-block textarea#bc-cipher-out,
.cipher-block textarea#bc-cipher-in,
#rc-numbers,
#rc-decode-in { font-family: 'Courier New', Courier, monospace; letter-spacing: 0.02em; }

.bc-decoded {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.08rem;
    line-height: 1.6;
    min-height: 1.6em;
    overflow-wrap: anywhere;
}
.bc-dw-clear { color: var(--accent); letter-spacing: 0.04em; }
.bc-dw-spell { font-style: italic; }
.bc-dw-bad { color: var(--text-dim); }

/* Key text viewer */
.bc-key-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.4rem 1rem; }
.bc-key-head h2 { margin-bottom: 0.2rem; }
.bc-key-view {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 1rem;
    max-height: min(68vh, 640px);
    overflow-y: auto;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 0.98rem;
    line-height: 1.75;
    color: var(--text);
}
.bc-key-view:focus { outline: none; border-color: var(--accent); }
.bc-key-view p { margin: 0.7rem 0; }
.bc-key-view-short { max-height: 220px; margin-top: 0.8rem; padding: 0.6rem 0.9rem; }
.bc-key-empty { color: var(--text-dim); font-style: italic; }
.bc-w { border-radius: 3px; cursor: pointer; transition: background 0.2s ease; }
.bc-w:hover { background: var(--accent-soft); }
.bc-w.bc-picked { outline: 1px dashed var(--accent); }
.bc-hit,
.bc-hit-letter {
    position: relative;
    background: var(--accent);
    color: var(--bg);
    padding: 0 0.15em;
    font-weight: bold;
    animation: bc-pop 0.45s ease both;
    animation-delay: var(--bc-delay, 0ms);
}
.bc-hit-letter { background: var(--accent-soft); color: var(--text); outline: 1px solid var(--accent); }
.bc-key-view .bc-hit[data-order]::after,
.bc-key-view .bc-hit-letter[data-order]::after {
    content: attr(data-order);
    position: absolute;
    top: -0.95em;
    right: -0.2em;
    font: bold 0.6rem/1 system-ui, sans-serif;
    background: var(--bg-raised);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 1px 3px;
    pointer-events: none;
}
.bc-show-nums .bc-w::before {
    content: attr(data-n);
    font: 0.6rem/1 system-ui, sans-serif;
    color: var(--text-dim);
    vertical-align: super;
    margin-right: 1px;
}
.bc-show-nums .bc-hit::before { color: inherit; }
@keyframes bc-pop {
    0% { background: transparent; color: inherit; transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* Porlock walkthrough */
.bc-step-count { margin: 0; font-size: 0.75rem; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-dim); }
.bc-cipher-line {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0.8rem 0 1rem;
    padding: 0.8rem;
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-family: 'Courier New', Courier, monospace;
}
.bc-tok {
    padding: 0.15rem 0.4rem;
    border-radius: 5px;
    border: 1px solid transparent;
    color: var(--text);
    transition: all 0.25s ease;
}
.bc-tok-head { color: var(--text-dim); }
.bc-tok-clear { letter-spacing: 0.05em; }
.bc-tok-focus { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.bc-tok-done { color: var(--accent); }
.bc-tok-now { background: var(--accent); color: var(--bg); transform: translateY(-2px); }
.bc-step-body { line-height: 1.65; }
.bc-step-body ul { padding-left: 1.2rem; }
.bc-step-body li { margin-bottom: 0.45rem; }
.bc-step-tip { color: var(--text-dim); font-size: 0.92rem; }
.bc-porlock-final {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.15rem;
    border-left: 3px solid var(--accent);
    padding-left: 0.8rem;
}
.bc-porlock-out { margin: 0.6rem 0 0.2rem; }
.bc-step-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 1.2rem; }
.bc-step-nav button:disabled { opacity: 0.45; cursor: default; }
.bc-dots { display: flex; gap: 0.35rem; }
.bc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.bc-dot.active { background: var(--accent); }

/* The illustrative almanac page — it borrows the theme's card colours so it
   reads as a printed page in light and dark themes alike. */
.bc-almanac {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.7rem 0.9rem 0.9rem;
    font-family: Georgia, 'Times New Roman', serif;
    box-shadow: inset 0 0 40px var(--accent-soft);
}
.bc-almanac-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0 0 0.6rem;
    padding-bottom: 0.35rem;
    border-bottom: 2px solid var(--text-dim);
    font-size: 0.75rem;
    letter-spacing: 1px;
    color: var(--text-dim);
}
.bc-almanac-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.bc-almanac-col {
    font-size: 0.78rem;
    line-height: 1.55;
    text-align: justify;
    hyphens: auto;
    max-height: 430px;
    overflow-y: auto;
    color: var(--text-dim);
}
.bc-almanac-col1 { opacity: 0.45; overflow: hidden; }
.bc-almanac-col2 { border-left: 1px solid var(--border); padding-left: 0.8rem; color: var(--text); }
.bc-aw { border-radius: 2px; }
.bc-aw.bc-hit::after { content: attr(data-n); font: bold 0.55rem/1 system-ui, sans-serif; vertical-align: super; margin-left: 1px; }
.bc-almanac-note { margin-top: 0.7rem; font-size: 0.82rem; }

/* Gloria Scott */
.bc-tries { display: flex; flex-direction: column; gap: 0.3rem; }
.bc-try {
    display: grid;
    grid-template-columns: 11rem minmax(0, 1fr);
    gap: 0.6rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    font-size: 0.88rem;
}
.bc-try-click { cursor: pointer; }
.bc-try-click:hover { border-color: var(--accent); }
.bc-try-label { color: var(--text-dim); }
.bc-try-text { font-family: Georgia, 'Times New Roman', serif; overflow-wrap: anywhere; }

/* Red Circle */
.bc-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.8rem; align-items: center; }
.bc-chip {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: 2.2rem;
    padding: 0.25rem 0.35rem;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    line-height: 1.15;
}
.bc-chip strong { color: var(--accent); font-size: 1rem; }
.bc-chip span { font-size: 0.72rem; color: var(--text-dim); }
.bc-chip-gap { color: var(--text-dim); padding: 0 0.2rem; }

.bc-window {
    position: relative;
    width: min(260px, 100%);
    aspect-ratio: 3 / 4;
    margin: 0.6rem auto 0.8rem;
    border: 10px solid var(--border);
    border-radius: 6px 6px 2px 2px;
    background: var(--bg);
    overflow: hidden;
    transition: background 0.08s linear, box-shadow 0.08s linear;
}
.bc-window-panes { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; z-index: 2; pointer-events: none; }
.bc-window-panes span { border: 3px solid var(--border); }
.bc-candle { position: absolute; left: 27%; bottom: 8%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; z-index: 1; }
.bc-wax { width: 16px; height: 56px; background: var(--text-dim); border-radius: 2px; opacity: 0.6; }
.bc-flame {
    width: 14px;
    height: 24px;
    margin-bottom: 2px;
    border-radius: 50% 50% 45% 45% / 65% 65% 35% 35%;
    background: var(--border);
    opacity: 0.35;
    transition: all 0.08s linear;
}
.bc-window.lit { background: var(--accent-soft); box-shadow: 0 0 60px 10px var(--accent-soft); }
.bc-window.lit .bc-flame {
    opacity: 1;
    background: radial-gradient(ellipse at 50% 70%, #fff7d6 0%, #ffd27a 40%, #ff9a3c 75%, transparent 100%);
    box-shadow: 0 0 30px 14px rgba(255, 190, 90, 0.55);
    transform: scale(1.15);
}
.bc-window-readout { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-size: 0.95rem; color: var(--text-dim); }
.bc-window-readout strong { color: var(--accent); font-family: 'Courier New', Courier, monospace; font-size: 1.1rem; }
.bc-guess { margin-top: 1rem; border-top: 1px dashed var(--border); padding-top: 0.6rem; }
.bc-guess-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.bc-guess-row input { flex: 1; min-width: 8rem; }

@media (max-width: 900px) {
    .bc-grid { grid-template-columns: 1fr; }
    .bc-col-key { position: static; }
    .bc-key-view { max-height: 50vh; }
    .bc-almanac-cols { grid-template-columns: 1fr; }
    .bc-almanac-col1 { display: none; }
    .bc-almanac-col2 { border-left: none; padding-left: 0; max-height: 320px; }
    .bc-try { grid-template-columns: 1fr; gap: 0.15rem; }
}
@media (prefers-reduced-motion: reduce) {
    .bc-hit, .bc-hit-letter { animation: none; }
    .bc-tok, .bc-w { transition: none; }
}

/* --------------------------------------------------------------------------
   Description-page worked example (inline.php)
   -------------------------------------------------------------------------- */
.bc-static h2 { margin-top: 0; }
.bc-static-intro { color: var(--text-dim); max-width: 60rem; }
.bc-static-cipher {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.05rem;
    background: var(--bg-raised);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    overflow-wrap: anywhere;
}
.bc-static-table-wrap { overflow-x: auto; margin: 1rem 0; }
.bc-static-table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 0.92rem; }
.bc-static-table th,
.bc-static-table td { border: 1px solid var(--border); padding: 0.35rem 0.55rem; text-align: left; }
.bc-static-table th { background: var(--bg-raised); color: var(--text-dim); font-weight: normal; }
.bc-static-table td.bc-static-num { font-family: 'Courier New', Courier, monospace; color: var(--accent); }
.bc-static-plain {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.1rem;
    border-left: 3px solid var(--accent);
    padding-left: 0.9rem;
}
.bc-static-steps { padding-left: 1.3rem; }
.bc-static-steps li { margin-bottom: 0.45rem; }
.bc-static h3 { margin: 1.6rem 0 0.5rem; color: var(--accent); }
.bc-static-note mark { background: var(--accent); color: var(--bg); padding: 0 0.15em; border-radius: 3px; }
.bc-static-note {
    font-family: Georgia, 'Times New Roman', serif;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    line-height: 1.8;
}
.bc-static-cta { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.2rem; }
.bc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
