/* =========================================================
   Pokédex — 90s handheld style, built for iPad / touch
   The device is laid out on a fixed 1240×880 stage (landscape)
   or a 650×880 stage (portrait, one half at a time) and scaled
   to fit the screen, so proportions stay exact on any device.
   ========================================================= */

:root {
  --red: #dc0a2d;
  --red-deep: #6e0014;
  --label: #7c0016;
  --scr-text: #9dffb0;
  --scr-dim: #58b46c;
  --scr-line: rgba(157, 255, 176, .18);
  --lcd-ink: #263427;
  --px: 'Press Start 2P', ui-monospace, Menlo, monospace;
  --lcd: 'VT323', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  overscroll-behavior: none;
  background: #141416;
}
body {
  font-family: -apple-system, system-ui, "Helvetica Neue", Arial, sans-serif;
  color: #fff;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  background: radial-gradient(ellipse at 50% 40%, #2c2c33 0%, #131316 72%) fixed;
}
button {
  font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0;
  cursor: pointer; touch-action: manipulation; -webkit-appearance: none; appearance: none;
}
button:focus { outline: none; }
button:focus-visible { outline: 3px solid #ffe066; outline-offset: 2px; }

#viewport {
  position: fixed;
  top: env(safe-area-inset-top); right: env(safe-area-inset-right);
  bottom: env(safe-area-inset-bottom); left: env(safe-area-inset-left);
}
#stage {
  position: absolute; left: 50%; top: 50%;
  width: 1240px; height: 880px;
  transform: translate(-50%, -50%) scale(var(--s, 1));
}
body.portrait #stage { width: 650px; }

#device {
  position: absolute; left: 20px; top: 20px;
  width: 1200px; height: 840px;
  perspective: 2400px;
  transition: transform .18s ease-in;
}
body.portrait #device { left: 5px; width: 640px; }
#device.flip-out { transform: perspective(1800px) rotateY(88deg); }
#device.flip-in { transform: perspective(1800px) rotateY(-88deg); transition: none; }

/* ---------- halves ---------- */
.half { position: absolute; top: 0; width: 590px; height: 840px; }
.half.left { left: 0; }
.half.right {
  left: 610px;
  transform-origin: -10px 50%;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
body.portrait .half.right { left: 0; }
body.portrait #device[data-panel="left"] .half.right,
body.portrait #device[data-panel="right"] .half.left { display: none; }

.half > * { position: absolute; }
.shape {
  inset: 0; width: 590px; height: 840px; overflow: visible;
  filter: drop-shadow(0 22px 30px rgba(0, 0, 0, .6));
}
.shape .fill { fill: url(#redGrad); stroke: var(--red-deep); stroke-width: 3; }
.shape .trim-dark { fill: none; stroke: #82001a; stroke-width: 4; }
.shape .trim-light { fill: none; stroke: rgba(255, 255, 255, .28); stroke-width: 2; }
.shape .bezel { fill: url(#bezelGrad); stroke: #6b6b6b; stroke-width: 2; }
.shape .bezel-dot { fill: #e3132f; stroke: #6a0010; stroke-width: 1.5; }
.shape .grille rect { fill: #333; }

.hinge {
  position: absolute; left: 588px; top: 118px; width: 24px; height: 716px;
  border-radius: 8px;
  background: linear-gradient(90deg, #6b0012, #c40a28 35%, #ef3352 50%, #c40a28 65%, #6b0012);
  box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column; justify-content: space-between; padding: 40px 0;
}
.hinge i { display: block; height: 3px; background: rgba(0, 0, 0, .35); box-shadow: 0 1px 0 rgba(255, 255, 255, .2); }
body.portrait .hinge { display: none; }

.label {
  font: 800 13px/1 -apple-system, system-ui, sans-serif;
  letter-spacing: .12em; color: var(--label);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .25);
  text-align: center; pointer-events: none;
}

/* ---------- lens + LEDs ---------- */
.lens {
  left: 30px; top: 22px; width: 118px; height: 118px; border-radius: 50%;
  background: linear-gradient(#ffffff, #dcdcdc);
  box-shadow: 0 0 0 4px #262626, inset 0 -5px 8px rgba(0, 0, 0, .2), 0 8px 12px rgba(0, 0, 0, .35);
}
.lens-glass {
  position: absolute; inset: 13px; border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #c4f0ff 0 7%, #4bb7ff 24%, #0e6fdc 56%, #06357f 100%);
  box-shadow: inset 0 0 0 3px #072e6a, inset 0 -10px 16px rgba(0, 0, 0, .35);
  transition: filter .12s;
}
.lens-glass::after {
  content: ""; position: absolute; left: 17%; top: 14%; width: 30%; height: 21%;
  border-radius: 50%; background: rgba(255, 255, 255, .78); transform: rotate(-32deg);
}
.lens-glow {
  position: absolute; inset: 6px; border-radius: 50%;
  box-shadow: 0 0 40px 14px rgba(90, 200, 255, .75);
  opacity: 0; transition: opacity .2s;
}
.lens.talk .lens-glow { opacity: 1; animation: glow .45s ease-in-out infinite alternate; }
.lens.talk .lens-glass { animation: talk .45s ease-in-out infinite alternate; }
.lens.blip .lens-glass { filter: brightness(1.7); }
@keyframes talk { from { filter: brightness(1); } to { filter: brightness(1.5); } }
@keyframes glow { from { opacity: .45; } to { opacity: 1; } }
body.off .lens-glass { filter: brightness(.4) saturate(.6); }

.leds { left: 172px; top: 28px; display: flex; gap: 14px; }
.led {
  width: 24px; height: 24px; border-radius: 50%;
  box-shadow: 0 0 0 3px #262626, inset 0 -3px 5px rgba(0, 0, 0, .35);
}
.led.red { background: radial-gradient(circle at 35% 30%, #ffc0c0, #ff2b2b 45%, #9e0000); }
.led.yellow { background: radial-gradient(circle at 35% 30%, #fff4b8, #ffd21f 45%, #b38600); }
.led.green { background: radial-gradient(circle at 35% 30%, #ccffcc, #2fd12f 45%, #0a780a); }
body.off .led { filter: brightness(.35); }
.leds.busy .led { animation: ledblink .5s steps(2, jump-none) infinite; }
.leds.busy .led:nth-child(2) { animation-delay: .17s; }
.leds.busy .led:nth-child(3) { animation-delay: .34s; }
@keyframes ledblink { 0% { filter: brightness(1.15); } 100% { filter: brightness(.35); } }

/* ---------- screens (shared) ---------- */
.screen { overflow: hidden; }
.screen.dark {
  background: radial-gradient(ellipse at 50% 35%, #15221a, #060a07 85%);
  border: 4px solid #2a2a2a; border-radius: 8px;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, .85), 0 2px 0 rgba(255, 255, 255, .22);
  color: var(--scr-text);
  font-family: var(--lcd);
  text-shadow: 0 0 6px rgba(120, 255, 150, .4);
}
.screen.dark::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, .22) 2px 3px);
}
body.off .screen { background: #0b0e0c !important; }
body.off .screen > * { visibility: hidden; }
body.booting .screen { animation: flicker .7s steps(7, end) both; }
@keyframes flicker {
  0% { filter: brightness(0); } 25% { filter: brightness(1.7); } 40% { filter: brightness(.25); }
  65% { filter: brightness(1.25); } 100% { filter: brightness(1); }
}

/* ---------- main screen ---------- */
.main-screen {
  left: 92px; top: 228px; width: 396px; height: 272px;
  border: 4px solid #383838; border-radius: 8px;
  background: radial-gradient(ellipse at 50% 46%, #f6faf3 0%, #d3dfcf 72%, #b4c3b0 100%);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, .25), 0 2px 0 rgba(255, 255, 255, .6);
  touch-action: none;
  cursor: grab;
}
.main-screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, .045) 2px 3px);
}
#sprite {
  position: absolute; left: 50%; top: 53%;
  width: 236px; height: 236px; object-fit: contain;
  transform: translate(calc(-50% + var(--dx, 0px)), -50%) scale(.9);
  opacity: 0;
  transition: opacity .25s, transform .25s cubic-bezier(.2, .9, .3, 1.2);
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, .22));
  pointer-events: none;
}
#sprite.shown { opacity: 1; transform: translate(calc(-50% + var(--dx, 0px)), -50%) scale(1); }
#sprite.pixel { image-rendering: pixelated; width: 280px; height: 280px; }
#sprite.dragging { transition: opacity .25s; }
.ms-num {
  left: 12px; top: 10px; position: absolute;
  font-family: var(--px); font-size: 14px; color: var(--lcd-ink);
}
.ms-tags { position: absolute; right: 10px; top: 8px; display: flex; gap: 6px; }
.ms-tags span {
  font-family: var(--px); font-size: 9px; color: var(--lcd-ink);
  border: 2px solid var(--lcd-ink); border-radius: 3px; padding: 3px 5px 2px;
}
.ms-tags .shiny { background: var(--lcd-ink); color: #ffe066; }
.ms-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--px); font-size: 13px; color: var(--lcd-ink); text-align: center; line-height: 1.6; white-space: pre-line;
  pointer-events: none;
}
.ms-msg:empty { display: none; }
.ms-hint {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 18px; color: var(--lcd-ink); opacity: .28;
}
.ms-hint.l { left: 8px; } .ms-hint.r { right: 8px; }
.scan {
  position: absolute; left: 0; right: 0; top: -60px; height: 60px; display: none;
  background: linear-gradient(transparent, rgba(40, 130, 70, .3), transparent);
}
.main-screen.scanning .scan { display: block; animation: scan .9s linear infinite; }
@keyframes scan { to { top: 100%; } }

.cry-btn {
  left: 72px; top: 510px; width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8a8a, #e3132f 45%, #8b0012);
  box-shadow: 0 0 0 2px #5b000e, 0 4px 0 #5b000e;
}
.cry-btn.pressed { transform: translateY(3px); box-shadow: 0 0 0 2px #5b000e, 0 1px 0 #5b000e; }
.lbl-cry { left: 120px; top: 524px; color: #777; text-shadow: none; }

/* ---------- controls ---------- */
.round-btn {
  left: 52px; top: 604px; width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #6a6a6a, #1d1d1d 58%, #050505);
  box-shadow: 0 6px 0 #000, 0 10px 14px rgba(0, 0, 0, .4);
}
.round-btn.pressed { transform: translateY(5px); box-shadow: 0 1px 0 #000, 0 3px 6px rgba(0, 0, 0, .4); }
.lbl-voice { left: 46px; top: 694px; width: 86px; }

.pill {
  top: 606px; width: 86px; height: 22px; border-radius: 11px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .45);
}
.pill.red { left: 160px; background: linear-gradient(#ff5a64, #d11624); border: 2px solid #7a0010; }
.pill.blue { left: 264px; background: linear-gradient(#5fa0ff, #1f5fd0); border: 2px solid #0b2f78; }
.pill.on { filter: brightness(1.25); box-shadow: 0 4px 0 rgba(0, 0, 0, .45), 0 0 14px rgba(255, 255, 255, .6); }
.pill.pressed { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .45); }
.lbl-shiny { left: 160px; top: 638px; width: 86px; }
.lbl-view { left: 264px; top: 638px; width: 86px; }

.green-screen {
  left: 160px; top: 664px; width: 232px; height: 140px;
  border: 4px solid #2a2a2a; border-radius: 8px;
  background: radial-gradient(ellipse at 50% 35%, #7fe07a, #49b444 90%);
  box-shadow: inset 0 0 14px rgba(0, 0, 0, .35), 0 2px 0 rgba(255, 255, 255, .25);
  color: #10310f; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.green-screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, .06) 2px 3px);
}
.gs-top { display: flex; justify-content: space-between; font-family: var(--lcd); font-size: 26px; line-height: 1; }
.gs-star { color: #10310f; opacity: 0; transition: opacity .2s; }
.gs-star.on { opacity: 1; }
.gs-name {
  font-family: var(--px); font-size: 15px; line-height: 1.25; white-space: nowrap;
  overflow: hidden; text-overflow: clip;
}
.gs-name.long { font-size: 12px; }
.gs-name.xlong { font-size: 10px; }
.gs-types { display: flex; gap: 6px; flex-wrap: wrap; }

.dpad {
  left: 414px; top: 628px; width: 156px; height: 156px;
  display: grid; grid-template: repeat(3, 52px) / repeat(3, 52px);
  filter: drop-shadow(0 6px 0 #000) drop-shadow(0 10px 10px rgba(0, 0, 0, .35));
}
.dpad .d { background: linear-gradient(#3b3b3b, #1b1b1b); position: relative; }
.dpad .up { grid-area: 1 / 2; border-radius: 8px 8px 0 0; }
.dpad .left { grid-area: 2 / 1; border-radius: 8px 0 0 8px; }
.dpad .mid { grid-area: 2 / 2; background: #1f1f1f; }
.dpad .right { grid-area: 2 / 3; border-radius: 0 8px 8px 0; }
.dpad .down { grid-area: 3 / 2; border-radius: 0 0 8px 8px; }
.dpad .d.pressed { background: linear-gradient(#141414, #2a2a2a); }
.dpad .d i { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform: translate(-50%, -50%); border: 8px solid transparent; }
.dpad .up i { border-bottom-color: #666; margin-top: -4px; }
.dpad .down i { border-top-color: #666; margin-top: 4px; }
.dpad .left i { border-right-color: #666; margin-left: -4px; }
.dpad .right i { border-left-color: #666; margin-left: 4px; }
.dpad .mid i { width: 22px; height: 22px; border: 0; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #333, #111); box-shadow: inset 0 2px 3px rgba(0, 0, 0, .8); }

.slits { left: 62px; top: 736px; display: flex; flex-direction: column; gap: 8px; }
.slits i { display: block; width: 56px; height: 6px; border-radius: 3px; background: #8d0019; box-shadow: inset 0 2px 2px rgba(0, 0, 0, .45), 0 1px 0 rgba(255, 255, 255, .2); }

/* ---------- right half ---------- */
.top-btns { right: 34px; top: 92px; display: flex; gap: 10px; }
.mini {
  height: 40px; padding: 0 14px; border-radius: 8px;
  background: linear-gradient(#3d3d3d, #161616); color: #bbb;
  font-family: var(--px); font-size: 10px;
  box-shadow: 0 4px 0 #000;
  display: flex; align-items: center; gap: 6px;
}
.mini b { font-family: -apple-system, system-ui, sans-serif; font-size: 18px; color: #666; font-weight: normal; transition: color .2s, text-shadow .2s; }
.mini.on b { color: #ffd84a; text-shadow: 0 0 8px #ffb700; }
.mini.on { color: #ffe9a0; }
.mini.gear { font-size: 22px; font-family: inherit; width: 48px; justify-content: center; padding: 0; }
.mini.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #000; }

.desc-screen {
  left: 40px; top: 142px; width: 510px; height: 210px;
  display: flex; flex-direction: column;
}
.ds-head {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 12px 4px; font-size: 22px; color: #dfffe6;
  border-bottom: 1px dashed var(--scr-line);
  white-space: nowrap;
}
.ds-head span:first-child { overflow: hidden; text-overflow: ellipsis; }
.ds-body {
  flex: 1; padding: 6px 12px; font-size: 25px; line-height: 1.08;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  -webkit-user-select: text; user-select: text;
}
.ds-foot {
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px dashed var(--scr-line); font-size: 19px; color: var(--scr-dim);
}
.ds-foot span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 6px; }
.ds-foot button { width: 64px; height: 30px; color: var(--scr-text); font-size: 18px; flex: none; }
.ds-foot button.pressed { background: rgba(157, 255, 176, .15); }
.caret { display: inline-block; width: .5em; height: .9em; background: currentColor; vertical-align: -.1em; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.tabs { left: 40px; top: 368px; width: 510px; display: flex; gap: 10px; }
.tab {
  flex: 1; height: 38px; border-radius: 6px;
  background: linear-gradient(#3a3a3a, #141414); color: #7b897e;
  font-family: var(--px); font-size: 11px;
  box-shadow: 0 4px 0 #000;
}
.tab.on {
  color: var(--scr-text); text-shadow: 0 0 8px #5f5;
  transform: translateY(3px); box-shadow: 0 1px 0 #000, inset 0 0 10px rgba(120, 255, 150, .25);
}
.tab.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #000; }

.data-screen {
  left: 40px; top: 420px; width: 510px; height: 228px;
  font-size: 22px;
}
.data-screen > .pane { position: absolute; inset: 0; padding: 10px 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.data-screen.dim .pane { opacity: .35; }
.empty { height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 26px; color: var(--scr-dim); flex-direction: column; gap: 12px; }
.retry { border: 2px solid var(--scr-text); color: var(--scr-text); font-family: var(--px); font-size: 11px; padding: 10px 16px; border-radius: 6px; }

.kv { display: grid; grid-template-columns: 128px 1fr; row-gap: 3px; column-gap: 10px; line-height: 1.05; }
.kv dt { color: var(--scr-dim); }
.kv dd { margin: 0; }
.kv .hid { color: var(--scr-dim); }

.stats { display: grid; grid-template-columns: 84px 44px 1fr; align-items: center; row-gap: 6px; column-gap: 10px; }
.stats .sl { color: var(--scr-dim); }
.stats .sv { text-align: right; }
.bar { height: 14px; background: rgba(157, 255, 176, .1); border: 1px solid var(--scr-line); position: relative; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--scr-text); box-shadow: 0 0 8px rgba(120, 255, 150, .5); transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.bar i.lo { background: #ff6b6b; box-shadow: 0 0 8px rgba(255, 90, 90, .5); }
.bar i.mid { background: #ffd84a; box-shadow: 0 0 8px rgba(255, 210, 60, .5); }
.bar i.hi { background: #7dffa0; }
.bar i.top { background: #6ee7ff; box-shadow: 0 0 8px rgba(100, 220, 255, .6); }
.stats .tot { grid-column: 1 / -1; display: flex; justify-content: space-between; border-top: 1px dashed var(--scr-line); padding-top: 4px; margin-top: 2px; }

.evo { min-height: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; width: max-content; min-width: 100%; }
.evo-col { display: grid; grid-template-columns: repeat(var(--cols, 1), 88px); gap: 4px; }
.evo-arrow { color: var(--scr-dim); font-size: 22px; }
.evo-mon {
  display: flex; flex-direction: column; align-items: center; padding: 2px; border-radius: 6px;
  border: 1px solid transparent; color: var(--scr-text); font-family: var(--lcd); text-shadow: inherit;
}
.evo-mon.cur { border-color: var(--scr-text); background: rgba(157, 255, 176, .08); }
.evo-mon.pressed { background: rgba(157, 255, 176, .2); }
.evo-mon img { width: 84px; height: 84px; margin: -12px 0 -10px; object-fit: contain; image-rendering: pixelated; }
.em-name { font-size: 18px; line-height: 1; max-width: 86px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.em-cond { font-size: 15px; line-height: 1; color: var(--scr-dim); text-align: center; max-width: 86px; }
.evo-note { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; color: var(--scr-dim); font-size: 20px; }

.tgroup { display: grid; grid-template-columns: 70px 1fr; gap: 8px; align-items: start; margin-bottom: 8px; }
.tgroup .tm { color: var(--scr-dim); padding-top: 2px; }
.tgroup .tl { display: flex; flex-wrap: wrap; gap: 5px; }
.thead { font-size: 18px; color: var(--scr-dim); margin-bottom: 6px; border-bottom: 1px dashed var(--scr-line); }

.type {
  display: inline-block; padding: 4px 7px 3px; border-radius: 4px;
  background: var(--c, #777); color: #fff;
  font-family: var(--px); font-size: 9px; line-height: 1; letter-spacing: .02em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .55);
  border: 1px solid rgba(0, 0, 0, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}
.green-screen .type { font-size: 9px; }

.keys {
  left: 40px; top: 666px; width: 510px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
}
.key {
  height: 42px; border-radius: 6px;
  background: linear-gradient(#55a4ff, #1f6fe0);
  border: 2px solid #0f3f8d;
  box-shadow: 0 4px 0 #0c3a82, 0 6px 8px rgba(0, 0, 0, .3);
  font-family: var(--px); font-size: 14px; color: rgba(255, 255, 255, .92);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}
.key.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #0c3a82; }

.num-display {
  left: 40px; top: 772px; width: 150px; height: 50px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--px); font-size: 16px; color: var(--scr-dim);
}
.num-display.typing { color: var(--scr-text); }
.num-display.err { color: #ff6b6b; text-shadow: 0 0 8px rgba(255, 80, 80, .6); }

.wbtn, .ybtn {
  height: 50px; border-radius: 8px;
  font-family: var(--px); font-size: 11px;
}
.wbtn { background: linear-gradient(#ffffff, #d8d8d8); color: #333; border: 2px solid #8a8a8a; box-shadow: 0 4px 0 #7a7a7a; }
.ybtn { background: linear-gradient(#ffe36e, #f0b400); color: #4a3500; border: 2px solid #9a6f00; box-shadow: 0 4px 0 #8a6200; }
.wbtn.pressed, .ybtn.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #7a7a7a; }
.b-clr { left: 200px; top: 772px; width: 70px; }
.b-go { left: 280px; top: 772px; width: 70px; }
.b-search { left: 360px; top: 772px; width: 90px; font-size: 10px; }
.b-random { left: 460px; top: 772px; width: 90px; font-size: 10px; }

/* portrait flip tab */
.flip-tab {
  display: none; left: 592px; top: 340px; width: 44px; height: 160px;
  border-radius: 0 12px 12px 0;
  background: linear-gradient(90deg, #8a0018, #c90c2b);
  box-shadow: 0 6px 12px rgba(0, 0, 0, .5);
  align-items: center; justify-content: center;
}
.flip-tab span {
  writing-mode: vertical-rl; font-family: var(--px); font-size: 11px; color: #ffd6dc; letter-spacing: .1em;
}
.flip-tab.pressed { filter: brightness(.85); }
body.portrait .flip-tab { display: flex; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: -20px; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .6);
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.ov-frame {
  width: calc(100% - 80px); height: calc(100% - 80px);
  background: linear-gradient(#e3112e, #c10822);
  border: 3px solid var(--red-deep); border-radius: 26px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .6), inset 0 2px 0 rgba(255, 255, 255, .25);
  padding: 22px; display: flex; flex-direction: column; gap: 14px;
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.15);
}
.ov-frame.narrow { max-width: 620px; height: auto; max-height: calc(100% - 80px); }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.ov-head { display: flex; gap: 12px; align-items: stretch; }
.ov-title { flex: 1; font-family: var(--px); font-size: 18px; color: #fff; display: flex; align-items: center; text-shadow: 0 2px 0 var(--red-deep); }
.ov-close { width: 64px; height: 58px; font-size: 22px; font-family: inherit; flex: none; }
#searchInput {
  flex: 1; min-width: 0; height: 58px; border-radius: 8px;
  border: 4px solid #2a2a2a; background: #08100a; color: var(--scr-text);
  font-family: var(--lcd); font-size: 32px; padding: 0 16px;
  box-shadow: inset 0 0 14px rgba(0, 0, 0, .9);
  text-shadow: 0 0 6px rgba(120, 255, 150, .4);
  -webkit-appearance: none; appearance: none; outline: none;
  -webkit-user-select: text; user-select: text;
}
#searchInput::placeholder { color: #3f7c4c; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 40px; min-width: 52px; padding: 0 12px; border-radius: 6px;
  background: linear-gradient(#3a3a3a, #141414); color: #9aa69c;
  font-family: var(--px); font-size: 10px; box-shadow: 0 4px 0 #000;
}
.chip.on { color: var(--scr-text); text-shadow: 0 0 8px #5f5; transform: translateY(3px); box-shadow: 0 1px 0 #000, inset 0 0 10px rgba(120, 255, 150, .25); }
.chip.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.list {
  position: relative; flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  align-content: start; gap: 8px; padding: 12px;
}
.list::after, .settings-body::after { display: none; }
.row {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 8px;
  height: 64px; padding: 0 10px 0 4px; border-radius: 6px; text-align: left;
  border: 1px solid var(--scr-line); background: rgba(157, 255, 176, .04);
  color: var(--scr-text); font-family: var(--lcd); text-shadow: inherit;
  content-visibility: auto; contain-intrinsic-size: 196px 64px;
}
.row.pressed { background: rgba(157, 255, 176, .2); }
.row.cur { border-color: var(--scr-text); background: rgba(157, 255, 176, .12); }
.row img { width: 64px; height: 64px; margin: 0 -4px; object-fit: contain; image-rendering: pixelated; }
.row .rt { display: flex; flex-direction: column; min-width: 0; line-height: 1; }
.row .rn { font-size: 17px; color: var(--scr-dim); }
.row .rm { font-size: 23px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row:not(.seen) .rm { opacity: .55; }
.row .rs { color: #ffd84a; font-size: 18px; opacity: 0; }
.row.caught .rs { opacity: 1; }
.star { font-family: -apple-system, system-ui, sans-serif; font-size: 18px; line-height: 0; vertical-align: -2px; }
.ov-count { font-family: var(--px); font-size: 10px; color: #ffd6dc; text-align: center; }

.settings-body { position: relative; padding: 14px 18px; font-size: 26px; overflow-y: auto; }
.set-row { display: flex; align-items: center; gap: 12px; min-height: 56px; border-bottom: 1px dashed var(--scr-line); }
.set-row > span { width: 150px; color: var(--scr-dim); flex: none; }
.set-row b { font-weight: normal; width: 50px; text-align: right; }
.tog {
  height: 38px; min-width: 76px; border-radius: 6px; border: 2px solid var(--scr-dim);
  color: var(--scr-dim); font-family: var(--px); font-size: 11px;
}
.tog.on { border-color: var(--scr-text); color: #06130a; background: var(--scr-text); text-shadow: none; }
.settings-body select {
  flex: 1; min-width: 0; height: 40px; font-family: var(--lcd); font-size: 22px;
  background: #0c1a10; color: var(--scr-text); border: 2px solid var(--scr-dim); border-radius: 6px; padding: 0 8px;
}
.settings-body .wbtn { height: 40px; padding: 0 14px; font-size: 10px; flex: none; }
.settings-body input[type=range] { flex: 1; accent-color: #7dffa0; height: 36px; }
.diag { flex: 1; font-size: 17px; line-height: 1.05; color: var(--scr-dim); }
.credit { font-size: 18px; color: var(--scr-dim); line-height: 1.1; margin: 12px 0 0; }

/* ---------- toast + power ---------- */
#toast {
  position: absolute; left: 50%; bottom: 30px; transform: translate(-50%, 20px);
  background: #08100a; color: var(--scr-text); border: 3px solid #2a2a2a; border-radius: 8px;
  font-family: var(--px); font-size: 12px; padding: 12px 18px; z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
  text-shadow: 0 0 6px rgba(120, 255, 150, .4);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#power { position: absolute; inset: -20px; z-index: 60; display: none; }
body.off #power { display: block; }
#power span {
  position: absolute; left: 112px; top: 248px; width: 396px; height: 272px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--px); font-size: 14px; color: #6dff8c; text-shadow: 0 0 10px rgba(80, 255, 120, .7);
  animation: blink 1.2s steps(1) infinite;
}

/* landscape boot: closed device sits centred, slides over as the lid swings open */
body.off:not(.portrait) #device { transform: translateX(305px); }
body.booting:not(.portrait) #device { transition: transform 1.1s cubic-bezier(.3, .75, .25, 1); }
body.off:not(.portrait) .half.right { transform: rotateY(-178deg); }
body.booting:not(.portrait) .half.right { animation: unfold 1.1s cubic-bezier(.3, .75, .25, 1) both; }
@keyframes unfold { from { transform: rotateY(-178deg); } to { transform: rotateY(0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
