/* ===== Games (/games hub + /games/bug-smash) =====
   Loaded only by the Games views (Styles section), so the rest of the site doesn't download it. */

/* ---------- Hub ---------- */
.games-intro { margin: 0 0 12px; font-size: 15px; text-align: left; }
.games-page .games-card-body { text-align: left; }
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 12px;
}
.games-card,
.portfolio-content a.games-card:link,
.portfolio-content a.games-card:visited {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: #ffffff;
    border: 2px outset #ffffff;
    border-right-color: #404040;
    border-bottom-color: #404040;
    color: #000;
    text-decoration: none;
}
.portfolio-content a.games-card:hover { background: #ffffe8; }
.portfolio-content a.games-card:focus-visible { outline: 2px dotted #000; outline-offset: 2px; }
.games-card.is-soon { background: #e4e4e4; color: #404040; }
.games-card-icon { font-size: 34px; line-height: 1; }
.games-card-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.games-card-body b { color: #000080; font-size: 16px; }
.games-card.is-soon .games-card-body b { color: #404040; }
.games-card-body small { font-size: 13px; font-style: italic; }
.games-card-text { font-size: 13px; }
.games-card-play { align-self: flex-start; margin-top: 6px; }
.games-soon {
    align-self: flex-start;
    margin-top: 6px;
    padding: 1px 8px;
    border: 1px dashed #808080;
    font-size: 12px;
}

/* ---------- Bug Smash ---------- */
.bs-window .title-bar { justify-content: space-between; }
.bs-window .title-bar a.bs-title-link:link,
.bs-window .title-bar a.bs-title-link:visited { color: #fff; font-weight: normal; text-decoration: underline; }
.bs-noscript { padding: 8px; background: #ffffe0; border: 1px solid #808080; }

.portfolio-content .bs-heading { margin: 0 0 4px; }
.bs-pitch { margin: 0 0 12px; font-size: 15px; text-align: left; }
.bs-window .portfolio-content p, .bs-window .portfolio-content li { text-align: left; }
.portfolio-content .bs-choice b { color: #000080; }

.bs-setup { display: grid; gap: 10px; }
.bs-fieldset {
    margin: 0;
    padding: 8px 12px 10px;
    border: 2px groove #ffffff;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
}
.bs-fieldset legend { padding: 0 4px; font-weight: bold; }
.bs-fieldset legend small { font-weight: normal; }
.bs-choice { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 32px; }
.bs-choice small { color: #404040; }
.bs-field-error { flex-basis: 100%; margin: 0; color: #a00000; font-weight: bold; }
.bs-pool { margin: 0; font-size: 13px; color: #303030; min-height: 1.2em; }
.bs-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0; }
.bs-start { font-size: 16px; padding: 6px 22px; }
.bs-start:disabled { color: #808080; text-shadow: 1px 1px #fff; cursor: not-allowed; }
.bs-best { font-size: 13px; font-weight: bold; color: #000080; }

.bs-rules { margin-top: 12px; padding: 6px 10px; background: #ffffff; border: 2px inset #c0c0c0; }
.bs-rules summary { cursor: pointer; font-weight: bold; }
.bs-rules ul { margin: 8px 0 0; padding-left: 20px; }
.bs-rules li { margin: 3px 0; }
.bs-rules kbd { padding: 0 4px; border: 1px solid #808080; background: #e8e8e8; font-family: "Courier New", monospace; }

.bs-badge {
    display: inline-block;
    min-width: 30px;
    padding: 0 4px;
    border: 1px solid #000;
    font: bold 11px/16px "MS Sans Serif", sans-serif;
    text-align: center;
    color: #fff;
}
.bs-lang-cs { background: #68217a; }
.bs-lang-js { background: #c9a400; color: #000; }
.bs-lang-sql { background: #00607a; }

/* HUD */
.bs-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    padding: 4px 6px;
    margin-bottom: 6px;
    border: 2px inset #c0c0c0;
    background: #d4d0c8;
    font-size: 14px;
}
.bs-hud-item b { display: inline-block; min-width: 2ch; color: #000080; font-family: "Courier New", monospace; font-size: 16px; }
.bs-hud-item.is-hot b { color: #c00000; }
.bs-lives { display: inline-flex; gap: 2px; font-size: 16px; }
.bs-heart.is-lost { opacity: .45; }
.bs-hud-buttons { margin-left: auto; display: flex; gap: 6px; }

/* Arena = the editor */
.bs-arena {
    position: relative;
    height: min(62vh, 560px);
    min-height: 220px;
    overflow: hidden;
    background: #ffffff;
    border: 2px inset #c0c0c0;
    /* Gutter strip behind the line numbers. */
    background-image: linear-gradient(90deg, #ececec 0 44px, #c0c0c0 44px 45px, transparent 45px);
    /* No panning/zooming gestures on the play field: every touch is a tap on a line. */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.bs-arena.is-slow { background-color: #f3ecff; }
.bs-arena.flash-bad { animation: bs-flash-bad .45s ease-out; }
@keyframes bs-flash-bad {
    0% { box-shadow: inset 0 0 0 6px #ff3030; }
    100% { box-shadow: inset 0 0 0 0 transparent; }
}

.bs-line {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin: 0;
    padding: 5px 8px 5px 0;
    border: 1px solid transparent;
    background: transparent;
    color: #000;
    text-align: left;
    font-size: 14px;
    cursor: crosshair;
    will-change: transform;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}
/* Hover only where there is a real pointer; on touch screens it would stick after a tap. */
@media (hover: hover) {
    .bs-line:hover { background: rgba(0, 0, 128, .06); border-color: #c0c0ff; }
}
.bs-line:focus-visible { outline: 2px dotted #000080; outline-offset: -2px; }
.bs-gutter {
    flex: 0 0 44px;
    padding-right: 6px;
    text-align: right;
    color: #808080;
    font: 13px/20px "Courier New", monospace;
}
.bs-line .bs-badge { flex: 0 0 auto; margin-top: 2px; }
.bs-code {
    flex: 1 1 auto;
    min-width: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 14px/20px "Courier New", Courier, monospace;
    color: #000;
    background: none;
}
.bs-line.is-power { background: #fff8c8; border: 1px dashed #b08000; font-weight: bold; cursor: pointer; }
.bs-line.is-power .bs-gutter { font-size: 18px; color: #000; }
.bs-line.is-power .bs-code { font-family: "MS Sans Serif", sans-serif; }
.bs-line.is-duck { background: #fff1a8; border-color: #e0a000; box-shadow: 0 0 0 2px #ffcc00; }
.bs-line.is-duck .bs-gutter::before { content: "🦆 "; }

.bs-line.is-smashed { animation: bs-smash .38s ease-out forwards; background: #d8ffd8; }
.bs-line.is-false { animation: bs-shake .45s ease-out forwards; background: #ffd8d8; }
.bs-line.is-used { animation: bs-smash .3s ease-out forwards; }
.bs-line.is-smashed .bs-code { text-decoration: line-through; color: #006000; }
@keyframes bs-smash {
    0% { opacity: 1; filter: none; }
    100% { opacity: 0; filter: blur(2px); }
}
@keyframes bs-shake {
    0%, 100% { margin-left: 0; opacity: 1; }
    20% { margin-left: -8px; }
    40% { margin-left: 8px; }
    60% { margin-left: -5px; }
    80% { margin-left: 5px; opacity: .8; }
    100% { opacity: 0; }
}

.bs-effects { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bs-float {
    position: absolute;
    right: 14px;
    font: bold 18px "Courier New", monospace;
    animation: bs-float .9s ease-out forwards;
}
.bs-float.is-good { color: #008000; }
.bs-float.is-bad { color: #c00000; }
@keyframes bs-float {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-36px); }
}

.bs-banner {
    position: absolute;
    left: 50%;
    top: 40%;
    z-index: 3;
    transform: translate(-50%, -50%);
    padding: 8px 16px;
    background: #000080;
    color: #fff;
    border: 2px outset #ffffff;
    font-weight: bold;
    white-space: nowrap;
    pointer-events: none;
}
.bs-paused {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(192, 192, 192, .85);
}
.bs-paused p { margin: 0; font-size: 20px; }
.bs-banner[hidden], .bs-paused[hidden] { display: none; }

.bs-explain {
    margin-top: 6px;
    padding: 6px 8px;
    min-height: 2.6em;
    background: #ffffe0;
    border: 1px solid #808080;
    font-size: 14px;
}
.bs-explain.is-good { background: #e6ffe6; }
.bs-explain.is-bad { background: #ffe6e6; }
.bs-explain.is-power { background: #fff8c8; }
.bs-explain code { font-family: "Courier New", monospace; background: #fff; padding: 0 3px; border: 1px solid #c0c0c0; overflow-wrap: anywhere; }

/* Game over: blue screen */
.bs-bsod {
    padding: 16px 18px;
    background: #0000aa;
    color: #ffffff;
    font: 15px/1.45 "Courier New", Courier, monospace;
}
.portfolio-content .bs-bsod-title {
    display: inline-block;
    margin: 0 0 10px;
    padding: 0 8px;
    background: #aaaaaa;
    color: #0000aa;
    font: bold 16px "Courier New", monospace;
    text-decoration: none;
}
.bs-bsod p { margin: 0 0 8px; text-align: left; }
.portfolio-content .bs-bsod b { color: #ffff55; }
.bs-bsod-score { font-size: 20px; }
.bs-new-best { margin-left: 8px; padding: 0 6px; background: #ffff55; color: #0000aa; font-weight: bold; }
.bs-new-best[hidden] { display: none; }
.bs-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 4px 16px;
    margin: 10px 0;
}
.bs-stats div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted #6a6aff; }
.bs-stats dt { font-weight: normal; }
.bs-stats dd { margin: 0; font-weight: bold; }
.bs-bsod-hint { opacity: .8; animation: bs-blink 1.1s steps(1) infinite; }
@keyframes bs-blink { 50% { opacity: .2; } }

.bs-review { margin-top: 10px; padding: 8px 10px; background: #ffffff; border: 2px inset #c0c0c0; }
.portfolio-content .bs-review h3 { margin: 0 0 6px; font-size: 15px; }
.bs-review-list { margin: 0; padding-left: 22px; }
.bs-review-list li { margin: 0 0 8px; }
.bs-review-list code { font-family: "Courier New", monospace; font-size: 13px; overflow-wrap: anywhere; }
.bs-review-bug { color: #a00000; text-decoration: line-through; }
.bs-review-fix { color: #006000; }
.bs-review-why { display: block; font-size: 13px; color: #303030; }

/* ---------- Bug Smash: daily, packs, leaderboard ---------- */
.bs-small { margin: 4px 0 0; font-size: 13px; }
.bs-notice {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
    margin: 0 0 10px; padding: 6px 10px;
    background: #ffffe0; border: 1px solid #808080;
}
.bs-notice[hidden] { display: none; }
.bs-daily, .bs-pack-banner { margin-bottom: 10px; display: block; background: #f4f4ff; }
.bs-daily p, .bs-pack-banner p { margin: 0 0 6px; }
.bs-daily-status { font-weight: bold; color: #000080; min-height: 1.2em; }
.bs-custom { margin-top: 12px; display: block; }
.bs-custom-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bs-custom-form input[type="text"] { flex: 1 1 220px; min-width: 0; }
.bs-pack-list-wrap { margin-top: 8px; }
.bs-pack-list { margin: 4px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.bs-pack-list li { display: inline-flex; align-items: center; gap: 6px; }
.bs-pack-list small { color: #404040; }

.bs-board { margin-top: 12px; padding: 6px 10px; background: #ffffff; border: 2px inset #c0c0c0; }
.bs-board summary { cursor: pointer; font-weight: bold; }
.bs-board-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.bs-board-tabs .classic-btn.is-active { border-style: inset; font-weight: bold; }
.bs-board-title { margin: 4px 0; font-size: 13px; color: #404040; }
.bs-board-list { margin: 0; padding-left: 28px; }
.bs-board-list li { padding: 2px 0; border-bottom: 1px dotted #c0c0c0; }
.bs-board-list li > * { vertical-align: middle; }
.bs-board-list li.is-me { background: #ffffd0; font-weight: bold; }
.bs-board-list li.bs-board-empty { list-style: none; margin-left: -28px; color: #404040; border: 0; }
.bs-board-name { display: inline-block; min-width: 9em; margin-right: 8px; overflow-wrap: anywhere; }
.bs-board-list b { display: inline-block; min-width: 4ch; margin-right: 8px; color: #000080; font-family: "Courier New", monospace; }
.bs-board-list small { color: #404040; }
.bs-board-delete { margin-left: 6px; padding: 0 6px; min-height: 0; }

/* ---------- Bug Smash: pull request boss fight ---------- */
.bs-boss {
    position: absolute; inset: 0; z-index: 3;
    display: flex; align-items: center; justify-content: center;
    padding: 8px;
    background: rgba(0, 0, 64, .35);
    touch-action: manipulation;
}
.bs-boss[hidden] { display: none; }
.bs-boss-window {
    width: min(640px, 100%);
    max-height: 100%;
    overflow-y: auto;
    background: #c0c0c0;
    border: 2px outset #ffffff;
    border-right-color: #404040;
    border-bottom-color: #404040;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, .35);
}
.bs-boss-title { padding: 3px 8px; background: #000080; color: #fff; font-weight: bold; }
.bs-boss-ask { margin: 6px 8px; font-size: 14px; }
.bs-boss-timer { height: 8px; margin: 0 8px 6px; background: #fff; border: 1px inset #808080; }
.bs-boss-timer span { display: block; height: 100%; width: 100%; background: #c00000; }
.bs-boss-lines { margin: 0 8px 8px; padding: 0; list-style: none; background: #fff; border: 2px inset #c0c0c0; }
.bs-boss-line {
    display: flex; align-items: flex-start; gap: 6px;
    width: 100%; margin: 0; padding: 4px 6px 4px 0;
    border: 1px solid transparent; background: transparent; color: #000;
    text-align: left; cursor: crosshair;
    -webkit-tap-highlight-color: transparent;
}
.bs-boss-no { flex: 0 0 32px; text-align: right; color: #808080; font: 13px/20px "Courier New", monospace; }
.bs-boss-line code { flex: 1 1 auto; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/20px "Courier New", monospace; background: none; }
@media (hover: hover) {
    .bs-boss-line:hover:not(:disabled) { background: rgba(0, 0, 128, .08); border-color: #c0c0ff; }
}
.bs-boss-line:focus-visible { outline: 2px dotted #000080; outline-offset: -2px; }
.bs-boss-line:disabled { cursor: default; color: #000; }
.bs-boss-line.is-bug { background: #ffd8d8; border-color: #c00000; }
.bs-boss-line.is-bug code { text-decoration: underline wavy #c00000; }
.bs-boss-line.is-wrong { background: #e8e8e8; text-decoration: line-through; }

/* ---------- Bug Smash: game over extras ---------- */
.bs-daily-grid { margin: 6px 0 10px; font-size: 18px; line-height: 1.2; letter-spacing: 1px; white-space: pre-line; }
.bs-daily-grid[hidden] { display: none; }
.bs-save, .bs-ai { margin-top: 10px; padding: 8px 10px; background: #ffffff; border: 2px inset #c0c0c0; }
.bs-save[hidden], .bs-ai[hidden] { display: none; }
.portfolio-content .bs-save h3 { margin: 0 0 6px; font-size: 15px; }
.bs-save-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.bs-save-form[hidden] { display: none; }
.bs-save-form input { flex: 1 1 160px; min-width: 0; }
.bs-ai-review { margin-top: 8px; border: 2px outset #ffffff; border-right-color: #404040; border-bottom-color: #404040; }
.bs-ai-review[hidden] { display: none; }
.bs-ai-title { padding: 2px 8px; background: #000080; color: #fff; font-weight: bold; }
.bs-ai-body { padding: 8px 10px; background: #ffffff; font: 14px/1.45 "Courier New", Courier, monospace; }
.bs-ai-body p { margin: 0 0 8px; }
.bs-ai-body ul { margin: 0 0 8px; padding-left: 20px; }
.bs-ai-body li { margin: 0 0 8px; }
.bs-ai-tip { display: block; }
.portfolio-content a.bs-ai-link { display: block; margin-top: 2px; font-family: "MS Sans Serif", sans-serif; font-size: 13px; }
.bs-ai-next { font-weight: bold; }

/* ---------- Admin: Game content page ---------- */
.games-admin-daily, .games-admin-section { margin: 10px 0; padding: 6px 12px 10px; border: 2px groove #ffffff; }
.games-admin-daily legend, .games-admin-section legend { padding: 0 4px; font-weight: bold; }
.games-admin-daily p { margin: 0 0 6px; text-align: left; }
.games-admin-note { margin: 4px 0 8px; font-size: 13px; text-align: left; }
.games-snippet.is-draft { border-style: dashed; }
.games-snippet .portfolio-card-title { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.games-snippet-line { margin: 0 0 4px; text-align: left; }
.games-snippet-line code { font-family: "Courier New", monospace; font-size: 13px; overflow-wrap: anywhere; }
.games-snippet-label { display: inline-block; min-width: 3.5em; font-size: 12px; color: #404040; }
.games-snippet-why { margin: 4px 0; font-size: 13px; text-align: left; }
.games-snippet-meta { margin: 0 0 6px; font-size: 12px; text-align: left; }
.games-boss-code { margin: 0 0 6px; padding: 4px 4px 4px 30px; background: #fff; border: 1px inset #c0c0c0; text-align: left; }
.games-boss-code li { font-size: 12px; }
.games-boss-code code { white-space: pre-wrap; overflow-wrap: anywhere; font-family: "Courier New", monospace; font-size: 12px; background: none; }
.games-boss-code li.is-bug { background: #ffd8d8; }
.games-admin-table-wrap { overflow-x: auto; }
.games-admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.games-admin-table th, .games-admin-table td { padding: 3px 6px; border-bottom: 1px solid #c0c0c0; text-align: left; vertical-align: middle; }
.games-admin-table th { background: #e0e0e0; }

/* ---------- Touch screens: finger-sized controls ---------- */
@media (pointer: coarse), (max-width: 768px), (max-height: 500px) {
    .bs-window .classic-btn { min-height: 44px; padding-left: 12px; padding-right: 12px; }
    .bs-choice { min-height: 44px; }
    .bs-choice input { width: 20px; height: 20px; margin: 0; }
    .bs-rules summary { padding: 12px 0; }
    .bs-window .title-bar a.bs-title-link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 6px; }
    .bs-window .title-bar { padding-top: 0; padding-bottom: 0; }
    /* Keyboard hint only matters with a keyboard. */
    .bs-key-hint { display: none; }
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
    /* The page is already inside the site's window, so give the game back some width. */
    .bs-window { padding: 2px; }
    .bs-window > .portfolio-content { padding: 8px; }
    .bs-arena { height: 58vh; min-height: 220px; background-image: linear-gradient(90deg, #ececec 0 30px, #c0c0c0 30px 31px, transparent 31px); }
    .bs-gutter { flex-basis: 30px; padding-right: 3px; font-size: 11px; }
    .bs-line { gap: 4px; padding: 4px 6px 4px 0; }
    .bs-line .bs-badge { min-width: 26px; padding: 0 2px; font-size: 10px; line-height: 15px; }
    .bs-code { font-size: 13px; line-height: 18px; }
    .bs-hud { gap: 4px 10px; font-size: 13px; padding: 4px; }
    .bs-hud-buttons { margin-left: 0; width: 100%; }
    .bs-hud-buttons .classic-btn { flex: 1 1 0; }
    /* Fixed height so the arena doesn't jump when the explanation changes length. */
    .bs-explain { height: 4.6em; min-height: 0; overflow-y: auto; font-size: 13px; padding: 4px 6px; }
    .bs-banner { white-space: normal; text-align: center; width: 80%; }
    .bs-fieldset { padding: 6px 8px 8px; gap: 0 14px; }
    .bs-actions .classic-btn { flex: 1 1 auto; }
    .bs-bsod { padding: 12px; font-size: 14px; }
    .bs-bsod-score { font-size: 18px; }
    .bs-stats { grid-template-columns: 1fr; }
    .bs-review-list { padding-left: 18px; }
}

/* ---------- Phones: new Bug Smash panels ---------- */
@media (max-width: 600px) {
    .bs-boss { padding: 4px; }
    .bs-boss-no { flex-basis: 22px; font-size: 11px; }
    .bs-boss-line code { font-size: 12px; line-height: 17px; }
    .bs-boss-ask { font-size: 13px; margin: 4px 6px; }
    .bs-board-name { min-width: 0; }
    .bs-board-list small { display: block; }
    .bs-custom-form .classic-btn, .bs-save-form .classic-btn { flex: 1 1 100%; }
}

/* ---------- Very narrow phones (320px) ---------- */
@media (max-width: 360px) {
    .bs-gutter { display: none; }
    .bs-arena { background-image: none; }
    .bs-line { padding-left: 4px; }
    .bs-hud-item { font-size: 12px; }
}

/* ---------- Phones in landscape: little height, so everything is compact ---------- */
@media (max-height: 500px) and (orientation: landscape) {
    .bs-hud { flex-wrap: nowrap; gap: 4px 10px; padding: 2px 4px; margin-bottom: 4px; }
    .bs-hud-buttons { width: auto; margin-left: auto; }
    .bs-hud-buttons .classic-btn { min-height: 40px; flex: 0 0 auto; }
    .bs-explain { height: 2.9em; min-height: 0; overflow-y: auto; margin-top: 4px; padding: 3px 6px; font-size: 13px; }
    .bs-banner { top: 50%; }
}

@media (prefers-reduced-motion: reduce) {
    .bs-line.is-smashed, .bs-line.is-false, .bs-line.is-used { animation: bs-fade .2s linear forwards; }
    .bs-float, .bs-bsod-hint, .bs-arena.flash-bad { animation: none; }
    @keyframes bs-fade { to { opacity: 0; } }
}
