:root {
    --ink: #182018;
    --paper: #e6e8d5;
    --paper-bright: #f4f2df;
    --case: #2e3b32;
    --case-dark: #151c18;
    --line: #687669;
    --muted: #7f897e;
    --mint: #74e0b4;
    --coral: #ff705f;
    --yellow: #f3d45b;
    --blue: #70bde2;
    --violet: #b994df;
    --orange: #ec9d55;
    --lime: #a9dc61;
    --red: #ed5a55;
    --mono: "Courier New", ui-monospace, monospace;
    --sans: Inter, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: #bec3ad;
    font-family: var(--sans);
    -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.wall-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(rgba(24,32,24,.07) 1px, transparent 1px), linear-gradient(90deg, rgba(24,32,24,.07) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: linear-gradient(to bottom, #000, transparent 82%);
}

.arcade-shell, .main-container {
    position: relative;
    width: min(1180px, calc(100% - 32px));
    margin: 18px auto 28px;
    background: var(--paper);
    border: 1px solid #7d8675;
    box-shadow: 0 6px 0 #5e665b, 0 22px 65px rgba(21,28,24,.2);
}

.topbar, .header {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 12px 18px;
    color: var(--paper-bright);
    background: var(--case-dark);
    border-bottom: 5px solid var(--coral);
}

.brand {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px;
    cursor: pointer;
    font-family: var(--mono);
    font-size: 1.18rem;
    letter-spacing: 0;
}
.brand strong { color: var(--yellow); }
.brand-mark {
    width: 39px;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 3px;
    padding: 6px;
    border: 2px solid var(--paper-bright);
}
.brand-mark i:nth-child(1) { background: var(--coral); }
.brand-mark i:nth-child(2) { background: var(--yellow); }
.brand-mark i:nth-child(3) { background: var(--blue); }
.brand-mark i:nth-child(4) { background: var(--mint); }

.library-count { display: flex; align-items: center; gap: 10px; font-family: var(--mono); }
.library-count strong { color: var(--mint); font-size: 1.8rem; line-height: 1; }
.library-count span { color: #9faa9e; font-size: .62rem; line-height: 1.2; }
.header-stats { display: flex; align-items: stretch; gap: 2px; margin-left: auto; }
.readout { min-width: 82px; padding: 7px 10px; border-left: 1px solid #445047; display: grid; gap: 3px; font-family: var(--mono); }
.readout span { color: #89968d; font-size: .57rem; }
.readout strong { color: var(--paper-bright); font-size: .95rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.readout.status strong { color: var(--blue); }
.readout.status.win strong { color: var(--mint); }
.readout.status.lose strong { color: var(--coral); }

.menu-view { padding: 0 28px 22px; }
.marquee-band {
    min-height: 155px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 26px 0 20px;
    border-bottom: 2px solid var(--ink);
}
.kicker { margin: 0 0 8px; color: #58635a; font: 700 .66rem/1 var(--mono); text-transform: uppercase; }
h1 { margin: 0; font: 800 clamp(2.4rem, 8vw, 5.5rem)/.88 var(--sans); letter-spacing: 0; }
.marquee-actions { display: flex; align-items: flex-end; gap: 12px; }
.menu-chip {
    min-height: 42px;
    border: 1px solid var(--ink);
    padding: 0 14px;
    background: var(--paper-bright);
    cursor: pointer;
    font: 800 .68rem var(--mono);
    text-transform: uppercase;
    box-shadow: 4px 4px 0 var(--ink);
}
.menu-chip:hover { background: var(--yellow); }
.surprise {
    width: 68px;
    aspect-ratio: 1;
    border: 0;
    background: var(--coral);
    box-shadow: 5px 5px 0 var(--ink);
    cursor: pointer;
    font-size: 1.7rem;
    transition: transform .15s, box-shadow .15s;
}
.surprise:hover { transform: translate(-2px, -2px); box-shadow: 7px 7px 0 var(--ink); }
.surprise:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }

.daily-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--paper-bright);
    border: 1px solid #8c9688;
    box-shadow: 4px 4px 0 var(--ink);
}
.daily-copy { min-width: 0; display: grid; gap: 4px; }
.daily-copy .kicker { margin: 0; }
.daily-copy strong { font: 800 1rem/1.2 var(--sans); }
.daily-copy span { color: #667166; font: 700 .68rem var(--mono); text-transform: uppercase; }
.daily-banner .btn { flex: 0 0 auto; min-width: 96px; }

.library-tools { display: flex; align-items: center; gap: 14px; padding: 17px 0; border-bottom: 1px solid #a5ad9e; }
.search-box { flex: 1 1 260px; min-width: 180px; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--paper-bright); border: 1px solid #8c9688; }
.search-box span { font: 700 1.3rem var(--mono); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search-box input::placeholder { color: #7e897f; }
.filter-tabs { display: flex; flex-wrap: wrap; border: 1px solid #798477; }
.filter-tabs button { min-height: 40px; border: 0; border-right: 1px solid #798477; padding: 0 13px; background: transparent; cursor: pointer; font: 700 .68rem var(--mono); text-transform: uppercase; }
.filter-tabs button:last-child { border-right: 0; }
.filter-tabs button:hover { background: #d6dac7; }
.filter-tabs button.is-active { background: var(--ink); color: var(--paper-bright); }

.shelf-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 0 11px; font: 700 .68rem var(--mono); text-transform: uppercase; }
.shelf-heading p { margin: 0; }
.shelf-heading span { color: #667166; }
.game-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid #8d9789; border-left: 1px solid #8d9789; }
.game-card {
    --accent-color: var(--mint);
    position: relative;
    min-width: 0;
    min-height: 220px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--paper-bright);
    border-right: 1px solid #8d9789;
    border-bottom: 1px solid #8d9789;
    overflow: hidden;
    animation: cartridge-in .35s both;
    animation-delay: calc(var(--order) * 25ms);
}
.game-card::after { content: ''; position: absolute; right: 0; bottom: 0; width: 44px; height: 5px; background: var(--accent-color); }
.accent-mint { --accent-color: var(--mint); }
.accent-coral { --accent-color: var(--coral); }
.accent-yellow { --accent-color: var(--yellow); }
.accent-blue { --accent-color: var(--blue); }
.accent-violet { --accent-color: var(--violet); }
.accent-orange { --accent-color: var(--orange); }
.accent-lime { --accent-color: var(--lime); }
.accent-red { --accent-color: var(--red); }
.cartridge-top, .cartridge-foot { display: flex; justify-content: space-between; align-items: center; min-width: 0; font: 700 .61rem var(--mono); text-transform: uppercase; }
.cartridge-top { padding: 10px 12px 0; }
.cartridge-foot { padding: 8px 12px; color: #657066; border-top: 1px solid #cad0bf; }
.game-number { color: #747e75; }
.favorite-button { width: 31px; height: 31px; border: 0; background: transparent; cursor: pointer; color: var(--ink); font-size: 1.15rem; line-height: 1; }
.favorite-button:hover { color: var(--coral); }
.cartridge-launch { width: 100%; min-width: 0; display: grid; grid-template-columns: 66px 1fr; align-items: center; gap: 12px; padding: 10px 15px 15px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.game-glyph { width: 60px; aspect-ratio: 1; display: grid; place-items: center; color: var(--ink); background: var(--accent-color); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); font: 800 1.7rem var(--mono); transition: transform .16s, box-shadow .16s; }
.cartridge-launch:hover .game-glyph { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.game-copy { min-width: 0; display: grid; gap: 7px; }
.game-copy strong { font-size: 1.02rem; line-height: 1.05; overflow-wrap: anywhere; }
.game-copy small { color: #6a746b; font-size: .75rem; line-height: 1.35; }
.empty-library { margin: 0; padding: 54px 10px; border: 1px solid #8d9789; text-align: center; color: #687269; font: 700 .78rem var(--mono); }
@keyframes cartridge-in { from { opacity: 0; transform: translateY(8px); } }

.game-view { padding: 18px 28px 24px; }
.game-toolbar { min-height: 52px; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 12px; margin-bottom: 12px; }
.icon-button { width: 42px; aspect-ratio: 1; border: 1px solid var(--ink); background: var(--paper-bright); cursor: pointer; font: 700 1.3rem var(--mono); }
.icon-button:hover { background: var(--yellow); }
.game-ident { text-align: center; min-width: 0; }
.game-ident span { color: #6e796f; font: 700 .58rem var(--mono); }
.game-title { margin: 2px 0 0; font-size: 1.14rem; line-height: 1.1; overflow-wrap: anywhere; }
.game-stage {
    position: relative;
    width: min(100%, 720px);
    aspect-ratio: 1;
    min-height: 300px;
    margin: 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: var(--case-dark);
    border: 11px solid var(--case);
    outline: 2px solid var(--case-dark);
    box-shadow: inset 0 0 0 2px #607066, 7px 7px 0 #788277;
}
.game-canvas { display: block; width: min(100%, 650px); height: min(100%, 650px); max-width: 100%; max-height: 100%; object-fit: contain; background: #111713; image-rendering: pixelated; }
.screen-glass { position: absolute; inset: 0; pointer-events: none; z-index: 8; background: repeating-linear-gradient(0deg, rgba(0,0,0,.06) 0 1px, transparent 1px 4px); box-shadow: inset 0 0 55px rgba(0,0,0,.45); }
.pause-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: grid;
    place-items: center;
    pointer-events: none;
    background: rgba(17, 23, 19, 0.72);
    color: var(--yellow);
    font: 700 2rem var(--mono);
    letter-spacing: .08em;
}
.controls-hint { min-height: 20px; margin: 17px auto 0; text-align: center; color: #5d685f; font: 700 .68rem/1.4 var(--mono); }

.memory-board { position: relative; z-index: 2; width: min(90%, 520px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px; }
.memory-card { aspect-ratio: 1; border: 2px solid #809083; background: #27332b; color: var(--paper-bright); cursor: pointer; display: grid; place-items: center; font-size: 1.75rem; transition: transform .15s, background .15s; }
.memory-card:hover:not(.flipped):not(.matched) { transform: translateY(-2px); background: #34473a; }
.memory-card .card-back { color: var(--mint); font: 800 1.3rem var(--mono); }
.memory-card .card-face { display: none; }
.memory-card.flipped, .memory-card.matched { background: #e9ead8; color: var(--ink); border-color: var(--yellow); }
.memory-card.flipped .card-back, .memory-card.matched .card-back { display: none; }
.memory-card.flipped .card-face, .memory-card.matched .card-face { display: block; }
.memory-card.matched { opacity: .62; }

.overlay { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 18px; background: rgba(16,23,19,.82); backdrop-filter: blur(5px); }
.overlay-card { width: min(420px, 100%); padding: 25px; background: var(--paper-bright); border: 2px solid var(--ink); box-shadow: 10px 10px 0 var(--coral); }
.overlay-card h3 { margin: 0 0 8px; font-size: 2rem; line-height: 1; }
.overlay-msg { min-height: 40px; margin: 0 0 15px; color: #677168; font: 700 .76rem/1.5 var(--mono); }
.result-record { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-top: 1px solid #9ca598; border-bottom: 1px solid #9ca598; font: 700 .65rem var(--mono); }
.result-record strong { color: var(--coral); font-size: 1.55rem; }
.overlay-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 17px; }
.btn { min-height: 43px; border: 1px solid var(--ink); padding: 8px 15px; cursor: pointer; font: 800 .72rem var(--mono); text-transform: uppercase; }
.btn-primary { color: var(--ink); background: var(--yellow); }
.btn-secondary { color: var(--paper-bright); background: var(--case-dark); }
.btn:hover { filter: brightness(1.07); }

.records-card { width: min(520px, 100%); }
.records-list {
    max-height: min(48vh, 360px);
    overflow: auto;
    margin: 4px 0 0;
    border-top: 1px solid #9ca598;
}
.records-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: baseline;
    padding: 10px 0;
    border-bottom: 1px solid #d5d9c8;
    font: 700 .68rem var(--mono);
    text-transform: uppercase;
}
.records-name { color: var(--ink); overflow-wrap: anywhere; }
.records-best { color: var(--coral); white-space: nowrap; }
.records-plays { color: #667166; white-space: nowrap; }
.records-actions { margin-top: 14px; }

.ad-rail:not([hidden]), .result-ad:not([hidden]) { display: flex; min-height: 88px; align-items: center; gap: 14px; margin-top: 17px; padding: 10px; border: 1px dashed #7e887e; color: #687269; font: 700 .57rem var(--mono); }
.ad-rail .ad-frame, .result-ad .ad-frame { min-height: 66px; flex: 1; }
.result-ad:not([hidden]) { min-height: 70px; margin-top: 14px; }

.page-foot { min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 18px; color: #95a197; background: var(--case-dark); font: 700 .57rem var(--mono); }
.page-foot nav { display: flex; flex-wrap: wrap; gap: 14px; }
.page-foot a { color: var(--paper-bright); }
.flintglade-attribution { display: inline-flex; align-items: center; gap: 7px; color: #ff617e !important; font: 800 .57rem var(--mono); letter-spacing: .06em; text-decoration: none; text-transform: uppercase; }
.flintglade-attribution img { display: block; border-radius: 5px; box-shadow: 0 0 10px rgba(255,23,69,.18); }
.prose { padding: 28px; color: var(--ink); line-height: 1.65; user-select: text; }
.prose h1 { font-size: 2.2rem; }
.prose a { color: #9e3029; }
.logo { color: var(--yellow); font: 800 1.1rem var(--mono); }

.guide-shell { position: relative; width: min(1040px, calc(100% - 32px)); margin: 18px auto 28px; color: var(--ink); background: var(--paper-bright); border: 1px solid #7d8675; box-shadow: 0 6px 0 #5e665b, 0 22px 65px rgba(21,28,24,.2); }
.guide-topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 18px; color: var(--paper-bright); background: var(--case-dark); border-bottom: 5px solid var(--coral); }
.guide-topbar nav, .guide-footer nav { display: flex; flex-wrap: wrap; gap: 16px; font: 700 .62rem var(--mono); text-transform: uppercase; }
.guide-topbar a, .guide-footer a { color: var(--paper-bright); }
.guide-article { user-select: text; }
.guide-hero { padding: clamp(38px, 7vw, 80px) clamp(20px, 6vw, 70px) 42px; background: var(--paper); border-bottom: 2px solid var(--ink); }
.guide-hero h1 { max-width: 850px; font-size: clamp(2.6rem, 7vw, 5.5rem); }
.guide-lead { max-width: 800px; margin: 25px 0 0; color: #4f5d52; font-size: clamp(1rem, 2vw, 1.2rem); line-height: 1.65; }
.guide-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 630px; margin-top: 32px; border-top: 1px solid var(--ink); border-left: 1px solid var(--ink); }
.guide-facts div { min-height: 86px; display: grid; align-content: space-between; gap: 7px; padding: 12px; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.guide-facts strong { color: #9e3029; font: 800 1.35rem var(--mono); }
.guide-facts span { color: #59645b; font: 700 .6rem var(--mono); text-transform: uppercase; }
.guide-article > section { padding: 42px clamp(20px, 6vw, 70px); border-bottom: 1px solid #aeb5a6; }
.section-code { margin: 0 0 8px; color: #9e3029; font: 800 .62rem var(--mono); text-transform: uppercase; }
.guide-article h2 { max-width: 780px; margin: 0 0 18px; font-size: clamp(1.65rem, 4vw, 2.7rem); line-height: 1.05; }
.guide-article h3 { margin: 0 0 8px; color: #9e3029; font-size: 1rem; }
.guide-article p, .guide-article li { max-width: 820px; color: #435047; font-size: .98rem; line-height: 1.72; }
.guide-article a { color: #85251f; font-weight: 700; }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 25px; background: #9ca598; border: 1px solid #9ca598; }
.guide-grid > div { padding: 22px; background: var(--paper); }
.guide-grid p { margin-bottom: 0; }
.guide-table-wrap { overflow-x: auto; margin: 25px 0; border: 1px solid #8b9688; }
.guide-table-wrap table { width: 100%; min-width: 680px; border-collapse: collapse; background: var(--paper); }
.guide-table-wrap caption { padding: 12px; color: #59645b; background: #d7dac9; text-align: left; font: 700 .63rem var(--mono); }
.guide-table-wrap th, .guide-table-wrap td { padding: 11px 12px; border-top: 1px solid #b6bdae; text-align: left; vertical-align: top; font-size: .85rem; line-height: 1.45; }
.guide-table-wrap thead th { color: var(--paper-bright); background: var(--case-dark); border-top: 0; font: 700 .62rem var(--mono); text-transform: uppercase; }
.guide-table-wrap tbody th { color: #85251f; }
.guide-steps { display: grid; gap: 12px; padding-left: 25px; }
.guide-steps li { padding-left: 7px; }
.guide-article kbd { padding: 2px 5px; border: 1px solid #7c877c; color: var(--ink); background: #dadccc; box-shadow: 0 2px 0 #7c877c; font: 700 .8rem var(--mono); }
.guide-faq details { max-width: 820px; border-top: 1px solid #9ca598; }
.guide-faq details:last-child { border-bottom: 1px solid #9ca598; }
.guide-faq summary { padding: 16px 0; cursor: pointer; color: var(--ink); font-weight: 800; }
.guide-faq details p { margin-top: 0; padding-bottom: 8px; }
.guide-footer { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 18px; color: #95a197; background: var(--case-dark); font: 700 .57rem var(--mono); }

.consentbar { position: fixed; left: 50%; bottom: 15px; transform: translateX(-50%); z-index: 300; width: min(590px, calc(100vw - 24px)); padding: 14px 16px; color: var(--paper-bright); background: var(--case-dark); border: 1px solid #657268; box-shadow: 7px 7px 0 rgba(24,32,24,.35); font-size: .8rem; }
.consentbar a { color: var(--yellow); }
.consentbar__actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 10px; }
.consentbar__btn { min-height: 35px; border: 1px solid #839087; padding: 6px 13px; color: var(--paper-bright); background: transparent; cursor: pointer; }
.consentbar__btn--accept { color: var(--ink); background: var(--mint); border-color: var(--mint); }

@media (max-width: 820px) {
    .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .library-tools { align-items: stretch; flex-direction: column; }
    .filter-tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .filter-tabs button { flex: 1 0 auto; }
}

@media (max-width: 560px) {
    .arcade-shell, .main-container { width: 100%; margin: 0; border: 0; box-shadow: none; }
    .topbar, .header { min-height: 64px; padding: 9px 12px; }
    .brand { font-size: .95rem; }
    .brand-mark { width: 33px; }
    .library-count { display: none; }
    .header-stats { width: 100%; order: 3; }
    .topbar:has(.header-stats:not([hidden])) { flex-wrap: wrap; }
    .readout { flex: 1; min-width: 0; }
    .menu-view, .game-view { padding-left: 14px; padding-right: 14px; }
    .marquee-band { min-height: 126px; }
    h1 { font-size: 2.65rem; }
    .surprise { width: 53px; }
    .marquee-actions { gap: 8px; }
    .menu-chip { min-height: 38px; padding: 0 10px; font-size: .62rem; }
    .daily-banner { flex-direction: column; align-items: stretch; }
    .records-row { grid-template-columns: 1fr; gap: 4px; }
    .game-grid { grid-template-columns: 1fr; }
    .game-card { min-height: 178px; }
    .cartridge-launch { grid-template-columns: 58px 1fr; }
    .game-glyph { width: 52px; }
    .game-stage { border-width: 7px; min-height: 290px; }
    .memory-board { gap: 5px; padding: 7px; }
    .memory-card { font-size: 1.3rem; }
    .overlay-card { padding: 20px; box-shadow: 6px 6px 0 var(--coral); }
    .guide-shell { width: 100%; margin: 0; border: 0; box-shadow: none; }
    .guide-topbar, .guide-footer { align-items: flex-start; flex-direction: column; }
    .guide-topbar .brand { padding-left: 0; }
    .guide-facts, .guide-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
