/* ============================================================
   TETRIS — Handheld LCD 1990
   Palet & tekstur dibuat untuk meniru plastik abu-abu-beige
   dan layar LCD monokrom hijau khas handheld era 90-an.
   ============================================================ */

:root {
  /* Palet LCD (mirip Game Boy DMG) */
  --lcd-bg:      #9bbc0f;
  --lcd-bg-2:    #8bac0f;
  --lcd-ink:     #0f380f;
  --lcd-ink-2:   #306230;

  /* Plastik bodi */
  --body-hi:     #e0dbcd;
  --body-mid:    #c9c3b2;
  --body-lo:     #a49e8e;
  --body-edge:   #6f6a5d;

  /* Aksen */
  --red:         #b6362b;
  --red-dk:      #7d1f17;
  --grey-btn:    #3b3a35;
  --grey-btn-hi: #55534b;

  --font-pixel: "Press Start 2P", "Courier New", ui-monospace, monospace;
}

/* Font pixel di-vendor lokal (SIL OFL 1.1) supaya game jalan tanpa internet */
@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("assets/fonts/press-start-2p.woff2") format("woff2");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 16px 20px;
  background:
    radial-gradient(120% 90% at 50% 0%, #23262b 0%, #14161a 55%, #0b0c0e 100%);
  font-family: var(--font-pixel);
  color: #cfc9b8;
  -webkit-font-smoothing: none;
}

/* Debu/vinet halus di meja */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 2px, transparent 2px 4px);
}

.desk {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 420px;
}

/* ============================================================
   BODI DEVICE
   ============================================================ */
.device {
  position: relative;
  width: 100%;
  padding: 18px 18px 14px;
  border-radius: 16px 16px 46px 16px;
  background:
    linear-gradient(158deg, var(--body-hi) 0%, var(--body-mid) 42%, var(--body-lo) 78%, #948e7f 100%);
  box-shadow:
    /* cahaya atas */
    inset 0 2px 0 rgba(255,255,255,.65),
    inset 2px 0 0 rgba(255,255,255,.35),
    /* bayangan bawah kanan */
    inset -3px -4px 0 rgba(0,0,0,.14),
    inset 0 -1px 0 rgba(0,0,0,.18),
    /* duduk di meja */
    0 2px 0 var(--body-edge),
    0 22px 40px -12px rgba(0,0,0,.85),
    0 4px 10px rgba(0,0,0,.5);
  /* tekstur plastik */
  background-blend-mode: normal;
}

/* butiran plastik */
.device::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: .5;
  background-image:
    radial-gradient(rgba(255,255,255,.35) .5px, transparent .6px),
    radial-gradient(rgba(0,0,0,.10) .5px, transparent .6px);
  background-size: 3px 3px, 4px 4px;
  background-position: 0 0, 1px 2px;
  mix-blend-mode: overlay;
}

/* sekrup sudut */
.device::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 12px 12px 40px 12px;
  pointer-events: none;
  background:
    radial-gradient(circle at 4px 4px,      #8b8578 0 2px, #6d685c 2px 2.5px, transparent 2.6px),
    radial-gradient(circle at calc(100% - 4px) 4px, #8b8578 0 2px, #6d685c 2px 2.5px, transparent 2.6px),
    radial-gradient(circle at 4px calc(100% - 4px), #8b8578 0 2px, #6d685c 2px 2.5px, transparent 2.6px),
    radial-gradient(circle at calc(100% - 4px) calc(100% - 4px), #8b8578 0 2px, #6d685c 2px 2.5px, transparent 2.6px);
  background-repeat: no-repeat;
}

/* ── Label merek ─────────────────────────────────────────── */
.brand {
  text-align: center;
  margin: 2px 0 10px;
}

.brand__stripes {
  display: flex;
  gap: 3px;
  justify-content: center;
  margin-bottom: 6px;
}
.brand__stripes span {
  display: block;
  height: 3px;
  width: 26px;
  border-radius: 2px;
  box-shadow: 0 1px 0 rgba(255,255,255,.35);
}
.brand__stripes span:nth-child(1) { background: #2f5fa8; }
.brand__stripes span:nth-child(2) { background: #b6362b; }
.brand__stripes span:nth-child(3) { background: #d9b53c; }

.brand__title {
  margin: 0;
  font-size: 21px;
  line-height: 1;
  letter-spacing: 1px;
  color: #2b2a26;
  text-shadow:
    0 1px 0 rgba(255,255,255,.85),
    0 -1px 0 rgba(0,0,0,.22),
    2px 2px 0 rgba(0,0,0,.08);
  font-weight: normal;
}

.brand__sub {
  margin: 7px 0 0;
  font-size: 7px;
  letter-spacing: 1.1px;
  color: #5c574c;
  text-shadow: 0 1px 0 rgba(255,255,255,.55);
}

/* ── Bezel ───────────────────────────────────────────────── */
.bezel {
  padding: 11px 11px 20px;
  border-radius: 10px 10px 30px 10px;
  background: linear-gradient(165deg, #4a4841 0%, #33322d 40%, #24231f 100%);
  box-shadow:
    inset 0 3px 6px rgba(0,0,0,.75),
    inset 0 -1px 0 rgba(255,255,255,.10),
    0 1px 0 rgba(255,255,255,.55),
    0 2px 4px rgba(0,0,0,.25);
}

.bezel__text {
  display: block;
  font-size: 5px;
  letter-spacing: 1.2px;
  color: #8d8a80;
}

/* ── Layar LCD ───────────────────────────────────────────── */
.screen {
  position: relative;
  padding: 9px;
  border-radius: 4px;
  background: var(--lcd-bg);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,.45),
    inset 0 0 14px rgba(15,56,15,.45),
    0 0 0 1px rgba(255,255,255,.06);
  overflow: hidden;
  /* refleksi kaca */
  isolation: isolate;
}

.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background:
    /* vignette LCD: tepi layar sedikit lebih gelap */
    radial-gradient(115% 92% at 50% 45%, transparent 55%, rgba(15,56,15,.17) 100%),
    linear-gradient(118deg, rgba(255,255,255,.28) 0%, rgba(255,255,255,.09) 18%, transparent 42%),
    radial-gradient(80% 50% at 20% 0%, rgba(255,255,255,.15), transparent 70%);
}

/* scanline LCD */
.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background: repeating-linear-gradient(
    to bottom,
    rgba(15,56,15,.13) 0 1px,
    transparent 1px 3px
  );
  opacity: .55;
}

.lcd {
  display: flex;
  gap: 8px;
  align-items: stretch;
  color: var(--lcd-ink);
}

.lcd__board {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 244px;
  margin-inline: auto;
  padding: 3px;
  border-radius: 2px;
  background: var(--lcd-bg-2);
  box-shadow: inset 0 0 0 1px rgba(15,56,15,.30);
}

/* panel skor bisa dimatikan per game */
.lcd__panel[hidden],
[data-slot][hidden] {
  display: none !important;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── Panel skor ──────────────────────────────────────────── */
.lcd__panel {
  flex: 0 0 84px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0 0;
  font-size: 7px;
  letter-spacing: .5px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-bottom: 1px dotted rgba(15,56,15,.35);
  padding-bottom: 4px;
}

.stat__label {
  font-size: 6px;
  letter-spacing: 1px;
  opacity: .85;
}

.stat__value {
  font-size: 10px;
  line-height: 1.15;
  letter-spacing: .5px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.next { margin-top: auto; }

.next__box {
  margin-top: 3px;
  padding: 2px;
  border: 1px solid rgba(15,56,15,.45);
  border-radius: 2px;
  background: var(--lcd-bg-2);
  box-shadow: inset 0 0 0 1px rgba(155,188,15,.6);
}

#next {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.leds {
  display: flex;
  gap: 6px;
  padding-top: 2px;
}

.led {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(15,56,15,.18);
  box-shadow: inset 0 0 2px rgba(15,56,15,.5);
}

.led--on {
  background: var(--lcd-ink);
  box-shadow: 0 0 4px rgba(15,56,15,.7);
}

/* ── Overlay pesan ───────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
  color: var(--lcd-ink);
  background: rgba(155,188,15,.90);
  transition: opacity .12s linear;
}

.overlay[data-state="playing"] {
  opacity: 0;
  pointer-events: none;
}

.overlay__title {
  margin: 0;
  font-size: 15px;
  letter-spacing: 1px;
  line-height: 1.35;
}

.overlay__msg {
  margin: 0;
  font-size: 8px;
  line-height: 1.7;
  letter-spacing: .5px;
  animation: blink 1.05s steps(1, end) infinite;
}

.overlay__hint {
  margin: 4px 0 0;
  font-size: 5px;
  line-height: 1.9;
  letter-spacing: .5px;
  opacity: .8;
  max-width: 22ch;
}

.overlay[data-state="over"] .overlay__msg,
.overlay[data-state="paused"] .overlay__msg { animation: none; }

@keyframes blink {
  0%, 55%  { opacity: 1; }
  56%, 99% { opacity: .15; }
}

/* ============================================================
   KONTROL
   ============================================================ */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 6px 6px;
}

/* ── D-Pad ───────────────────────────────────────────────── */
.dpad {
  position: relative;
  flex: 0 0 auto;
  width: 104px;
  height: 104px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.45));
}

/* alas tenggelam di bodi, memberi kesan tombol menonjol */
.dpad::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(0,0,0,.12), rgba(0,0,0,.04) 60%, transparent 72%);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.18), 0 1px 0 rgba(255,255,255,.30);
  pointer-events: none;
}

.dpad__btn {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: #c3bdac;
  font-size: 8px;
  background: linear-gradient(158deg, #5d5a52 0%, #45443d 40%, #2c2b27 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(255,255,255,.34),
    inset 1px 0 0 rgba(255,255,255,.10),
    inset 0 -3px 4px rgba(0,0,0,.6),
    0 2px 0 #1f1e1a,
    0 4px 6px rgba(0,0,0,.35);
  transition: transform .04s linear, filter .04s linear, box-shadow .04s linear;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dpad__btn:active {
  filter: brightness(.8);
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.16),
    inset 0 -1px 3px rgba(0,0,0,.6),
    0 0 0 #1f1e1a;
}

.dpad__btn--up {
  grid-area: 1 / 2 / 2 / 3;
  border-radius: 4px 4px 0 0;
  padding-bottom: 4px;
}
.dpad__btn--left {
  grid-area: 2 / 1 / 3 / 2;
  border-radius: 4px 0 0 4px;
  padding-right: 4px;
}
.dpad__btn--right {
  grid-area: 2 / 3 / 3 / 4;
  border-radius: 0 4px 4px 0;
  padding-left: 4px;
}
.dpad__btn--down {
  grid-area: 3 / 2 / 4 / 3;
  border-radius: 0 0 4px 4px;
  padding-top: 4px;
}

.dpad__hub {
  grid-area: 2 / 2 / 3 / 3;
  background: radial-gradient(circle at 50% 35%, #4d4b45, #2b2a26 75%);
  box-shadow: inset 0 1px 2px rgba(255,255,255,.12), inset 0 -1px 2px rgba(0,0,0,.6);
  position: relative;
}
.dpad__hub::after {
  content: "";
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 30%, rgba(255,255,255,.16), rgba(0,0,0,.35));
}

/* ── Tombol A / B ────────────────────────────────────────── */
.ab {
  display: flex;
  align-items: center;
  gap: 10px;
  transform: rotate(-18deg);
  margin: 0 10px 0 0;
}

.ab__col { display: flex; flex-direction: column; align-items: center; }

.ab__btn {
  -webkit-appearance: none;
  appearance: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 9px;
  color: rgba(255,255,255,.82);
  text-shadow: 0 1px 1px rgba(0,0,0,.55);
  background: radial-gradient(circle at 36% 28%, #d4544a 0%, var(--red) 42%, var(--red-dk) 100%);
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,.35),
    inset 0 -4px 6px rgba(0,0,0,.45),
    0 3px 0 #5d1710,
    0 5px 8px rgba(0,0,0,.45);
  transition: transform .04s linear, box-shadow .04s linear;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ab__btn:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,.25),
    inset 0 -3px 5px rgba(0,0,0,.5),
    0 1px 0 #5d1710,
    0 2px 4px rgba(0,0,0,.4);
}

/* ── Baris tombol pill ───────────────────────────────────── */
.pillrow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 20px;
}

.pill {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  cursor: pointer;
  width: 100%;
  padding: 8px 2px 7px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 6px;
  letter-spacing: .4px;
  color: #efeadc;
  background: linear-gradient(180deg, #6b675d 0%, #4a4740 55%, #35332d 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.30),
    inset 0 -2px 3px rgba(0,0,0,.5),
    0 2px 0 #26241f,
    0 3px 5px rgba(0,0,0,.4);
  transition: transform .04s linear, filter .04s linear;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pill:active { transform: translateY(2px); filter: brightness(.85); }

.pill--start {
  background: linear-gradient(180deg, #c2453a 0%, var(--red) 45%, var(--red-dk) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.35),
    inset 0 -2px 3px rgba(0,0,0,.45),
    0 2px 0 #5d1710,
    0 3px 5px rgba(0,0,0,.4);
}

.pill--reset { color: #ded8c8; }

/* ── Speaker & footer ────────────────────────────────────── */
.cosmetic {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 8px 0;
}

.speaker {
  display: flex;
  gap: 4px;
  transform: skewX(-14deg);
}

.speaker span {
  display: block;
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: linear-gradient(180deg, #8e887a, #6b6659);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.5), 0 1px 0 rgba(255,255,255,.45);
}

.cosmetic__note {
  margin: 0 0 2px;
  font-size: 6px;
  letter-spacing: .9px;
  color: #655f53;
  text-shadow: 0 1px 0 rgba(255,255,255,.45);
}

.footer {
  margin: 10px 0 0;
  text-align: center;
  font-size: 6px;
  letter-spacing: .7px;
  line-height: 1.6;
  color: #6a6559;
  text-shadow: 0 1px 0 rgba(255,255,255,.45);
}

/* ── Hint keyboard di luar device ────────────────────────── */
.pagehint {
  margin: 0;
  font-size: 6px;
  line-height: 2.2;
  letter-spacing: .5px;
  color: #6e6a60;
  text-align: center;
}

kbd {
  font-family: inherit;
  font-size: 6px;
  padding: 3px 4px;
  border-radius: 3px;
  color: #b7b2a4;
  background: #22242a;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 1px 0 #000;
}

/* ── Layar kecil: rapatkan sedikit ───────────────────────── */
@media (max-width: 400px) {
  body { padding: 14px 10px 20px; }
  .device { padding: 12px 12px 10px; border-radius: 14px 14px 38px 14px; }
  .brand__title { font-size: 21px; }
  .dpad { width: 96px; height: 96px; }
  .ab__btn { width: 38px; height: 38px; font-size: 8px; }
  .lcd__panel { flex-basis: 74px; font-size: 6px; }
  .stat__value { font-size: 9px; }
  /* tap target lebih nyaman di layar sentuh */
  .pillrow { gap: 6px; }
  .pill { padding: 11px 2px 10px; }
  .overlay__hint { opacity: 1; }
}

@media (max-height: 980px) {
  /* sembunyikan baris hint keyboard supaya device tidak memaksa scroll */
  .pagehint { display: none; }
}

@media (max-height: 800px) and (min-width: 401px) {
  .desk { max-width: 380px; }
  .brand__title { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay__msg { animation: none; }
}
