/* Nonograme — picture logic puzzles (js/nonograme.js). Theme-aware like the other game pages:
   tokens on :root, redefined under body.dark-theme. */
:root {
    --ng-accent: #6d28d9;
    --ng-accent-2: #7c3aed;
    --ng-accent-soft: #efe7ff;
    --ng-page-bg: #f6f3fc;
    --ng-card-bg: #ffffff;
    --ng-card-border: #e2daf2;
    --ng-muted: #645a78;
    --ng-shadow: 0 10px 30px rgba(60, 30, 120, .10);
    --ng-cell-bg: #ffffff;
    --ng-clue-bg: #f3effb;
    --ng-clue-alt: #e9e2f8;
    --ng-line: #d8d0e8;
    --ng-line5: #7c6aa8;
    --ng-ink: #2e1a5c;
    --ng-cross: #8b7fa6;
    --ng-clue: #2b2140;
    --ng-done: #b5abc9;
    --ng-good: #15803d;
    --ng-bad: #dc2626;
    --ng-gold: #f59e0b;
    --ng-flash: #fff3c4;
    --ng-cell: 28px;
}

body.dark-theme {
    --ng-accent: #b794ff;
    --ng-accent-2: #c4a8ff;
    --ng-accent-soft: #241a3d;
    --ng-page-bg: #110d1b;
    --ng-card-bg: #1b1529;
    --ng-card-border: #33284d;
    --ng-muted: #ada3c4;
    --ng-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --ng-cell-bg: #211a33;
    --ng-clue-bg: #18122a;
    --ng-clue-alt: #221a38;
    --ng-line: #3a2f55;
    --ng-line5: #8a77bd;
    --ng-ink: #d9ccff;
    --ng-cross: #8d81a8;
    --ng-clue: #ece6ff;
    --ng-done: #5a4f73;
    --ng-good: #4ade80;
    --ng-bad: #f87171;
    --ng-flash: #4a3d12;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` would kill position: sticky. */
.ng-body, body.ng-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--ng-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.ng-main { padding-top: 92px; padding-bottom: 40px; }
.ng-game .container, .ng-hero .container { max-width: 1000px; }

/* ---- hero ---- */
.ng-hero { text-align: center; padding: 4px 0 8px; }
.ng-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); margin-bottom: 4px; }
.ng-hero-icon { color: var(--ng-accent); }
.ng-lead { margin: 0 auto; max-width: 580px; color: var(--ng-muted); font-size: .98rem; line-height: 1.45; }
body.ng-playing .ng-lead { display: none; }
body.ng-playing .ng-hero h1 { font-size: 1.35rem; margin: 0; }
.ng-loading, .ng-failed { text-align: center; color: var(--ng-muted); margin: 30px 0; }
.ng-failed[hidden], .ng-loading[hidden] { display: none; }

/* ---- buttons, chips, switches ---- */
.ng-btn { min-height: 48px; padding: 8px 14px; border: 1px solid var(--ng-card-border); border-radius: 14px; background: var(--ng-card-bg); color: inherit; font-weight: 700; font-size: .95rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.ng-btn:hover:not(:disabled) { border-color: var(--ng-accent); }
.ng-btn[hidden] { display: none; }
.ng-btn-primary { background: var(--ng-accent); border-color: var(--ng-accent); color: #fff; }
body.dark-theme .ng-btn-primary { color: #1a0f33; }
.ng-round { width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--ng-card-border); background: var(--ng-card-bg); color: inherit; font-size: 1.1rem; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; flex: none; }
.ng-round:hover:not(:disabled) { border-color: var(--ng-accent); }
.ng-round:disabled { opacity: .38; cursor: not-allowed; }
.ng-round span[hidden] { display: none; }
#ng-hint { color: var(--ng-gold); }
.ng-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ng-chip { flex: 1 1 0; min-width: 56px; min-height: 44px; padding: 4px 8px; border-radius: 12px; border: 2px solid var(--ng-card-border); background: var(--ng-card-bg); color: inherit; font-weight: 800; cursor: pointer; touch-action: manipulation; }
.ng-chip[aria-checked="true"] { border-color: var(--ng-accent); background: var(--ng-accent-soft); color: var(--ng-accent); }
.ng-switch { display: inline-flex; align-items: center; gap: 8px; margin: 0; min-height: 40px; font-weight: 700; cursor: pointer; user-select: none; }
.ng-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ng-switch-ui { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--ng-card-border); transition: background .2s; flex: none; }
.ng-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.ng-switch input:checked + .ng-switch-ui { background: var(--ng-accent); }
.ng-switch input:checked + .ng-switch-ui::after { transform: translateX(18px); }
.ng-switch input:focus-visible + .ng-switch-ui { outline: 3px solid var(--ng-gold); outline-offset: 2px; }
.ng-btn:focus-visible, .ng-round:focus-visible, .ng-chip:focus-visible, .ng-tap:focus-visible, .ng-tile:focus-visible { outline: 3px solid var(--ng-gold); outline-offset: 2px; }

/* ---- library ---- */
.ng-lib-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px; margin: 4px 0 10px; }
.ng-count { margin: 0; color: var(--ng-muted); font-weight: 600; }
.ng-count b { color: var(--text-color); }
.ng-gen { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px 14px; padding: 12px 14px; margin: 0 0 16px; border-radius: 18px; background: var(--ng-card-bg); border: 1px solid var(--ng-card-border); box-shadow: var(--ng-shadow); }
.ng-gen-text strong { display: block; }
.ng-gen-text strong i { color: var(--ng-accent); }
.ng-gen-text small { color: var(--ng-muted); }
.ng-gen .ng-chips { flex-wrap: nowrap; }
.ng-group { margin: 0 0 18px; }
.ng-group-title { font-size: 1.1rem; font-weight: 800; margin: 0 0 8px; }
.ng-group-title small { font-size: .82rem; font-weight: 600; color: var(--ng-muted); margin-left: 6px; }
.ng-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.ng-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 8px; border-radius: 16px; border: 1px solid var(--ng-card-border); background: var(--ng-card-bg); color: inherit; cursor: pointer; touch-action: manipulation; transition: transform .12s, border-color .12s; }
.ng-tile:hover { border-color: var(--ng-accent); transform: translateY(-2px); }
.ng-tile-pic { display: grid; place-items: center; width: 88px; height: 88px; }
.ng-thumb { max-width: 88px; max-height: 88px; border-radius: 6px; image-rendering: pixelated; }
.ng-tile:not(.is-done):not(.is-started) .ng-tile-pic::after { content: "?"; position: absolute; font-size: 2rem; font-weight: 900; color: var(--ng-done); }
.ng-tile-name { font-weight: 800; font-size: .9rem; line-height: 1.15; text-align: center; }
.ng-tile-size { font-size: .76rem; color: var(--ng-muted); }
.ng-tile.is-started { border-color: var(--ng-accent); border-style: dashed; }
.ng-tile-ok { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ng-good); color: #fff; font-weight: 900; font-size: .8rem; }
body.dark-theme .ng-tile-ok { color: #052e14; }

/* ---- play ---- */
.ng-play { max-width: 1000px; margin: 0 auto; }
.ng-bar { display: flex; align-items: center; gap: 8px; max-width: 640px; margin: 0 auto 8px; }
.ng-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.ng-title strong { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ng-title small { color: var(--ng-muted); font-weight: 600; }
.ng-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 12px; border-radius: 14px; background: var(--ng-card-bg); border: 1px solid var(--ng-card-border); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ng-pill i { color: var(--ng-accent); }
.ng-pill b { font-size: 1.05rem; }
#ng-errs i { color: var(--ng-bad); }
.ng-pill[hidden] { display: none; }

.ng-wrap { display: flex; justify-content: center; width: 100%; }
.ng-scroll { max-width: 100%; max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); overflow: auto; border-radius: 14px; background: var(--ng-card-bg); border: 1px solid var(--ng-card-border); box-shadow: var(--ng-shadow); touch-action: none; overscroll-behavior: contain; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; scrollbar-width: thin; }
.ng-scroll:focus { outline: none; }
.ng-scroll:focus-visible { box-shadow: 0 0 0 3px var(--ng-gold); }
.ng-grid { display: grid; grid-template-columns: var(--ng-lw) repeat(var(--ng-w), var(--ng-cell)); grid-template-rows: var(--ng-th) repeat(var(--ng-h), var(--ng-cell)); width: max-content; padding: 0 2px 2px 0; }
.ng-corner { position: sticky; top: 0; left: 0; z-index: 4; background: var(--ng-clue-bg); border-right: 2px solid var(--ng-line5); border-bottom: 2px solid var(--ng-line5); }
.ng-cc { position: sticky; top: 0; z-index: 3; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 0; padding-bottom: 3px; background: var(--ng-clue-bg); border-right: 1px solid var(--ng-line); border-bottom: 2px solid var(--ng-line5); color: var(--ng-clue); font-weight: 800; font-size: calc(var(--ng-cell) * .5); line-height: 1.5; font-variant-numeric: tabular-nums; }
.ng-cc:nth-child(odd) { background: var(--ng-clue-alt); }
.ng-rc { position: sticky; left: 0; z-index: 2; display: flex; justify-content: flex-end; align-items: center; gap: calc(var(--ng-cell) * .26); padding-right: calc(var(--ng-cell) * .2); background: var(--ng-clue-bg); border-right: 2px solid var(--ng-line5); border-bottom: 1px solid var(--ng-line); color: var(--ng-clue); font-weight: 800; font-size: calc(var(--ng-cell) * .5); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ng-rc:nth-child(even of .ng-rc) { background: var(--ng-clue-alt); }
.ng-cc.b5 { border-right: 2px solid var(--ng-line5); }
.ng-rc.b5 { border-bottom: 2px solid var(--ng-line5); }
.ng-cc span, .ng-rc span { transition: color .2s, opacity .2s; }
.ng-cc span.is-done, .ng-rc span.is-done { color: var(--ng-done); }
.ng-cc.is-done, .ng-rc.is-done { color: var(--ng-done); }
.ng-cc.is-cur, .ng-rc.is-cur { box-shadow: inset 0 0 0 2px var(--ng-gold); }
.ng-c { position: relative; background: var(--ng-cell-bg); border-right: 1px solid var(--ng-line); border-bottom: 1px solid var(--ng-line); cursor: pointer; }
.ng-c.b5r { border-right: 2px solid var(--ng-line5); }
.ng-c.b5b { border-bottom: 2px solid var(--ng-line5); }
.ng-c.is-fill { background: var(--ng-ink); }
.ng-c.is-fill::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14); animation: ng-pop .12s ease-out; }
@keyframes ng-pop { from { transform: scale(.6); opacity: .4; } }
.ng-c.is-x::before { content: ""; position: absolute; inset: 22%; background: linear-gradient(45deg, transparent 43%, var(--ng-cross) 43% 57%, transparent 57%), linear-gradient(-45deg, transparent 43%, var(--ng-cross) 43% 57%, transparent 57%); }
.ng-c.is-err.is-x::before { background: linear-gradient(45deg, transparent 40%, var(--ng-bad) 40% 60%, transparent 60%), linear-gradient(-45deg, transparent 40%, var(--ng-bad) 40% 60%, transparent 60%); }
.ng-c.is-err.is-fill { background: linear-gradient(135deg, var(--ng-ink) 0 70%, var(--ng-bad) 70%); }
.ng-c.is-flash:not(.is-fill) { background: var(--ng-flash); }
.ng-c.is-hint { z-index: 1; animation: ng-hint .6s ease-in-out 3; box-shadow: 0 0 0 3px var(--ng-gold); }
@keyframes ng-hint { 50% { transform: scale(1.18); } }
.ng-c.is-cursor { box-shadow: inset 0 0 0 3px var(--ng-gold); z-index: 1; }
.ng-grid.is-small .ng-c.is-x::before { inset: 18%; }
@media (hover: hover) {
    .ng-c:not(.is-fill):hover { background: var(--ng-accent-soft); }
}
/* the picture appears in colour */
.ng-grid.is-won .ng-c { background: var(--ng-pic) !important; border-color: transparent !important; transition: background .45s ease var(--d, 0ms); cursor: default; }
.ng-grid.is-won .ng-c::before, .ng-grid.is-won .ng-c::after { display: none; }
.ng-grid.is-won .ng-cc span, .ng-grid.is-won .ng-rc span { color: var(--ng-done); }

.ng-status { margin: 8px 2px 0; min-height: 1.5em; font-weight: 700; text-align: center; color: var(--ng-muted); line-height: 1.4; }
.ng-status.is-good { color: var(--ng-good); }
.ng-status.is-bad { color: var(--ng-bad); }

.ng-tools { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 12px; margin: 8px auto 0; max-width: 640px; }
.ng-taps { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--ng-card-bg); border: 1px solid var(--ng-card-border); flex: 1 1 200px; max-width: 280px; }
.ng-tap { min-height: 46px; border: 0; border-radius: 11px; background: transparent; color: inherit; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; }
.ng-tap[aria-checked="true"] { background: var(--ng-accent); color: #fff; }
body.dark-theme .ng-tap[aria-checked="true"] { color: #1a0f33; }
.ng-tap-fill { display: inline-block; width: 16px; height: 16px; border-radius: 3px; background: currentColor; }
.ng-round-group { display: flex; gap: 6px; }
.ng-opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin: 10px 0 0; }
.ng-actions { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; max-width: 520px; margin: 10px auto 0; }

.ng-help { max-width: 760px; margin: 18px auto 0; padding: 12px 16px; border-radius: 14px; background: var(--ng-card-bg); border: 1px solid var(--ng-card-border); }
.ng-help summary { cursor: pointer; font-weight: 700; }
.ng-help ol { margin: 10px 0 0; padding-left: 20px; color: var(--ng-muted); line-height: 1.55; }
.ng-help li { margin-bottom: 4px; }
.ng-help strong { color: var(--text-color); }
.ng-help p { color: var(--ng-muted); margin: 10px 0 0; line-height: 1.55; font-size: .93rem; }
.ng-help p.ng-credit { font-size: .8rem; }
.ng-help a { color: var(--ng-accent); }
.ng-powered { text-align: center; color: var(--ng-muted); font-size: .85rem; margin: 26px 0 0; }
.ng-powered a { color: var(--ng-accent); }

/* ---- the win dialog ---- */
.ng-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .5); animation: ng-fade .2s ease-out; }
.ng-overlay[hidden] { display: none; }
@keyframes ng-fade { from { opacity: 0; } }
.ng-dialog { width: 100%; max-width: 380px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; padding: 20px 16px 16px; border-radius: 22px; background: var(--ng-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: ng-rise .3s ease-out; }
@keyframes ng-rise { from { transform: translateY(16px) scale(.96); opacity: 0; } }
.ng-win-pic { display: block; width: min(220px, 60vw); height: auto; margin: 0 auto 10px; border-radius: 10px; image-rendering: pixelated; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.ng-dialog h2 { font-weight: 800; font-size: 1.45rem; margin: 2px 0 6px; }
.ng-dialog-sub { color: var(--ng-muted); margin: 0; line-height: 1.45; }
.ng-dialog-sub b { color: var(--text-color); }
.ng-dialog-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; margin-top: 16px; }

@media (max-width: 640px) {
    .ng-gen { grid-template-columns: 1fr; }
    .ng-gen .ng-btn { width: 100%; }
    .ng-tiles { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
    .ng-tile-pic { width: 76px; height: 76px; }
    .ng-thumb { max-width: 76px; max-height: 76px; }
}
@media (max-width: 420px) {
    .ng-tools { gap: 8px; }
    .ng-taps { flex-basis: 100%; max-width: none; }
    .ng-round-group { width: 100%; justify-content: space-between; }
    .ng-round-group .ng-round { flex: 1 1 0; width: auto; }
    .ng-actions { grid-template-columns: 1fr auto; }
    .ng-actions #ng-new { grid-column: 1 / -1; }
    .ng-pill { padding: 4px 9px; }
}
@media (prefers-reduced-motion: reduce) {
    .ng-c, .ng-c::after, .ng-dialog, .ng-overlay, .ng-tile { animation: none !important; transition: none !important; }
}
