@layer base, console, controls, help, responsive, device;
@layer base {
  :root { color-scheme: dark; font-family: Arial, Helvetica, sans-serif; --ink: #17271d; --lcd: #99a880; --blue: #1485e6; --case-ink: #073057; }
  * { box-sizing: border-box; }
  html { touch-action: pan-y; overscroll-behavior: none; }
  body { margin: 0; min-width: 280px; min-height: 100svh; background: radial-gradient(ellipse at 50% 35%, #243642 0, #121d25 55%, #10181e 100%); color: #b6c5ce; }
  [hidden] { display: none !important; }
  button, summary { -webkit-tap-highlight-color: transparent; }
  button { font: inherit; cursor: pointer; }
  button:focus-visible, summary:focus-visible { outline: 3px solid #fff9b7; outline-offset: 5px; }
  button:disabled { cursor: not-allowed; }
  .page { width: min(100%, 430px); margin: auto; padding: 25px 0 20px; }
  .console-stage { margin-inline: auto; }
  .console { touch-action: none; transform-origin: top left; }
  .board-wrap, #next { contain: layout paint; }
}
@layer console {
  .console { position: relative; padding: 23px 32px 20px; overflow: hidden; border: 1px solid #56a4e3; border-radius: 25px 25px 48px 48px; background: linear-gradient(100deg, #2997ea 0%, #1182df 6%, #1888e5 50%, #0b76d0 94%, #0863b2 100%); box-shadow: inset 0 3px 2px #9acaf480, inset 5px 0 7px #7cc4f540, inset -4px -8px 12px #004b9670, 0 22px 48px #0007, 0 2px 3px #000a; color: var(--case-ink); user-select: none; -webkit-user-select: none; }
  .brand { display: flex; align-items: center; gap: 13px; padding: 0 4px; margin-bottom: 22px; }
  h1 { font: italic 900 29px/1 Arial, sans-serif; letter-spacing: 4px; margin: 0; color: #082f51; text-shadow: 0 1px #75bbeb70; }
  .brand-line { flex: 1; height: 7px; border-block: 2px solid #08395d; opacity: .9; }
  .screen-bezel { position: relative; padding: 10px; background: #112d3c; border: 2px solid #103a55; border-radius: 8px; box-shadow: 0 2px 1px #68b9f2, inset 0 2px 3px #000b, 0 0 0 4px #066ec070; }
  .lcd { display: grid; grid-template-columns: 10fr 4.15fr; gap: 11px; padding: 11px 10px 11px 11px; background: var(--lcd); color: var(--ink); box-shadow: inset 1px 2px 4px #26371c80; border: 1px solid #172d21; }
  .board-wrap { position: relative; align-self: start; border: 1.5px solid #475b36; box-shadow: 0 0 0 1px #b3be9370; aspect-ratio: 1 / 2; overflow: hidden; }
  #board { width: 100%; height: 100%; display: block; }
  .readouts { display: flex; min-width: 0; flex-direction: column; text-align: center; padding-top: 2px; font-family: 'Courier New', monospace; }
  .readout { margin-bottom: 13%; }
  .lcd-label { display: block; font-size: clamp(10px, 3.1vw, 14px); font-weight: 700; letter-spacing: -.6px; line-height: 1.1; }
  .readout output { display: block; margin-top: 4px; font-size: clamp(14px, 4.3vw, 21px); line-height: 1; font-style: italic; font-weight: 600; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
  .high-score output { font-size: clamp(12px, 3.8vw, 18px); }
  .goal-readout { margin: 4% 0 14%; }
  #goal span { font-size: .78em; }
  #goal #goal-value { font-size: inherit; }
  .goal-track { height: 3px; background: #243a241c; margin: 7px 1px 0; }
  .goal-track span { display: block; width: 0; height: 100%; background: #465e39; }
  .next-piece { margin: 0 0 auto; }
  .next-piece .lcd-label { font-size: 9px; letter-spacing: 2px; margin-bottom: 5px; opacity: .75; }
  #next { display: block; width: 100%; aspect-ratio: 1; border: 1px solid #60734a80; }
  .settings-readout { font-size: clamp(10px, 2.9vw, 13px); font-weight: 700; margin-top: 14%; }
  .settings-readout > div { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; }
  .settings-readout output { font-size: 17px; font-weight: 500; font-style: italic; }
  .lcd-bottom { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-size: 8px; font-weight: 700; letter-spacing: .5px; margin-top: 17%; opacity: .65; }
  .battery { display: flex; gap: 1px; border: 1px solid currentColor; padding: 2px; position: relative; height: 10px; width: 19px; flex-shrink: 0; }
  .battery::after { content: ''; position: absolute; width: 2px; height: 4px; right: -3px; top: 2px; background: currentColor; }
  .battery i { background: currentColor; flex: 1; }
  .board-overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
  .board-overlay[hidden] { display: none; }
  .overlay-content { width: 90%; padding: 21px 2px; background: #99a880f0; box-shadow: 0 0 24px 8px #99a880a0; }
  .pixel-mark { width: 47px; height: 32px; fill: var(--ink); margin-bottom: 16px; }
  .overlay-content h2 { font-family: 'Courier New', monospace; font-size: clamp(15px, 5vw, 23px); letter-spacing: -.7px; margin: 0; }
  .overlay-content p { font-size: clamp(10px, 2.9vw, 12px); line-height: 1.65; margin: 0; }
  .start-prompt { display: inline-block; border-block: 1px solid #314b3460; padding: 9px 0; margin-top: 21px; font: 700 9px/1.2 monospace; letter-spacing: .5px; }
  .case-ridge { height: 15px; margin: 18px -15px 0; border-top: 1px solid #8bceff60; border-radius: 50%; box-shadow: 0 -4px 5px #8bceff12, inset 0 6px 6px #075ba72b; }
  .side-pieces { position: absolute; top: 113px; width: 18px; display: grid; gap: 21px; opacity: .68; }
  .side-pieces-left { left: 6px; }
  .side-pieces-right { right: 6px; }
  .side-pieces svg { width: 18px; height: 26px; fill: #083659; stroke: #65b5e9; stroke-width: .45; }
}
@layer controls {
  .control-deck { position: relative; height: 270px; margin: 0 -17px; touch-action: none; }
  .utility-controls { position: absolute; z-index: 2; display: flex; justify-content: space-between; width: 53%; right: 0; top: 2px; }
  .utility { text-align: center; width: 25%; }
  .round-button { border: 2px solid #133b36; border-radius: 50%; padding: 0; display: inline-grid; place-items: center; touch-action: none; position: relative; }
  .round-button::before { content: ''; position: absolute; inset: 7% 13% 40%; border-top: 3px solid #ffffff85; border-radius: 50%; pointer-events: none; }
  .green { width: 29px; height: 29px; background: radial-gradient(circle at 40% 32%, #65fb5c, #2de64c 60%, #14a847); box-shadow: inset 0 -2px 3px #0c8a45, 0 2px 3px #034578a0, 0 0 0 2px #0969b380; }
  .green::after { content: ''; position: absolute; inset: -9px; border-radius: 50%; }
  .green:disabled { background: radial-gradient(circle at 40% 32%, #46d970, #23b765 70%, #199352); box-shadow: inset 0 -2px 3px #128148, 0 2px 3px #034578a0; opacity: .66; }
  .utility > span { display: block; font-size: 8px; line-height: 1.45; font-weight: 800; font-style: italic; margin-top: 7px; }
  .utility:has(button:disabled) > span { opacity: .65; }
  .dpad { position: absolute; left: 0; top: 6px; width: 58%; height: 241px; pointer-events: none; }
  .dpad button { pointer-events: auto; }
  .direction { position: absolute; width: 36%; text-align: center; }
  .direction-up { top: 0; left: 32%; }
  .direction-left { top: 80px; left: -1%; }
  .direction-right { top: 80px; right: -1%; }
  .direction-down { top: 157px; left: 32%; }
  .yellow { width: 100%; aspect-ratio: 1; background: radial-gradient(circle at 42% 34%, #f3fc39 0%, #e6f11b 56%, #cada12 78%, #a5b417 100%); border-color: #283f2c; box-shadow: inset 0 -3px 5px #93a009, inset 0 2px 4px #faff94, 0 3px 5px #003b5fb0, 0 0 0 3px #0968a35c; color: #768820; }
  .yellow > span { font-size: 13px; opacity: .48; text-shadow: 0 1px #f5ff7860; }
  .round-button.is-pressed, .round-button:active:not(:disabled) { transform: translateY(2px); }
  .button-label { display: block; font: italic 800 9px/1.4 Arial, sans-serif; margin-top: 8px; white-space: nowrap; }
  .button-label b { font-weight: inherit; }
  .rotate-control { width: 34%; position: absolute; right: 0; top: 83px; text-align: center; }
  .rotate > span { font-size: 42px; opacity: .44; line-height: 1; }
  .rotate-control .button-label { margin-top: 12px; font-size: 11px; letter-spacing: .6px; }
  .label-secondary { display: block; font-size: 8px; letter-spacing: .5px; margin-top: 1px; }
}
@layer device {
  .fullscreen-button { display: grid; place-items: center; width: 34px; height: 34px; flex-shrink: 0; padding: 5px; border: 1px solid #08395d80; border-radius: 5px; background: transparent; color: var(--case-ink); touch-action: manipulation; }
  .fullscreen-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
  .immersive, .immersive body { width: 100%; height: 100%; overflow: hidden; background: #121d25; }
  .immersive .page { height: 100dvh; display: grid; place-content: center; padding: 0; }
  .immersive .below-console { display: none; }
  .immersive #fullscreen-note:not([hidden]) { position: fixed; inset: auto 10px 8px; background: #121d25; padding: 8px; z-index: 5; }
  .debug-content { font-size: 11px; line-height: 1.6; padding: 4px 0 14px; }
  .debug-content dl { grid-template-columns: 125px 1fr; font-variant-numeric: tabular-nums; }
  .debug-content p { margin: 10px 0; color: #98aab7; }
  .debug-actions { display: flex; gap: 14px; align-items: center; }
  .debug-actions button { padding: 9px 12px; border: 1px solid #526575; border-radius: 4px; background: #223440; color: #e5edf3; }
  .debug-actions a { color: #b7dafa; }
  @media (pointer: coarse) {
    .console { background: #1687e3; box-shadow: inset 0 2px 2px #86c5f4, inset 0 -3px 3px #076ac0; }
    .screen-bezel { box-shadow: 0 2px #68b9f2; }
    .lcd { box-shadow: inset 1px 1px 2px #26371c80; }
    .yellow { background: linear-gradient(#f2fb36, #d4e219); box-shadow: inset 0 -2px 2px #a2b00c, 0 2px 2px #075c99; }
    .green, .green:disabled { box-shadow: 0 2px 2px #075c99; }
    .overlay-content { box-shadow: none; background: var(--lcd); }
  }
}
@layer help {
  .below-console { padding: 0 22px; }
  #context-help { text-align: center; font-size: 11px; letter-spacing: .25px; margin: 23px 0 18px; color: #b0bfca; }
  #context-help b { color: #e2e9ed; font-family: monospace; }
  details { border-block: 1px solid #35424d; }
  summary { padding: 14px 0; font-size: 12px; cursor: pointer; display: flex; justify-content: space-between; list-style: none; color: #d4dfe6; }
  summary::-webkit-details-marker { display: none; }
  summary span { font-size: 18px; line-height: .8; color: #9baab5; }
  details[open] summary span { transform: rotate(45deg); }
  .instructions-content { font-size: 12px; line-height: 1.75; padding-bottom: 6px; }
  .instructions-content p { margin: 0 0 14px; }
  .instructions-content b { color: #e1e7ec; }
  dl { display: grid; grid-template-columns: 80px 1fr; margin: 0 0 14px; row-gap: 6px; }
  dt { font-family: monospace; color: #dae6ed; } dd { margin: 0; }
  .storage-note { font-size: 10px; text-align: center; line-height: 1.6; color: #94a5b1; margin: 18px 0 0; }
}
@layer responsive {
  @media (min-width: 461px) and (max-height: 1000px) { .page { width: 360px; } }
  @media (min-width: 700px) and (min-height: 850px) { .page { padding-top: 34px; } }
  @media (max-width: 460px) {
    body { background: #121d25; }
    .page { padding-top: 0; }
    .console { border-radius: 0 0 33px 33px; border-top: 0; padding-top: 20px; }
  }
  @media (max-width: 380px) {
    .console { padding-inline: 25px; }
    .screen-bezel { padding: 8px; }
    .lcd { padding: 8px; gap: 9px; }
    .control-deck { height: 239px; margin-inline: -13px; }
    .dpad { height: 220px; }
    .direction-left, .direction-right { top: 71px; }
    .direction-down { top: 139px; }
    .rotate-control { top: 77px; }
    .green { width: 27px; height: 27px; }
    .side-pieces-left { left: 2px; } .side-pieces-right { right: 2px; }
  }
  @media (max-width: 330px) {
    .console { padding-inline: 22px; }
    .lcd { gap: 7px; padding: 6px; }
    .readout { margin-bottom: 9%; }
    .lcd-label { font-size: 10px; }
    .readout output { font-size: 15px; }
    .high-score output { font-size: 12px; }
    .settings-readout { font-size: 9px; }
    .settings-readout output { font-size: 14px; }
    .lcd-bottom { font-size: 6px; }
    .brand h1 { font-size: 25px; }
    .control-deck { height: 222px; }
    .direction-left, .direction-right { top: 63px; }
    .direction-down { top: 126px; }
    .rotate-control { top: 74px; }
    .button-label { font-size: 8px; }
    .utility > span { font-size: 7px; }
    .green { width: 25px; height: 25px; }
    .overlay-content h2 { font-size: 15px; }
    .start-prompt { font-size: 7px; }
  }
}

@layer device {
  .readouts[data-home="true"] .settings-readout { margin-top: auto; }
  .network-status { font-size: 11px; text-align: center; margin: -10px 0 10px; line-height: 1.4; font-weight: 700; }
  .mode-menu { display: grid; gap: 8px; margin-top: 12px; }
  .mode-menu button, .friend-lobby button { border: 1px solid #455b36; border-radius: 4px; background: #b7c697; color: #1c2d20; padding: 10px 3px; font-size: 11px; font-weight: 700; touch-action: manipulation; }
  .mode-menu button:first-child { background: #253d2c; color: #dce6bc; }
  .friend-lobby { display: grid; gap: 7px; margin-top: 10px; font-size: 10px; }
  .friend-lobby input { width: 100%; min-width: 0; color: #243825; border: 1px solid #596e47; background: #b6c49d; padding: 6px 3px; font-size: 10px; }
  #copy-status { font-size: 10px; }
  .dealer-controls { margin: 4px -13px 0; }
  .dealer-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 13px; }
  .dealer-heading button { padding: 8px 13px; background: #123f58; color: #f0f4e3; border: 0; border-radius: 5px; }
  .friend-hand { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .piece-card { background: #ecf430; border: 2px solid #375328; border-radius: 7px; color: #1c2d20; min-width: 0; padding: 7px 2px; display: grid; justify-items: center; gap: 6px; touch-action: manipulation; }
  .piece-card svg { width: 32px; height: 40px; fill: currentColor; }
  .piece-card small { font-size: 8px; white-space: nowrap; }
  .piece-card:disabled { opacity: .45; }
  .piece-card.required { border-color: #602823; background: #fff48a; outline: 2px solid #fff5b3; }
  .dealer-controls p { font-size: 11px; line-height: 1.5; margin: 10px 0 0; }
  .friend-error { font-size: 11px; line-height: 1.5; background: #fff1bf; color: #522514; padding: 8px; border-radius: 5px; margin: 8px 0 0; }
  .friend-lobby input:focus { outline: 2px solid #253d2c; }
  @media (max-width: 380px) { .piece-card small { font-size: 7px; } .mode-menu button { font-size: 10px; } }
}
