/* BLOCK DROP - Game Boy (DMG) styled Tetris, tuned for iPhone portrait.
   Palette: the four classic DMG greens, kept clean and crisp. */
:root {
  --dmg-darkest: #0f380f;
  --dmg-dark:    #306230;
  --dmg-light:   #8bac0f;
  --dmg-lightest:#9bbc0f;

  --shell:       #c4bdb0;   /* off-white plastic of the handheld */
  --shell-dark:  #9a9484;
  --shell-edge:  #6f6a5d;
  --screen-bg:   #8bac0f;   /* lit LCD background */
  --btn-face:    #3a3a44;   /* dark grey A/B/dpad plastic */
  --btn-edge:    #1f1f26;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1b1c18;
  color: var(--dmg-darkest);
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#device {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.6rem, 2.5vh, 1.4rem);
  padding: max(0.8rem, env(safe-area-inset-top)) 0.8rem
           max(0.8rem, env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 60% at 50% 0%, #2a2c25 0%, #16170f 70%);
}

/* ---- Screen / LCD ---- */
#screen {
  width: min(94vw, 30rem);
  background: var(--shell);
  border-radius: 0.7rem 0.7rem 1.6rem 0.7rem;
  padding: 0.9rem 0.9rem 1.1rem;
  box-shadow:
    inset 0 0 0 2px var(--shell-dark),
    inset 0 0 0 4px var(--shell-edge),
    0 8px 22px rgba(0,0,0,0.55);
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0.2rem 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--shell-edge);
}
#topbar .brand { font-size: 0.95rem; }

.icon-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--shell);
  background: var(--shell-edge);
  border: none;
  border-radius: 0.4rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
}
.icon-btn:active { transform: translateY(1px); }

/* The lit LCD area that holds the playfield + side panel */
#stage {
  position: relative;
  display: flex;
  gap: 0.6rem;
  padding: 0.7rem;
  background: var(--screen-bg);
  border: 0.18rem solid var(--dmg-darkest);
  border-radius: 0.3rem;
  box-shadow: inset 0 0 0.5rem rgba(15,56,15,0.35);
}

#board {
  display: block;
  height: auto;
  width: 62%;
  max-width: 12rem;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--screen-bg);
}

#side {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  color: var(--dmg-darkest);
}
.panel .label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}
.panel .value {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}
#next {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  max-width: 4rem;
  height: auto;
  margin-top: 0.2rem;
}

/* ---- Overlay (title / pause / game over) ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
  background: rgba(15, 56, 15, 0.82);
  color: var(--dmg-lightest);
  border-radius: 0.3rem;
  padding: 1rem;
}
.overlay.hidden { display: none; }
#overlay-title { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.08em; }
#overlay-text  { font-size: 1rem; font-weight: 700; letter-spacing: 0.06em; }
#overlay-sub   { font-size: 0.72rem; opacity: 0.85; text-wrap: balance; }
.overlay .blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- Controls ---- */
#controls {
  width: min(94vw, 30rem);
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  gap: 0.4rem 0.6rem;
}

/* D-pad */
.dpad {
  position: relative;
  width: clamp(8rem, 38vw, 10rem);
  height: clamp(8rem, 38vw, 10rem);
}
.pad {
  position: absolute;
  border: none;
  background: var(--btn-face);
  box-shadow: 0 3px 0 var(--btn-edge);
  width: 33.33%;
  height: 33.33%;
}
.pad:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--btn-edge); }
.pad-up    { top: 0;    left: 33.33%; border-radius: 0.4rem 0.4rem 0 0; }
.pad-down  { bottom: 0; left: 33.33%; border-radius: 0 0 0.4rem 0.4rem; }
.pad-left  { top: 33.33%; left: 0;  border-radius: 0.4rem 0 0 0.4rem; }
.pad-right { top: 33.33%; right: 0; border-radius: 0 0.4rem 0.4rem 0; }
.pad-mid   { top: 33.33%; left: 33.33%; background: var(--btn-face); box-shadow: none; }
.pad-mid::after {
  content: ""; position: absolute; inset: 28%;
  border-radius: 50%; background: var(--btn-edge); opacity: 0.6;
}
.pad-down::after, .pad-left::after, .pad-right::after, .pad-up::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 0.5rem; height: 0.5rem;
}

/* A / B buttons */
.ab {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  transform: rotate(-18deg);
  justify-self: center;
}
.round {
  width: clamp(3.4rem, 16vw, 4.4rem);
  height: clamp(3.4rem, 16vw, 4.4rem);
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, #b0436b, #7b1d3f);
  color: #ffd9e4;
  font-family: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 4px 0 #5a142e;
}
.round:active { transform: translateY(2px); box-shadow: 0 2px 0 #5a142e; }
.btn-b { margin-top: 1.4rem; }

/* Start / Select */
.startselect {
  grid-column: 1 / -1;
  display: flex;
  gap: 1.6rem;
  justify-content: center;
}
.pill {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: var(--shell);
  background: var(--shell-edge);
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 1rem;
  transform: rotate(-18deg);
  box-shadow: 0 3px 0 #4a463c;
}
.pill:active { transform: rotate(-18deg) translateY(2px); box-shadow: 0 1px 0 #4a463c; }

/* Short, wide phones: keep everything on one screen */
@media (max-height: 700px) {
  #device { gap: 0.5rem; }
  #board { max-width: 9.5rem; }
}
