:root {
  --bg: #c9d63a;
  --ink: #2a1c12;
  --body: #f3b42e;
  --body-dark: #d89a1c;
  --bezel: #1a140f;
  --plastic: #2a1c12;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

*,
*::before,
*::after {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  background: #1c140e;
  color: var(--ink);
  font-family: ui-rounded, "Trebuchet MS", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  caret-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: calc(8px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(8px + env(safe-area-inset-left, 0px));
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.device,
.device *,
canvas,
button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
}

.device {
  position: relative;
  background: linear-gradient(180deg, #ffc44a 0%, var(--body) 55%, var(--body-dark) 100%);
  border-radius: 28px;
  width: min(100%, 448px);
  padding: 16px 16px 22px;
  box-shadow:
    0 0 0 3px #6a4a12,
    0 18px 40px rgba(0, 0, 0, 0.45);
  max-width: 100%;
  flex-shrink: 0;
  touch-action: none;
  overflow: hidden;
}

.bezel {
  background: var(--bezel);
  border-radius: 10px;
  padding: 8px;
  overflow: hidden;
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 400 / 240;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--bg);
  outline: none;
  touch-action: none;
  pointer-events: auto;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  gap: 12px;
}

.dpad {
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 2px;
}

.dpad button,
.face,
.menu-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: var(--plastic);
  color: transparent;
  font-size: 0;
  line-height: 0;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
}

.dpad button {
  border-radius: 6px;
}

.dpad button::before,
.face::before,
.menu-btn::before {
  content: "";
  display: block;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.dpad button::before {
  width: 0;
  height: 0;
  margin: 0;
}

.dpad button[data-dir="u"]::before {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid var(--bg);
}

.dpad button[data-dir="d"]::before {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--bg);
}

.dpad button[data-dir="l"]::before {
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 8px solid var(--bg);
}

.dpad button[data-dir="r"]::before {
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid var(--bg);
}

.dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 3; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 2; grid-row: 3; }

.dpad button.is-down,
.face.is-down,
.menu-btn.is-down {
  transform: translateY(1px);
  filter: brightness(1.25);
}

.menu-btn {
  width: 52px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
}

.menu-btn::before {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  background: linear-gradient(
    to right,
    var(--bg) 0 5px,
    transparent 5px 11px,
    var(--bg) 11px 16px
  );
}

.faces {
  display: flex;
  gap: 10px;
  align-items: center;
}

.face {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.face::before {
  width: 14px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  background: var(--bg);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.face-a::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M8 1.2L14.2 14.8h-2.6l-1.1-2.9H5.5L4.4 14.8H1.8L8 1.2zm-1.8 8.4h3.6L8 5l-1.8 4.6z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M8 1.2L14.2 14.8h-2.6l-1.1-2.9H5.5L4.4 14.8H1.8L8 1.2zm-1.8 8.4h3.6L8 5l-1.8 4.6z'/%3E%3C/svg%3E");
}

.face-b::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M3.6 1.6h5.4c2.3 0 3.8 1.2 3.8 3.1 0 1.2-.7 2.1-1.7 2.6 1.5.5 2.4 1.6 2.4 3.1 0 2.2-1.8 3.7-4.4 3.7H3.6V1.6zm2.3 2.1v3.3h2.9c1.2 0 1.8-.6 1.8-1.6S9.9 3.7 8.8 3.7H5.9zm0 5.3V12h3.3c1.3 0 2-.7 2-1.8s-.7-1.8-2-1.8H5.9z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M3.6 1.6h5.4c2.3 0 3.8 1.2 3.8 3.1 0 1.2-.7 2.1-1.7 2.6 1.5.5 2.4 1.6 2.4 3.1 0 2.2-1.8 3.7-4.4 3.7H3.6V1.6zm2.3 2.1v3.3h2.9c1.2 0 1.8-.6 1.8-1.6S9.9 3.7 8.8 3.7H5.9zm0 5.3V12h3.3c1.3 0 2-.7 2-1.8s-.7-1.8-2-1.8H5.9z'/%3E%3C/svg%3E");
}

@media (max-width: 520px) {
  .device {
    padding: 14px 14px 20px;
    border-radius: 22px;
  }
}

/* iPhone 17 / 17 Pro CSS viewport is 402×874. Chrome sits at the bottom for thumbs. */
@media (max-width: 430px) {
  body {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .device {
    padding: 12px 12px 18px;
    border-radius: 20px;
  }

  .controls {
    margin-top: 16px;
  }
}
