.lcd-handheld {
  --case-front: #abb6a8;
  --case-light: #d6dcc3;
  --case-edge: #263e43;
  --case-side: #657b79;
  --lcd-ink: #253f40;
  --lcd-cap: #cad2bb;
  --direction-size: 44px;
  box-sizing: border-box;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: clamp(8px, 3.3vw, 34px);
  border: 0;
  background: #1d3031;
  color: var(--lcd-ink);
  overscroll-behavior: contain;
  overflow: auto;
}

.lcd-handheld[open] {
  display: grid;
  align-items: safe center;
  justify-items: center;
}

.lcd-handheld::backdrop { background: #1d3031; }
.lcd-handheld [hidden] { display: none !important; }

.lcd-case {
  position: relative;
  display: grid;
  width: min(100%, 910px);
  grid-template-columns: minmax(144px, .88fr) minmax(0, 3.35fr) minmax(144px, .88fr);
  grid-template-areas: "header header header" "directions display actions" "footer footer footer";
  gap: clamp(8px, 1.4vw, 16px);
  padding: clamp(10px, 2vw, 23px);
  margin: auto;
  background:
    linear-gradient(90deg, var(--case-side) 0 3px, transparent 3px calc(100% - 3px), var(--case-side) 0),
    var(--case-print, linear-gradient(transparent, transparent)),
    var(--case-front);
  border: 4px solid var(--case-edge);
  border-radius: var(--case-radius, 32px 32px 47px 27px);
  box-shadow: inset 0 3px var(--case-light), inset 3px 0 var(--case-light),
    inset 0 -6px var(--case-side), inset -4px 0 var(--case-side),
    0 8px #102527, 0 17px 30px #111f227e;
}

.lcd-header {
  grid-area: header;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.lcd-header > div:first-child { min-width: 0; }

.lcd-venue {
  margin: 0 0 2px;
  color: var(--case-sub, #3a5353);
  font: 750 .68rem/1.13 system-ui, sans-serif;
  letter-spacing: .065em;
  text-transform: uppercase;
}

.lcd-header h2 {
  margin: 0;
  color: var(--lcd-ink);
  font: 700 clamp(1.1rem, 3.4vw, 2.1rem)/1.06 var(--display, system-ui);
  text-wrap: balance;
}

.lcd-header-controls, .lcd-speeds, .lcd-lifecycle {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.lcd-header-controls { flex: none; }

.lcd-handheld button {
  appearance: none;
  position: relative;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  border: 2px solid #283f42;
  background: var(--lcd-cap);
  color: #243c3d;
  box-shadow: inset 0 2px #ffffff6b, inset 0 -3px #788b8177, 0 3px #283f42;
  font: 700 .83rem/1.05 var(--display, system-ui);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.lcd-handheld button:focus-visible {
  z-index: 3;
  outline: 3px solid #f8d173;
  outline-offset: 2px;
}

.lcd-handheld button:enabled:is(:active, [data-held]) {
  translate: 0 2px;
  box-shadow: inset 0 2px #243b3c58, 0 1px #283f42;
  filter: brightness(.88);
}

.lcd-handheld button[aria-pressed="true"]:not([data-lcd-sound]) {
  background: #91b59f;
  box-shadow: inset 0 2px #587b72, 0 1px #283f42;
}

.lcd-handheld button:disabled { filter: saturate(.15) brightness(.87); cursor: default; }

.lcd-handheld .lcd-switch { padding: 5px 9px; border-radius: 6px 6px 8px 8px; }
.lcd-handheld .lcd-start { background: var(--start-face, #ddac62); color: #372c20; }

.lcd-display {
  grid-area: display;
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
}

.lcd-bezel {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  margin-inline: auto;
  padding: 11px 13px 13px;
  border: 3px solid #243a3d;
  border-radius: var(--bezel-radius, 18px 18px 20px 10px);
  background: var(--bezel-face, #425a59);
  box-shadow: inset 0 2px var(--bezel-light, #789185), inset 2px 0 var(--bezel-light, #708780),
    inset -3px -3px var(--bezel-edge, #2e4444), 0 2px #ffffff6b;
}

.lcd-bezel canvas {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: auto;
  outline: 0;
  border: 3px solid #243b38;
  background: #b2bc84;
  image-rendering: pixelated;
}

.lcd-screen-lamp {
  position: absolute;
  width: 5px;
  height: 4px;
  top: 5px;
  right: 17px;
  background: #b6c477;
  box-shadow: 0 0 0 1px #273d3d;
}

.lcd-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lcd-players li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 5px;
  padding: 4px 6px;
  min-width: 0;
  border: 1px solid #63796e;
  background: #c1cbb1;
  color: #2a4443;
  font-size: .75rem;
  line-height: 1.05;
}

.lcd-players li:only-child { grid-column: 1 / -1; }
.lcd-players li[data-active="true"] { background: #dec38a; }
.lcd-players strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lcd-seat, .lcd-player-detail { font: 750 .74rem/1.1 var(--display, system-ui); white-space: nowrap; }

.lcd-grip {
  position: relative;
  min-width: 0;
  min-height: 155px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
}

.lcd-grip-direction { grid-area: directions; }
.lcd-grip-action { grid-area: actions; }

.lcd-dpad, .lcd-actions {
  display: grid;
  justify-content: center;
  align-content: center;
  gap: 4px;
  min-width: 0;
}

.lcd-dpad[data-count="0"], .lcd-actions[data-count="0"] { display: none; }

.lcd-dpad[data-layout="pad"][data-count="2"]:has([data-lcd-control="left"], [data-lcd-control="right"]) {
  grid-template-columns: repeat(2, var(--direction-size));
}

.lcd-dpad[data-layout="pad"]:has([data-lcd-control="up"], [data-lcd-control="down"]):not([data-count="1"]) {
  grid-template: repeat(3, var(--direction-size)) / repeat(3, var(--direction-size));
  gap: 0;
  background: var(--pad-base, #435d5d);
  border: 2px solid #263e43;
  box-shadow: inset 0 2px #759087, 0 3px #7b8d81;
}

.lcd-dpad[data-layout="pad"]:has([data-lcd-control="up"], [data-lcd-control="down"]):not([data-count="1"])::after {
  content: "";
  grid-area: 2 / 2;
  margin: 10px;
  background: #7d9a85;
  clip-path: polygon(33% 0, 67% 0, 67% 33%, 100% 33%, 100% 67%, 67% 67%, 67% 100%, 33% 100%, 33% 67%, 0 67%, 0 33%, 33% 33%);
}

.lcd-dpad[data-layout="pad"]:has([data-lcd-control="up"], [data-lcd-control="down"]):not([data-count="1"]) [data-lcd-control="up"] { grid-area: 1 / 2; }
.lcd-dpad[data-layout="pad"]:has([data-lcd-control="up"], [data-lcd-control="down"]):not([data-count="1"]) [data-lcd-control="left"] { grid-area: 2 / 1; }
.lcd-dpad[data-layout="pad"]:has([data-lcd-control="up"], [data-lcd-control="down"]):not([data-count="1"]) [data-lcd-control="right"] { grid-area: 2 / 3; }
.lcd-dpad[data-layout="pad"]:has([data-lcd-control="up"], [data-lcd-control="down"]):not([data-count="1"]) [data-lcd-control="down"] { grid-area: 3 / 2; }

.lcd-handheld .lcd-direction-cap {
  padding: 2px;
  border-radius: 4px;
  background: var(--pad-face, #395858);
  color: #e9edd6;
  font: 750 1.25rem/1 system-ui, sans-serif;
  box-shadow: inset 0 2px var(--pad-light, #7f9b91), inset -2px -3px #203a40, 0 2px #213c42;
  touch-action: none;
}

.lcd-actions, .lcd-dpad[data-layout="caps"] { grid-template-columns: repeat(2, minmax(0, 64px)); }

.lcd-handheld .lcd-action-cap {
  min-height: 50px;
  padding: 5px 3px;
  border-radius: var(--action-radius, 9px 9px 12px 12px);
  background: var(--action-face, #d09760);
  color: var(--action-ink, #302b20);
  box-shadow: inset 0 2px var(--action-light, #f5ca8c), inset -2px -4px var(--action-edge, #965b40), 0 3px #3e3e31;
  font-size: .78rem;
  overflow-wrap: anywhere;
  touch-action: none;
}

.lcd-handheld .lcd-action-cap:only-child { grid-column: 1 / -1; min-width: 76px; }
.lcd-handheld .lcd-action-cap:nth-child(2n) { background: var(--second-face, #bb8154); }
.lcd-action-cap kbd { display: block; margin-top: 3px; font: 650 .6rem/1.12 system-ui, sans-serif; }

.lcd-grip-ridges, .lcd-speaker {
  width: 59px;
  height: 17px;
  pointer-events: none;
}

.lcd-grip-ridges { background: repeating-linear-gradient(0deg, transparent 0 3px, var(--grip-line, #829589) 3px 5px); }
.lcd-speaker {
  transform: skewX(-14deg);
  background: repeating-linear-gradient(90deg, transparent 0 5px, var(--speaker-line, #455f5d) 5px 8px);
  opacity: .82;
}

.lcd-footer {
  grid-area: footer;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 7px;
  min-height: 22px;
}

.lcd-status {
  margin: 0;
  max-width: 100%;
  text-align: center;
  color: var(--lcd-ink);
  font-size: .84rem;
  font-weight: 700;
}

.lcd-status[data-error] { color: var(--case-error, #722d26); }
.lcd-lifecycle { flex-wrap: wrap; }
.lcd-speeds { padding-right: 7px; border-right: 1px solid #6c837a; }
.lcd-screen-reader { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 590px) and (orientation: portrait) {
  .lcd-handheld { padding: 0; --direction-size: clamp(44px, 12.9vw, 56px); }

  .lcd-case {
    min-height: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "header header" "display display" "directions actions" "footer footer";
    grid-template-rows: auto auto minmax(142px, 1fr) auto;
    gap: 12px 8px;
    align-content: center;
    padding: max(17px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(21px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    border-radius: 0;
    box-shadow: inset 0 3px var(--case-light), inset 0 -5px var(--case-side);
  }

  .lcd-header-controls { gap: 4px; }
  .lcd-handheld .lcd-switch { padding-inline: 7px; }
  .lcd-grip {
    position: relative;
    isolation: isolate;
    align-content: center;
    gap: clamp(12px, 3vh, 28px);
    border: 2px solid var(--case-side);
    border-radius: var(--grip-radius, 16px 16px 29px 16px);
    background:
      radial-gradient(ellipse at center, #ffffff29 0%, transparent 67%),
      var(--grip-face, #a6b29f);
    box-shadow: inset 0 2px var(--case-light), inset 0 -3px var(--case-side);
  }
  .lcd-grip::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 8px;
    border-radius: inherit;
    border: 1px solid #ffffff2f;
    box-shadow: 0 0 0 1px #15182726, inset 0 0 8px #16222418;
    pointer-events: none;
  }
  .lcd-grip .lcd-direction-cap { min-width: var(--direction-size); min-height: var(--direction-size); }
  .lcd-grip .lcd-dpad[data-count="2"] .lcd-direction-cap { min-height: 58px; }
  .lcd-grip .lcd-action-cap { min-height: 62px; }
  .lcd-grip .lcd-action-cap:only-child { min-width: 94px; }
  .lcd-grip-ridges, .lcd-speaker { width: 70px; height: 22px; }
}

@media (orientation: landscape) and (max-height: 510px) {
  .lcd-handheld { padding: 0; }

  .lcd-case {
    min-height: 100%;
    width: 100%;
    grid-template-columns: minmax(142px, .8fr) minmax(0, 3fr) minmax(142px, .8fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 5px 8px;
    align-items: center;
    padding: max(7px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(9px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-radius: 0;
    box-shadow: inset 0 3px var(--case-light), inset 0 -5px var(--case-side);
  }

  .lcd-header h2 { font-size: clamp(1.1rem, 3.5vw, 1.75rem); }
  .lcd-header .lcd-switch { padding: 3px 8px; }
  .lcd-case { --lcd-landscape-reserve: 204px; }
  [data-lcd-phase="play"] .lcd-case { --lcd-landscape-reserve: 164px; }
  .lcd-bezel {
    width: min(100%, calc(max(102px, 100dvh - var(--lcd-landscape-reserve)) * 1.7867 + 26px));
    padding: 7px 9px 8px;
  }
  .lcd-players { grid-template-columns: repeat(auto-fit, minmax(94px, 1fr)); }
  .lcd-screen-lamp { top: 3px; width: 4px; height: 2px; }
  .lcd-grip { align-content: center; gap: 8px; }
  .lcd-footer { gap: 4px; }
  .lcd-status { font-size: .75rem; }
}

@media (orientation: landscape) and (max-width: 700px) and (max-height: 510px) {
  .lcd-case { --lcd-landscape-reserve: 227px; }
  [data-lcd-phase="play"] .lcd-case { --lcd-landscape-reserve: 187px; }
}

@media (pointer: coarse) {
  .lcd-action-cap kbd { display: none; }
}

.lcd-handheld[data-lcd-game="cricket"] {
  --case-front: #cbb275;
  --case-light: #e9d295;
  --case-edge: #4d3928;
  --case-side: #8d734d;
  --case-radius: 18px 18px 45px 45px;
  --case-print: linear-gradient(0deg, #8e624b22 0 13px, transparent 13px 18px, #8e624b44 18px 21px, transparent 21px);
  --lcd-ink: #362a1e;
  --case-sub: #52412e;
  --lcd-cap: #e5cc94;
  --bezel-face: #514838;
  --bezel-light: #9f8e69;
  --bezel-edge: #3c362b;
  --bezel-radius: 10px 10px 33px 33px;
  --pad-face: #52462f;
  --pad-light: #a69566;
  --action-face: #ed9c51;
  --action-light: #ffc180;
  --action-edge: #a65a32;
  --action-radius: 23px;
  --grip-face: #b99a60;
  --grip-line: #a58250;
  --speaker-line: #6f5038;
}

.lcd-handheld[data-lcd-game="soccer"] {
  --case-front: #95bfa9;
  --case-light: #d6e7ce;
  --case-edge: #294c41;
  --case-side: #5d8b70;
  --case-radius: 42px 42px 26px 26px;
  --case-print: linear-gradient(145deg, #dcebd431 0 12%, transparent 12% 14%, #dcebd470 14% 16%, transparent 16% 84%, #dcebd470 84% 86%, transparent 86% 88%, #dcebd431 88%);
  --lcd-cap: #d6e5c9;
  --bezel-face: #38594e;
  --bezel-light: #7c9c83;
  --bezel-radius: 24px 24px 8px 8px;
  --pad-face: #365c51;
  --pad-light: #83aa8f;
  --action-face: #e1ce79;
  --action-light: #f7e7aa;
  --action-edge: #9a7c3a;
  --action-radius: 5px 18px 18px 5px;
  --grip-face: #8db295;
  --grip-radius: 25px 25px 11px 11px;
  --grip-line: #679077;
}

.lcd-handheld[data-lcd-game="pool"] {
  --case-front: #aa7977;
  --case-light: #d19c91;
  --case-edge: #492e34;
  --case-side: #805457;
  --case-radius: 13px 13px 25px 25px;
  --case-print: linear-gradient(0deg, #452e3b 0 3px, #dcb178 3px 6px, #452e3b 6px 9px, transparent 9px);
  --lcd-ink: #30202a;
  --case-sub: #36262d;
  --lcd-cap: #dfc2a1;
  --bezel-face: #4e3a43;
  --bezel-light: #a57977;
  --bezel-edge: #332631;
  --bezel-radius: 6px;
  --pad-base: #59484a;
  --pad-face: #493b42;
  --pad-light: #be8d88;
  --action-face: #c9d59a;
  --action-light: #e5e8b4;
  --action-edge: #697b5d;
  --action-radius: 5px;
  --grip-face: #9f6c6b;
  --grip-radius: 8px;
  --grip-line: #7e535a;
  --speaker-line: #533740;
}

.lcd-handheld[data-lcd-game="fishing"] {
  --case-front: #91b5c4;
  --case-light: #d4e7e2;
  --case-edge: #294650;
  --case-side: #577e8d;
  --case-radius: 13px 41px 48px 28px;
  --case-print: linear-gradient(0deg, #3a697b82 0 9px, #deeee687 9px 11px, #5e91a585 11px 16px, transparent 16px);
  --case-sub: #324d58;
  --lcd-cap: #cce0d8;
  --bezel-face: #3e5f68;
  --bezel-light: #84aab1;
  --bezel-edge: #2e4952;
  --bezel-radius: 6px 28px 28px 16px;
  --pad-base: #426571;
  --pad-face: #365966;
  --pad-light: #84a6ae;
  --action-face: #d0e2d3;
  --action-light: #edf7e7;
  --action-edge: #6e9c96;
  --action-radius: 12px 28px 28px 12px;
  --grip-face: #82a6b5;
  --grip-line: #6b8f9e;
}

.lcd-handheld[data-lcd-game="drinks"] {
  --case-front: #c58766;
  --case-light: #e8ac83;
  --case-edge: #53392c;
  --case-side: #935c48;
  --case-radius: 24px 24px 12px 12px;
  --case-print: linear-gradient(0deg, #71493c 0 3px, #dfa862 3px 6px, #71493c 6px 9px, transparent 9px);
  --lcd-ink: #34261f;
  --case-sub: #452e26;
  --lcd-cap: #e4c6a3;
  --bezel-face: #5d453a;
  --bezel-light: #a78066;
  --bezel-edge: #41322d;
  --bezel-radius: 17px 17px 6px 6px;
  --pad-face: #6b4c3e;
  --pad-light: #a98065;
  --action-face: #ead09a;
  --action-light: #ffe2a9;
  --action-edge: #a78053;
  --action-radius: 20px 20px 7px 7px;
  --grip-face: #ba7958;
  --grip-radius: 18px 18px 8px 8px;
  --grip-line: #9c634d;
  --speaker-line: #64463a;
}

.lcd-handheld[data-lcd-game="oak"] {
  --case-front: #543c60;
  --case-light: #a177a1;
  --case-edge: #261e37;
  --case-side: #382841;
  --case-radius: 31px 31px 40px 40px;
  --case-print: linear-gradient(0deg, #251e30 0 4px, #c39462 4px 6px, #412e51 6px 9px, transparent 9px);
  --lcd-ink: #fff0c6;
  --case-sub: #f1d599;
  --case-error: #ffd0bb;
  --lcd-cap: #d1b4cb;
  --start-face: #eda969;
  --bezel-face: #352b45;
  --bezel-light: #93788f;
  --bezel-edge: #2c2339;
  --bezel-radius: 24px 24px 9px 9px;
  --action-face: #eaae68;
  --second-face: #e5c184;
  --action-light: #f7d5a3;
  --action-edge: #94675c;
  --action-radius: 21px 21px 11px 11px;
  --grip-face: #644970;
  --grip-radius: 22px 22px 10px 10px;
  --grip-line: #9c7397;
  --speaker-line: #c291aa;
}

[data-lcd-game="oak"] .lcd-action-cap[data-lcd-control="up"] {
  --action-face: #dfa1a0;
  --action-light: #f6bfba;
  --action-edge: #8d5a63;
}

[data-lcd-game="cricket"] .lcd-speaker {
  transform: none;
  background: radial-gradient(circle, var(--speaker-line) 1.5px, transparent 2px) 0 0 / 7px 7px;
}

[data-lcd-game="fishing"] .lcd-speaker {
  transform: none;
  background: repeating-linear-gradient(0deg, transparent 0 3px, #3a5e6a 3px 5px);
  clip-path: polygon(11% 0, 89% 0, 100% 25%, 100% 75%, 89% 100%, 11% 100%, 0 75%, 0 25%);
}
