:root {
  --page: #26232f;
  --shell: #d3cfc6;
  --shell-dark: #bdb9af;
  --shell-edge: #a8a49a;
  --bezel: #5b5d6c;
  --ink: #2f3a8f;
  --label: #3b3a52;
  --btn: #a3245c;
  --btn-dark: #6e1239;
  --dpad: #26262c;
  --pill: #8f8c86;
  --lcd: #9bbc0f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Carcasa ---------- */
.console {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100vw, 420px);
  height: 100vh;
  height: min(100dvh, 860px);
  padding: max(10px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(160deg, var(--shell) 0%, var(--shell-dark) 100%);
  border-radius: 14px 14px 64px 14px;
  box-shadow:
    inset 0 -6px 0 var(--shell-edge),
    inset 0 2px 0 rgba(255, 255, 255, .6),
    0 20px 50px rgba(0, 0, 0, .5);
}

@media (max-width: 440px), (max-height: 700px) {
  .console { border-radius: 0 0 56px 0; height: 100vh; height: 100dvh; }
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 22px;
  margin-bottom: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #8a867d;
  border-bottom: 2px solid var(--shell-edge);
}
.topbar .home {
  color: var(--label);
  text-decoration: none;
  padding: 2px 6px 2px 0;
}

/* ---------- Pantalla ---------- */
.bezel {
  background: var(--bezel);
  border-radius: 10px 10px 40px 10px;
  padding: 8px 14px 14px 8px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35);
}

.bezel-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px 8px;
  font-size: 8px;
  letter-spacing: .14em;
  color: #c6c6d4;
}
.bezel-label::before, .bezel-label::after {
  content: "";
  flex: 1;
  height: 2px;
  background: linear-gradient(#8b2e5d 0 50%, #2f3a8f 50% 100%);
}
.bezel-label span { white-space: nowrap; }

.screen-row { display: flex; align-items: center; gap: 6px; }

.led-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 22px;
  flex: none;
}
.led {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #ff3b3b;
  box-shadow: 0 0 6px 2px rgba(255, 60, 60, .7);
}
.led-text { font-size: 6px; letter-spacing: .05em; color: #c6c6d4; }

#screen {
  display: block;
  margin: 0 auto;
  /* Ancho limitado por el contenedor y por la altura disponible (aspecto 272x320). */
  min-width: 0;
  width: min(100% - 28px, calc((100vh - 400px) * 0.85));
  width: min(100% - 28px, calc((100dvh - 400px) * 0.85));
  aspect-ratio: 272 / 320;
  background: var(--lcd);
  border-radius: 2px;
  box-shadow: 0 0 0 2px #3c3e4a;
  image-rendering: pixelated;
}

.brand {
  margin: 10px 4px 0;
  font-style: italic;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -.01em;
  color: var(--ink);
}
.brand b { font-weight: 800; color: var(--btn); margin-left: 2px; }

/* ---------- Controles ---------- */
.controls {
  position: relative;
  flex: 1;
  min-height: 230px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 64px;
  align-items: center;
  touch-action: none;
}

button {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  cursor: pointer;
  touch-action: none;
}
button:focus { outline: none; }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Cruceta */
.dpad {
  --s: clamp(118px, 34vw, 144px);
  --t: calc(var(--s) / 3);
  position: relative;
  width: var(--s);
  height: var(--s);
  margin-left: 6px;
  justify-self: start;
  touch-action: none;
  cursor: pointer;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .25));
}
.dpad .arm, .dpad .hub {
  position: absolute;
  background: var(--dpad);
  transition: background .05s;
}
.dpad .hub { left: var(--t); top: var(--t); width: var(--t); height: var(--t); }
.dpad .hub::after {
  content: "";
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #3a3a42, #1b1b20);
}
.dpad .up    { left: var(--t); top: 0; width: var(--t); height: var(--t); border-radius: 5px 5px 0 0; }
.dpad .down  { left: var(--t); bottom: 0; width: var(--t); height: var(--t); border-radius: 0 0 5px 5px; }
.dpad .left  { left: 0; top: var(--t); width: var(--t); height: var(--t); border-radius: 5px 0 0 5px; }
.dpad .right { right: 0; top: var(--t); width: var(--t); height: var(--t); border-radius: 0 5px 5px 0; }
.dpad .arm::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0; height: 0;
  border: 7px solid transparent;
}
.dpad .up::after    { border-bottom-color: #4a4a54; border-top-width: 0; }
.dpad .down::after  { border-top-color: #4a4a54; border-bottom-width: 0; }
.dpad .left::after  { border-right-color: #4a4a54; border-left-width: 0; }
.dpad .right::after { border-left-color: #4a4a54; border-right-width: 0; }
.dpad .arm.pressed { background: #0d0d10; }
/* «CAÍDA ▲: OFF» en el menú de pausa: la flecha superior se atenúa. */
.dpad.no-drop .up::after { border-bottom-color: #33333b; }

/* Botones A / B */
.ab {
  position: relative;
  justify-self: end;
  width: 150px;
  height: 120px;
  margin-right: 2px;
  transform: rotate(-25deg);
}
.ab::before {
  content: "";
  position: absolute;
  left: 4px; right: 4px; top: 50%;
  height: 74px;
  transform: translateY(-50%);
  border-radius: 40px;
  background: rgba(0, 0, 0, .07);
}
.ab-btn {
  position: absolute;
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateY(-50%);
}
.b-wrap { left: 10px; }
.a-wrap { right: 10px; }
.ab-btn span {
  position: absolute;
  top: 100%;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .1em;
  color: var(--label);
}
.round {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #c43a76, var(--btn) 55%, var(--btn-dark));
  box-shadow: 0 4px 0 var(--btn-dark), 0 6px 10px rgba(0, 0, 0, .3);
  transition: transform .05s, box-shadow .05s;
}
.round.pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-dark), 0 2px 4px rgba(0, 0, 0, .3); }

/* START / SELECT */
.menu-btns {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 26px;
  align-self: start;
  padding-right: 40px;
}
.pill-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transform: rotate(-25deg);
}
.pill-wrap span { font-size: 9px; font-weight: 800; letter-spacing: .12em; color: var(--label); }
.pill {
  width: 52px;
  height: 14px;
  border-radius: 8px;
  background: var(--pill);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .12), 0 2px 0 #6d6a64;
}
.pill.pressed { transform: translateY(2px); box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .2); }

/* Altavoz decorativo */
.speaker {
  position: absolute;
  right: 22px;
  bottom: 8px;
  display: flex;
  gap: 7px;
  transform: rotate(-25deg);
  pointer-events: none;
}
.speaker i {
  display: block;
  width: 6px;
  height: 46px;
  border-radius: 3px;
  background: var(--shell-edge);
  box-shadow: inset 0 2px 2px rgba(0, 0, 0, .3);
}

@media (max-height: 640px) {
  .controls { min-height: 200px; grid-template-rows: 1fr 50px; }
  .round { width: 50px; height: 50px; }
  .speaker i { height: 34px; }
  #screen {
    width: min(100% - 28px, calc((100vh - 350px) * 0.85));
    width: min(100% - 28px, calc((100dvh - 350px) * 0.85));
  }
}
