:root {
  color-scheme: dark;
  --background: #11141a;
  --surface: #1b2028;
  --raised: #252b35;
  --stroke: #353d49;
  --text: #f2f5f5;
  --muted: #bac3d0;
  --accent: #d9f78d;
  --ink: #171e16;
  --body: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--text); font: 500 1rem/1.5 var(--body); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button, a { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.shell { width: min(1500px, calc(100% - 88px)); margin-inline: auto; }
.site-header { border-bottom: 1px solid #2e343d; }
.header-inner { min-height: 74px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center; }
.brand { display: inline-flex; gap: 10px; align-items: center; justify-self: start; font: 800 1.19rem/1 var(--body); letter-spacing: -.043em; white-space: nowrap; }
.brand small { display: block; margin-top: 3px; font: 750 .64rem/1 var(--mono); letter-spacing: .22em; color: var(--muted); }
.brand-period { color: var(--accent); }
.brand-icon { display: grid; grid-template-columns: repeat(2, 6px); grid-template-rows: repeat(2, 6px); place-content: center; gap: 3px; width: 34px; height: 34px; border-radius: 8px; background: var(--accent); }
.brand-icon i { background: #252d24; border-radius: 1px; }
.brand-icon i:nth-child(2) { background: #718657; transform: translate(1px, -1px); }
.main-nav { display: flex; gap: 26px; align-items: center; align-self: stretch; }
.main-nav a { color: var(--muted); display: inline-flex; align-items: center; gap: 5px; height: 100%; font-size: .94rem; position: relative; white-space: nowrap; }
.main-nav a[aria-current="page"] { color: var(--text); }
.main-nav a[aria-current="page"]::after { content: ""; position: absolute; bottom: -1px; right: 0; left: 0; height: 2px; background: var(--accent); }
.main-nav a span { font-size: 1.18rem; line-height: 1; }
.site-header .sound-button { justify-self: end; }
.sound-button, .outline-button, .dock-button, .icon-control {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px;
  border: 1px solid var(--stroke); border-radius: 8px; padding: 0 13px; background: var(--surface); color: var(--text);
  font-size: .88rem; font-weight: 720; white-space: nowrap;
}
.sound-button:hover, .outline-button:hover, .dock-button:not(:disabled):hover, .icon-control:hover { background: var(--raised); border-color: #677487; }
.speaker { position: relative; width: 17px; height: 16px; flex: 0 0 17px; display: block; }
.speaker::before { content: ""; position: absolute; inset: 1px 5px 1px 0; background: currentColor; clip-path: polygon(0 30%,36% 30%,80% 0,80% 100%,36% 70%,0 70%); }
.speaker::after { content: "×"; position: absolute; right: -2px; top: 1px; font: 700 14px/1 var(--mono); }
.sound-button[aria-pressed="true"] .speaker::after { content: "))"; letter-spacing: -.2em; top: 2px; right: 0; font-size: 12px; }
.hero { position: relative; isolation: isolate; display: grid; align-items: center; overflow: hidden; min-height: 370px; margin-top: 26px; border: 1px solid #444050; border-radius: 16px; background: #1b1926; }
.hero::after { content: ""; position: absolute; z-index: -1; inset: 0; pointer-events: none; background: linear-gradient(90deg,#1c1b29 3%,#1c1b29 24%,#1c1b29d4 40%,#1c1b2900 68%); }
.hero-art { position: absolute; z-index: -2; width: 77%; height: 100%; inset: 0 0 0 auto; object-fit: cover; object-position: right 42%; image-rendering: pixelated; }
.hero-content { padding: 33px 44px 36px; }
.hero-kicker { display: flex; align-items: center; gap: 8px; color: #e1e6d9; font: 700 .77rem/1.4 var(--mono); letter-spacing: .13em; }
.hero-kicker > span:first-child { color: var(--accent); }
.hero h1 { margin-top: 11px; color: #f5f3ec; font: 800 clamp(3.6rem,7vw,6.4rem)/.87 var(--body); letter-spacing: -.06em; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 17px 0 19px; color: #e4deea; font-size: 1.02rem; }
.primary-button { display: inline-flex; justify-content: center; align-items: center; gap: 9px; min-height: 44px; padding: 0 15px; border-radius: 7px; background: var(--accent); color: var(--ink); font-size: .93rem; font-weight: 800; }
.primary-button:hover { background: #eeffc6; }
.play-icon { display: inline-block; width: 9px; height: 11px; background: currentColor; clip-path: polygon(0 0,100% 50%,0 100%); }
.hero-caption { display: flex; align-items: center; gap: 7px; position: absolute; right: 15px; bottom: 15px; color: #e9d9d6; padding: 7px 9px; background: #231e2cdb; border: 1px solid #e0bdac4c; border-radius: 6px; font: 700 .66rem/1.2 var(--mono); letter-spacing: .075em; }
.hero-caption i { width: 3px; height: 3px; border-radius: 50%; background: #d9b59b; }
.catalog { padding: 31px 0 47px; min-height: 290px; }
.catalog-heading { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.catalog h2 { font: 800 clamp(2rem,4vw,3rem)/1.05 var(--body); letter-spacing: -.05em; }
.catalog-tools { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: 15px 0 16px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button { border: 1px solid #39434e; background: #191e26; min-height: 36px; border-radius: 7px; padding: 4px 12px; font-size: .86rem; color: var(--muted); }
.filters button:hover { border-color: #6e7b88; color: var(--text); }
.filters button[aria-pressed="true"] { background: #29372a; color: #e4f8b5; border-color: #526545; font-weight: 800; }
#game-count { color: var(--muted); font: 600 .78rem/1.5 var(--mono); white-space: nowrap; }
.game-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 15px; }
.game-card { position: relative; overflow: hidden; border: 1px solid var(--stroke); border-radius: 11px; background: var(--surface); transition: transform .15s,border-color .15s; }
.game-card:hover { transform: translateY(-3px); border-color: var(--card-accent); }
.card-link { display: block; height: 100%; }
.card-link:focus-visible { outline-offset: -3px; border-radius: 11px; }
.card-art { display: block; width: 100%; height: auto; aspect-ratio: 17 / 9; object-fit: cover; image-rendering: pixelated; }
.card-info { padding: 13px 14px 14px; }
.card-info h3 { font: 800 1.16rem/1.15 var(--body); letter-spacing: -.025em; margin-bottom: 5px; }
.card-info p { color: var(--muted); font-size: .875rem; line-height: 1.35; }
.card-category { display: inline-block; margin-top: 9px; color: var(--card-accent); font: 700 .7rem/1.3 var(--mono); }
.favorite-button { position: absolute; display: grid; place-items: center; top: 8px; right: 8px; width: 40px; height: 40px; padding: 0 0 2px; border-radius: 8px; border: 1px solid #ecdbf359; background: #171b24e8; font: 600 1.28rem/1 var(--body); }
.favorite-button[aria-pressed="true"], .favorite-button:hover { color: var(--accent); border-color: var(--accent); }
.empty { display: grid; gap: 12px; justify-items: center; padding: 30px; background: var(--surface); border: 1px solid var(--stroke); border-radius: 12px; color: var(--muted); text-align: center; }
.empty > span { color: var(--accent); font-size: 2rem; }
.site-footer { display: flex; justify-content: space-between; border-top: 1px solid var(--stroke); color: var(--muted); padding: 17px 0 23px; font-size: .86rem; }

body.playing { overflow: hidden; }
body.playing > .site-header, body.playing > .site-footer { display: none; }
.play-view {
  position: fixed; inset: 0; width: 100%; height: 100dvh; min-width: 0;
  display: grid; grid-template-rows: auto minmax(0,1fr) auto; background: #10131b;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.play-view:fullscreen { width: 100%; height: 100%; }
.play-bar {
  display: grid; grid-template-columns: 40px minmax(0,1fr) auto; align-items: center; gap: 12px;
  min-height: 62px; padding: 7px 17px; border-bottom: 1px solid #343c48; background: #171b24;
}
.play-heading { min-width: 0; display: flex; align-items: center; gap: 15px; }
.play-heading h1 { color: #f5f7f6; font: 800 clamp(1.14rem,2.5vw,1.58rem)/1.06 var(--body); letter-spacing: -.035em; white-space: nowrap; }
.stage-selector { min-width: 0; display: inline-flex; gap: 8px; align-items: center; background: #222934; border: 1px solid #394451; border-radius: 7px; padding: 4px 9px; color: #d7e0e8; font-size: .79rem; font-weight: 700; white-space: nowrap; }
.stage-selector:hover { border-color: #7a8999; }
#current-stage { overflow: hidden; text-overflow: ellipsis; text-align: left; }
.chevron { width: 6px; height: 6px; border-bottom: 1px solid currentColor; border-right: 1px solid currentColor; transform: translateY(-2px) rotate(45deg); flex: 0 0 6px; }
.play-tools { display: flex; gap: 6px; }
.play-view .icon-control { width: 40px; height: 40px; min-height: 40px; padding: 0; flex: 0 0 auto; font-size: 1.27rem; }
.play-view .icon-control[aria-pressed="true"] { color: var(--accent); }
.back-icon { width: 10px; height: 10px; border-bottom: 2px solid currentColor; border-left: 2px solid currentColor; transform: translateX(2px) rotate(45deg); }
.pause-icon { width: 11px; height: 13px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; }
.expand-icon {
  width: 15px; height: 15px;
  background:
    linear-gradient(currentColor,currentColor) left top / 5px 2px no-repeat,
    linear-gradient(currentColor,currentColor) left top / 2px 5px no-repeat,
    linear-gradient(currentColor,currentColor) right top / 5px 2px no-repeat,
    linear-gradient(currentColor,currentColor) right top / 2px 5px no-repeat,
    linear-gradient(currentColor,currentColor) left bottom / 5px 2px no-repeat,
    linear-gradient(currentColor,currentColor) left bottom / 2px 5px no-repeat,
    linear-gradient(currentColor,currentColor) right bottom / 5px 2px no-repeat,
    linear-gradient(currentColor,currentColor) right bottom / 2px 5px no-repeat;
}

.canvas-wrap {
  position: relative; min-width: 0; min-height: 0; overflow: hidden; isolation: isolate;
  background: radial-gradient(ellipse at 50% 42%,#242633 0,#131620 69%,#0b0e15 100%);
}
.play-view[data-game="bus"] .canvas-wrap { background: #233546; }
.play-view[data-game="brick"] .canvas-wrap { background: #11121b; }
.play-view[data-game="rings"] .canvas-wrap { background: #0c101a; }
.play-view[data-game="string"] .canvas-wrap { background: #131723; }
#board { width: 100%; height: 100%; display: block; object-fit: contain; touch-action: none; cursor: crosshair; outline: none; }
#board:focus-visible { outline: 2px solid #ffffff35; outline-offset: -2px; }
.game-dock {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 7px 14px;
  min-height: 54px; padding: 6px 16px; background: #171b24; border-top: 1px solid #343c48;
}
.game-status { color: var(--accent); font: 700 .84rem/1.34 var(--mono); min-width: 0; }
.game-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.dock-button { min-height: 40px; }
.dock-button:disabled { opacity: .46; }
.dock-button[data-primary], .dock-button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #161d23; font-weight: 800; }
.dock-button[data-primary]:not(:disabled):hover { background: color-mix(in srgb,var(--accent) 75%,white); }
.game-result {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); pointer-events: none;
  width: max-content; max-width: calc(100% - 30px); min-width: min(260px,calc(100% - 30px));
  padding: 14px 23px 16px; text-align: center; border: 1px solid #707a92aa; border-radius: 12px;
  background: #151a26f5; box-shadow: 0 9px 40px #0709129c;
}
.game-result[data-place="low"] { top: auto; bottom: clamp(9px,4%,46px); transform: translateX(-50%); }
.game-result strong { display: block; color: var(--accent); font-size: clamp(1.26rem,4vw,1.89rem); line-height: 1.16; letter-spacing: -.025em; }
.game-result p { margin-top: 4px; color: #e0e6ef; font-size: .89rem; }
.play-view dialog {
  width: min(460px,calc(100% - 26px)); border: 1px solid #4b596a; border-radius: 14px; color: var(--text);
  background: #1d2531; padding: 17px; box-shadow: 0 16px 70px #06090bbf;
}
.play-view dialog::backdrop { background: #091018b7; backdrop-filter: blur(5px); }
.modal-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 11px; }
.modal-heading h2 { font: 800 1.45rem/1.1 var(--body); letter-spacing: -.035em; }
#game-menu p, #level-progress { color: var(--muted); font-size: .95rem; }
#game-menu #keyboard-help { margin-top: 9px; color: #aabed2; font-size: .82rem; }
.modal-actions { margin-top: 18px; display: flex; justify-content: space-between; gap: 9px; }
.level-buttons { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; margin-top: 12px; }
.level-buttons button { display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 44px; padding: 5px 8px; border: 1px solid #526071; border-radius: 7px; background: #252e3d; text-align: left; font-size: .83rem; font-weight: 700; }
.level-buttons button span:first-child { color: var(--accent); font: 700 .85rem/1 var(--mono); }
.level-buttons button[aria-current="step"] { border-color: var(--accent); }
.level-buttons button[data-cleared] { background: #334136; }
.level-buttons button:disabled { opacity: .48; }
@media (max-width: 950px) {
  .shell { width: calc(100% - 45px); }
  .game-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 680px) {
  .shell { width: calc(100% - 26px); }
  .header-inner { min-height: 62px; gap: 9px; }
  .brand { gap: 7px; font-size: 1.02rem; }
  .brand-icon { width: 29px; height: 29px; }
  .main-nav { gap: 13px; }
  .main-nav a { font-size: .81rem; }
  .site-header .sound-button { padding-inline: 8px; min-height: 36px; }
  .sound-label { display: none; }
  .hero { margin-top: 13px; min-height: 291px; }
  .hero-art { width: 100%; }
  .hero::after { background: linear-gradient(90deg,#1c1b29 0,#1c1b29d8 37%,#1c1b2936 100%); }
  .hero-content { padding: 29px 20px; }
  .hero h1 { font-size: clamp(2.85rem,12vw,4.55rem); }
  .hero-caption { display: none; }
  .catalog { padding-top: 23px; }
  .game-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .card-info { padding: 9px 10px 11px; }
  .card-info h3 { font-size: 1.03rem; }
  .card-info p { font-size: .81rem; }
  .favorite-button { width: 36px; height: 36px; top: 6px; right: 6px; }
  .catalog-tools { align-items: flex-start; }
  #game-count { padding-top: 7px; }
  .filters button { padding-inline: 8px; font-size: .8rem; }
  .play-bar { grid-template-columns: 38px minmax(0,1fr) auto; min-height: 58px; padding: 5px 7px; gap: 7px; }
  .play-heading { display: grid; gap: 2px; }
  .play-heading h1 { overflow: hidden; text-overflow: ellipsis; }
  .stage-selector { justify-self: start; max-width: 100%; padding: 1px 4px; border-color: transparent; background: transparent; font-size: .71rem; }
  .play-tools { gap: 3px; }
  .play-view .icon-control { min-height: 38px; width: 35px; height: 38px; }
  .game-dock { min-height: 48px; padding: 5px 7px; gap: 5px; }
  .game-status { font-size: .76rem; }
  .game-actions { gap: 4px; justify-content: flex-start; }
  .dock-button { padding-inline: 8px; min-height: 39px; font-size: .81rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
@media (max-width: 680px) {
  .game-actions:has(> button:not([hidden]) ~ button:not([hidden])) { width: 100%; }
  .game-actions:has(> button:not([hidden]) ~ button:not([hidden])) > button { flex: 1; }
}
