body:has(#glassworks) { background: #0f1922; }
body:has(#glassworks) > header { display: none; }
body:has(#glassworks) > main { width: 100%; max-width: none; margin: 0; padding: 0; }
body:has(#glassworks) > footer { display: none; }

#glassworks {
  --ink: #eff5f1;
  --muted: #adc3c6;
  --mint: #9ee8cf;
  --line: #39505a;
  --rows: 18;
  --columns: 8;
  --row-height: clamp(23px, calc((100svh - 220px) / var(--rows)), 35px);
  min-height: 100svh;
  padding: 28px 20px 28px;
  color: var(--ink);
  text-align: left;
  font-family: 'Instrument Sans', system-ui, sans-serif;
  background: radial-gradient(ellipse at 34% 0%, #34545194 0%, transparent 57%), radial-gradient(ellipse at 83% 28%, #46314c61 0%, transparent 55%), linear-gradient(155deg, #1b2b35, #0e1821 80%);
  color-scheme: dark;
}
#glassworks *, #glassworks *::before, #glassworks *::after { box-sizing: border-box; }
#glassworks button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
#glassworks button:disabled { opacity: .48; cursor: default; }
#glassworks :focus-visible { outline: 2px solid #fff2bd; outline-offset: 2px; }
#glassworks [hidden] { display: none; }
.gw-layout {
  max-width: 724px;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 385px) minmax(0, 1fr);
  grid-template-areas: 'intro .' 'play guide';
  align-items: start;
  gap: 15px 28px;
}
.gw-intro { grid-area: intro; position: relative; }
#glassworks .gw-back { display: inline-flex; align-items: center; gap: 6px; min-height: 22px; color: var(--muted); font-size: .8rem; text-decoration: none; }
#glassworks .gw-back .gw-chevron { width: 6px; height: 6px; transform: rotate(-135deg); }
#glassworks .gw-back:hover { color: var(--ink); text-decoration: underline; }
#glassworks h1 { font: 500 clamp(2.5rem, 5vw, 3.5rem)/1 Georgia, serif; letter-spacing: -.055em; color: var(--ink); margin: 8px 0 4px; }
#glassworks h1 span { color: #ffb899; }
#glassworks #gw-laser-help { position: absolute; right: 0; bottom: 0; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 9px; border: 1px solid #8b6766; border-radius: 11px; background: #372d38; color: #ffe1ce; font-size: .72rem; font-weight: 700; white-space: nowrap; }
#glassworks #gw-laser-help:hover, #glassworks #gw-laser-help:focus-visible { background: #493541; }
.gw-laser-lens { display: block; width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #fff0d1; box-shadow: 0 0 0 2px #ed989c65, 0 0 9px 2px #ff939ba8; }
.gw-play { grid-area: play; min-width: 0; }
.gw-frame { position: relative; padding: 0 7px 7px; border: 1px solid #557779; border-radius: 17px; background: linear-gradient(145deg, #365451, #253740 65%, #192b34); box-shadow: 0 14px 32px #050b1390, inset 0 1px #d3f3e82e; }
.gw-hud { display: grid; grid-template-columns: 1.15fr .7fr .7fr 1fr 44px; gap: 7px; min-height: 54px; padding: 4px 6px; align-items: center; }
.gw-hud > div { display: grid; gap: 3px; }
.gw-hud span { color: #bdd2d1; font-size: .66rem; line-height: 1; }
.gw-hud strong { color: #f5fbf2; font-size: 1.06rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
#gw-score { justify-self: start; }
#glassworks #gw-pause { height: 44px; width: 44px; border: 1px solid #58747a; border-radius: 9px; background: #172e37; display: grid; place-items: center; }
.gw-pause-icon { width: 11px; height: 13px; border-inline: 3px solid #d2eae3; }
.gw-board { position: relative; overflow: hidden; isolation: isolate; width: 100%; height: calc(var(--rows) * var(--row-height)); border-radius: 9px; background: radial-gradient(ellipse at 47% 8%, #27434a, #152730 52%, #101820 92%); }
.gw-grid, .gw-tiles, .gw-active, .gw-ghost, .gw-effects { position: absolute; inset: 0; }
.gw-tiles, .gw-active, .gw-ghost, .gw-effects { display: grid; grid-template: repeat(var(--rows), minmax(0, 1fr)) / repeat(var(--columns), minmax(0, 1fr)); pointer-events: none; }
.gw-active { --fall-step: 0%; }
.gw-active[data-falling] { --fall-step: calc(100% / var(--rows)); }
.gw-grid { background-image: linear-gradient(to right, #6884922a 1px, transparent 1px), linear-gradient(to bottom, #6884922a 1px, transparent 1px); background-size: calc(100% / var(--columns)) calc(100% / var(--rows)); box-shadow: inset 0 0 16px #080f1860; }
.gw-emitter { position: absolute; top: 0; right: 0; display: grid; place-items: center; width: 18px; height: 18px; border: 1px solid #bd7d76; border-radius: 4px 8px 4px 9px; background: linear-gradient(135deg, #70484f, #2a2433); pointer-events: none; }
.gw-cell { --glass: #376b82; --edge: #91d5ec; --glow: #cef3ff; position: relative; min-width: 0; margin: 1px; padding: 0; border-radius: 5px; border: 1px solid color-mix(in srgb, var(--edge) 72%, #233844); background: linear-gradient(145deg, color-mix(in srgb, var(--edge) 65%, var(--glass)), var(--glass) 67%); box-shadow: inset 0 2px 0 #ffffff40, inset 0 -3px 0 #0e172142; }
.gw-cell::before { content: ''; position: absolute; inset: 3px 3px 4px; border-radius: 3px; background: linear-gradient(145deg, #fff6 0%, #ffffff12 51%, #fff0 52%, #fff0 75%, #fff2 100%); box-shadow: inset 0 0 0 1px #f7ffff1b; }
.gw-cell[data-glass="teal"] { --glass: #277d73; --edge: #76ddbe; --glow: #c9fff0; }
.gw-cell[data-glass="rose"] { --glass: #8c485f; --edge: #f5a9b6; --glow: #ffe0da; }
.gw-cell[data-glass="violet"] { --glass: #604687; --edge: #bfabea; --glow: #ece0ff; }
.gw-cell[data-glass="gold"] { --glass: #9e682c; --edge: #f5ce74; --glow: #fff0a2; }
.gw-cell[data-glass="gold"]::after { content: ''; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; background: var(--glow); box-shadow: 0 0 8px var(--edge); transform: translate(-50%, -50%) rotate(45deg); }
#glassworks button.gw-cell { pointer-events: auto; cursor: crosshair; touch-action: none; filter: saturate(1.14) brightness(1.12); }
#glassworks button.gw-cell:focus-visible { z-index: 1; outline-offset: -3px; }
@media (hover: hover) { #glassworks button.gw-cell:hover { filter: saturate(1.1) brightness(1.42); } }
.gw-ghost span { margin: 2px; border: 1px dashed #b5f8e4bb; border-radius: 4px; background: #b5f8e418; }
.gw-ghost[data-shadow="faint"] { opacity: .45; }
.gw-overlay { position: absolute; inset: 0; display: grid; place-items: safe center; overflow-y: auto; padding: 10px; background: #101b25c9; z-index: 2; }
.gw-overlay > div { width: min(100%, 290px); padding: 17px; border: 1px solid #58857e; border-radius: 15px; background: #1d343c; box-shadow: 0 15px 45px #080e16aa; text-align: center; }
.gw-overlay.gw-welcome > div { width: min(100%, 310px); padding-top: 94px; background: linear-gradient(180deg, #13252b00 6%, #1d343c 57%), url('/glassworks-cover.webp') center top / 100% auto no-repeat, #1d343c; }
#glassworks .gw-overlay h2 { margin: 0; font: 500 1.7rem/1.1 Georgia, serif; color: var(--ink); }
#glassworks .gw-overlay p { margin: 8px 0 12px; font-size: .86rem; color: var(--muted); }
#glassworks .gw-overlay button, #glassworks [data-action="drop"] { color: #163631; border-color: #c1efd8; background: linear-gradient(#b3ecd2, #90ccb9); }
.gw-controls { display: grid; grid-template-columns: minmax(44px, 1fr) minmax(44px, 1fr) minmax(78px, 1.4fr) clamp(54px, 17%, 68px); gap: 6px; margin-top: 7px; }
#glassworks .gw-controls button, #glassworks #gw-restart, #glassworks .gw-overlay button { min-height: 48px; padding: 4px 10px; border: 1px solid #527079; border-radius: 10px; color: #e7f3ed; background: #223741; font-size: .9rem; font-weight: 700; }
#glassworks .gw-controls button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 54px; padding-inline: 5px; background: linear-gradient(#2e494d, #23383f); touch-action: none; user-select: none; }
#glassworks .gw-controls button:active, #glassworks .gw-overlay button:active { filter: brightness(1.18); }
#glassworks .gw-controls [data-action="rotate"], #glassworks .gw-overlay button { color: #163631; border-color: #c1efd8; background: linear-gradient(#b3ecd2, #90ccb9); }
#glassworks #gw-new-run { margin-left: 6px; border-color: #527079; background: #27454a; color: var(--ink); }
.gw-save { margin: 12px 0; padding-top: 11px; border-top: 1px solid #42625f; text-align: left; }
.gw-save label { display: block; margin-bottom: 5px; color: var(--ink); font-size: .8rem; font-weight: 650; }
.gw-save label span { color: var(--muted); font-weight: 400; }
.gw-save-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
#glassworks .gw-save input { min-width: 0; width: 100%; padding: 5px 9px; border: 1px solid #527079; border-radius: 8px; background: #14252e; color: var(--ink); font: inherit; font-size: 16px; }
#glassworks .gw-save input::placeholder { color: var(--muted); }
#glassworks .gw-save button { min-height: 44px; border-color: #527079; background: #27454a; color: var(--ink); font-size: .8rem; }
#glassworks #gw-save-status { min-height: 2.2em; margin: 5px 0 0; overflow-wrap: anywhere; color: var(--muted); font-size: .73rem; }
#gw-laser-guide { width: min(360px, calc(100% - 24px)); max-height: calc(100svh - 28px); margin: auto; padding: 17px; border: 1px solid #a97975; border-radius: 15px; background: #1c303a; color: var(--ink); text-align: left; box-shadow: 0 16px 44px #080e16a8; }
#gw-laser-guide::backdrop { background: #081218b5; }
#glassworks #gw-laser-guide h2 { margin: 0; color: var(--ink); font: 500 1.48rem/1.15 Georgia, serif; }
#glassworks #gw-laser-guide p { margin: 8px 0 13px; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.gw-cut-example { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: #14252e; text-align: center; }
.gw-demo-piece { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 21px; }
.gw-cut-example span { display: inline-block; margin-top: 5px; color: var(--muted); font-size: .73rem; }
.gw-cut-example .gw-demo-arrow { margin-top: -15px; color: var(--mint); font-size: 1.18rem; }
.gw-cut-target::after { content: ''; position: absolute; inset: 3px; border: 1px dashed #fff0d1; border-radius: 3px; }
.gw-cut-gap { margin: 1px; border: 1px dashed #9e7779; border-radius: 5px; }
#glassworks #gw-laser-guide .gw-laser-cost { margin-bottom: 8px; font-size: .77rem; }
#glassworks #gw-laser-guide button { min-height: 44px; padding: 5px 15px; border: 1px solid #c1efd8; border-radius: 9px; background: #a2ddc5; color: #163631; font-weight: 700; }
#glassworks .gw-controls [data-action="drop"] { gap: 2px; color: #c1d6d3; background: #1b2b34; font-size: .8rem; }
.gw-controls .gw-chevron { width: 12px; height: 12px; border-width: 2.5px; }
.gw-chevron { display: inline-block; width: 9px; height: 9px; border-right: 2px solid currentColor; border-top: 2px solid currentColor; transform: rotate(45deg); }
[data-action="left"] .gw-chevron { transform: rotate(-135deg); }
.gw-turn, .gw-down { display: inline-block; position: relative; width: 14px; height: 14px; flex: 0 0 14px; }
.gw-turn { width: 16px; height: 16px; flex-basis: 16px; }
.gw-turn { border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; }
.gw-turn::after { content: ''; position: absolute; right: -3px; top: 1px; width: 5px; height: 5px; border-right: 1.5px solid; border-bottom: 1.5px solid; }
.gw-down::before { content: ''; position: absolute; top: 1px; left: 6px; width: 1.5px; height: 9px; background: currentColor; }
.gw-down::after { content: ''; position: absolute; left: 4px; top: 5px; width: 6px; height: 6px; transform: rotate(45deg); border-right: 1.5px solid; border-bottom: 1.5px solid; }
#glassworks .gw-status { margin: 7px 0 0; min-height: 36px; color: #c6dbd7; font-size: .8rem; line-height: 1.4; }
.gw-level-note { display: block; color: #ffdea4; font-weight: 750; }
.gw-level-glow { position: absolute; inset: 0; z-index: 1; border-radius: inherit; pointer-events: none; box-shadow: inset 0 0 21px 4px #ffcf76a8; }
.gw-guide { grid-area: guide; min-width: 0; }
.gw-guide details { border: 1px solid var(--line); border-radius: 13px; background: #192b34; }
.gw-guide summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 14px; border-radius: 12px; list-style: none; cursor: pointer; color: var(--ink); font: 500 1.24rem/1.2 Georgia, serif; touch-action: manipulation; }
.gw-guide summary::-webkit-details-marker { display: none; }
.gw-guide summary:hover { background: #213840; }
.gw-help-icon { display: grid; width: 27px; height: 27px; place-items: center; border: 1px solid #42625f; border-radius: 8px; background: #233e42; color: var(--mint); font: 700 .88rem/1 system-ui, sans-serif; }
.gw-guide summary .gw-chevron { margin-inline: auto 2px; color: var(--mint); transform: translateY(-2px) rotate(135deg); }
.gw-guide details[open] summary .gw-chevron { transform: translateY(2px) rotate(-45deg); }
.gw-guide-body { padding: 13px 14px 14px; border-top: 1px solid var(--line); }
.gw-steps { display: grid; gap: 10px; list-style: none; padding: 0; margin: 0 0 16px; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.gw-steps strong { color: var(--ink); }
#glassworks .gw-guide h2 { margin: 0 0 6px; color: var(--ink); font: 500 1.16rem/1.2 Georgia, serif; }
.gw-values { padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; margin: 0; background: #14252e; font-size: .79rem; }
.gw-values > div { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; padding: 6px 0; }
.gw-values > div + div { border-top: 1px solid #39505a90; }
.gw-values dd { margin: 0; color: var(--mint); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gw-values > div:nth-last-child(-n+2) dd { color: #ffc2a6; }
#glassworks .gw-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 9px; margin: 12px 0; color: var(--muted); font-size: .72rem; }
.gw-keys span { white-space: nowrap; }
.gw-keys kbd { padding: 1px 4px; border: 1px solid var(--line); border-radius: 4px; background: #14252e; color: var(--ink); font: inherit; }
.gw-laser, .gw-spark, .gw-score-pop { position: absolute; pointer-events: none; }
.gw-laser { height: 2px; border-radius: 2px; background: #fff3c4; box-shadow: 0 0 7px 2px #ffab9c, 0 0 16px 3px #f36d8c; transform-origin: left center; }
.gw-spark { width: 4px; height: 4px; border-radius: 1px; background: #fff3ca; box-shadow: 0 0 6px #ff9f9c; }
.gw-score-pop { color: #ffceb6; font-size: .77rem; font-weight: 800; text-shadow: 0 1px 3px #111820; }
.gw-row-flash { grid-column: 1 / -1; background: linear-gradient(90deg, #a4fff580, #fff8d7, #a4fff580); box-shadow: 0 0 12px #d1ffed; }
.gw-row-flash[data-bonus] { background: linear-gradient(90deg, #ffb461a0, #fff8d7, #ffb461a0); }
.gw-shard { place-self: center; width: 12px; height: 14px; margin: 0; clip-path: polygon(6% 0, 100% 29%, 34% 100%); }
.gw-shard::before, .gw-shard[data-glass="gold"]::after { display: none; }
.gw-points-flight { position: absolute; z-index: 3; padding: 4px 9px; border: 1px solid #b9f9e8; border-radius: 7px; background: #1e4648; color: #e0fff2; font-size: 1rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }
.gw-points-flight[data-bonus] { padding: 5px 11px; border-color: #ffdb9d; background: #584035; color: #fff0c7; font-size: 1.2rem; box-shadow: 0 0 14px #ffbc6d52; }

@media (max-width: 650px) {
  #glassworks { --row-height: clamp(16px, calc((100svh - 211px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / var(--rows)), 34px); padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .gw-layout { max-width: 430px; grid-template-columns: minmax(0, 1fr); grid-template-areas: 'intro' 'play' 'guide'; gap: 8px; }
  #glassworks h1 { font-size: clamp(1.75rem, 8vw, 2.25rem); margin: 2px 0; }
  .gw-frame { padding: 0 5px 5px; border-radius: 13px; }
}
@media (max-width: 360px) {
  #glassworks { padding-inline: max(7px, env(safe-area-inset-left)) max(7px, env(safe-area-inset-right)); }
  .gw-controls { gap: 4px; }
}
@media (max-height: 490px) {
  .gw-overlay.gw-welcome > div { padding-top: 58px; }
}
