@font-face { font-family: 'TG'; src: url('font.ttf') format('truetype'); font-display: block; }
:root {
  --page: #16171c;
  --body: #cdcac3; --body-hi: #dedbd5; --body-lo: #aaa69e;
  --lens: #5a5c6b; --lens-lo: #45475a;
  --ink: #2c2f6b;
  --btn: #9b2153; --btn-hi: #c13a72; --btn-lo: #6d1338;
  --pad: #26262b;
  --px: 2px;
  --paper: #f6f1e1; --paper-ink: #1d1c27; --paper-muted: #5b5866;
  --sgb: #26306a; --sgb-2: #e0534a; --sgb-3: #f0c24b; --sgb-4: #3aa58a;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); overflow: hidden; -webkit-tap-highlight-color: transparent; }
body { font-family: 'TG', ui-monospace, monospace; color: var(--paper-ink); -webkit-font-smoothing: none; font-smooth: never; }
button { font: inherit; color: inherit; }

/* ---------------- the handheld */
.gb { position: fixed; inset: 0; display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; }
.shell {
  --w: min(100vw, 56svh);
  position: relative; width: var(--w); height: 100svh; height: 100dvh;
  display: flex; flex-direction: column; padding: calc(var(--w) * .035) calc(var(--w) * .035) 0;
  background: linear-gradient(180deg, var(--body-hi), var(--body) 12%, var(--body) 88%, var(--body-lo));
  border-radius: 10px 10px calc(var(--w) * .2) 10px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35), inset -6px -8px 18px rgba(0,0,0,.08), 0 20px 60px rgba(0,0,0,.5);
}
.lens {
  position: relative; flex: 0 0 auto; width: 100%; aspect-ratio: 160 / 152;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #66687a, var(--lens) 40%, var(--lens-lo));
  border-radius: 8px 8px calc(var(--w) * .1) 8px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.08), inset 0 -2px 6px rgba(0,0,0,.25);
}
.led { position: absolute; left: 3.6%; top: 42%; width: 2.6%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ff8a8a, #d5121b 60%, #7d0a10); box-shadow: 0 0 8px rgba(255, 40, 40, .6); pointer-events: none; }
.screen-wrap { position: relative; width: 320px; height: 288px; background: #e0f8d0; box-shadow: 0 0 0 2px rgba(0,0,0,.35), inset 0 0 12px rgba(0,0,0,.25); }
#screen { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none; cursor: pointer; }
.lcd { position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background-image: linear-gradient(rgba(8,24,32,.10) 1px, transparent 1px), linear-gradient(90deg, rgba(8,24,32,.10) 1px, transparent 1px);
  background-size: var(--px) var(--px); }
.grid .lcd { opacity: 1; }
.lcd::after { content: ''; position: absolute; inset: 0; background: linear-gradient(155deg, rgba(255,255,255,.07), transparent 40%); }

.controls { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; padding-bottom: calc(var(--w) * .08); }
.deck { position: relative; width: 100%; height: calc(var(--w) * .86); }
.dpad { position: absolute; left: 4%; top: calc(var(--w) * .12); width: calc(var(--w) * .33); aspect-ratio: 1; touch-action: none; cursor: pointer; }
.dpad .arm { position: absolute; background: var(--pad); border-radius: 5px; box-shadow: 0 3px 0 #0e0e10, inset 0 1px 0 rgba(255,255,255,.12); pointer-events: none; }
.dpad .arm.v { left: 33.5%; width: 33%; top: 0; height: 100%; }
.dpad .arm.h { top: 33.5%; height: 33%; left: 0; width: 100%; }
.dpad .hub { position: absolute; left: 40%; top: 40%; width: 20%; height: 20%; border-radius: 50%; background: radial-gradient(circle, #1a1a1e 30%, #2f2f35 70%); pointer-events: none; }
.dpad[data-dir="up"] .arm.v, .dpad[data-dir="down"] .arm.v, .dpad[data-dir="left"] .arm.h, .dpad[data-dir="right"] .arm.h { background: #1b1b1f; }
.dpad[data-dir="up"] { transform: perspective(300px) rotateX(5deg); }
.dpad[data-dir="down"] { transform: perspective(300px) rotateX(-5deg); }
.dpad[data-dir="left"] { transform: perspective(300px) rotateY(-5deg); }
.dpad[data-dir="right"] { transform: perspective(300px) rotateY(5deg); }

.ab { position: absolute; right: 3%; top: calc(var(--w) * .06); width: calc(var(--w) * .42); height: calc(var(--w) * .26); transform: rotate(-25deg); }
.btn { position: absolute; width: calc(var(--w) * .16); aspect-ratio: 1; border-radius: 50%; border: 0; padding: 0; cursor: pointer; touch-action: none;
  background: radial-gradient(circle at 38% 32%, var(--btn-hi), var(--btn) 55%, var(--btn-lo)); box-shadow: 0 4px 0 #4a0c26, 0 6px 10px rgba(0,0,0,.25); }
.btn.b { left: 0; bottom: 0; }
.btn.a { right: 0; top: 0; }
.btn span { position: absolute; left: 50%; top: 100%; transform: translate(-50%, 10px) rotate(25deg); color: var(--ink); font-size: calc(var(--w) * .045); letter-spacing: .05em; pointer-events: none; }
.btn.down, .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4a0c26; }
.ss { position: absolute; left: 50%; top: calc(var(--w) * .56); transform: translateX(-58%); display: flex; gap: calc(var(--w) * .07); }
.pill { position: relative; width: calc(var(--w) * .15); height: calc(var(--w) * .04); border-radius: 99px; border: 0; padding: 0; cursor: pointer; touch-action: none;
  background: #8e8b93; box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 0 0 3px var(--body-lo); transform: rotate(-25deg); }
.pill span { position: absolute; left: 50%; top: 150%; transform: translateX(-50%); color: var(--ink); font-size: calc(var(--w) * .03); letter-spacing: .08em; white-space: nowrap; pointer-events: none; }
.pill.down, .pill:active { background: #6f6c74; }
.grille { position: absolute; right: 5%; top: calc(var(--w) * .62); width: calc(var(--w) * .22); height: calc(var(--w) * .2); display: flex; gap: 11%; transform: rotate(-30deg); pointer-events: none; }
.grille i { flex: 1; border-radius: 99px; background: linear-gradient(90deg, #8f8b84, #b3afa8); box-shadow: inset 1px 1px 2px rgba(0,0,0,.35); }

/* wide screens: hold it sideways, controls either side of the screen */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .shell { --w: min(40svh, 22vw); width: auto; height: min(calc(100svh - 32px), 900px, calc((100vw - 24px - var(--w) * 1.64) * 0.925 + 40px)); flex-direction: row; align-items: center; gap: 0;
    padding: 20px calc(var(--w) * .1); border-radius: 18px 18px 18px 18px; }
  .lens { height: 100%; width: auto; aspect-ratio: 160 / 148; border-radius: 10px 10px 48px 10px; }
  .controls { position: static; }
  .dpad { position: relative; left: auto; top: auto; order: -1; }
  .shell { display: grid; grid-template-columns: calc(var(--w) * .62) auto calc(var(--w) * .82); grid-template-rows: 1fr; }
  .lens { grid-column: 2; grid-row: 1; }
  .controls, .deck { display: contents; }
  .dpad { grid-column: 1; grid-row: 1; justify-self: center; align-self: center; width: calc(var(--w) * .5); margin-top: 18%; }
  .ab { position: relative; grid-column: 3; grid-row: 1; right: auto; top: auto; justify-self: center; align-self: center; width: calc(var(--w) * .62); height: calc(var(--w) * .4); margin-top: -10%; }
  .btn { width: calc(var(--w) * .24); }
  .btn span { font-size: calc(var(--w) * .06); }
  .ss { position: absolute; left: auto; right: calc(var(--w) * .12); bottom: 16%; top: auto; transform: none; }
  .dpad, .ab { top: auto; }
  .pill { width: calc(var(--w) * .2); height: calc(var(--w) * .055); }
  .pill span { font-size: calc(var(--w) * .042); }
  .grille { right: auto; top: auto; left: calc(var(--w) * .12); bottom: 10%; width: calc(var(--w) * .3); height: calc(var(--w) * .26); }
}

/* ---------------- the dex page: the work, in full colour, in a border like the TV adapter's */
.dex { position: fixed; inset: 0; z-index: 10; opacity: 0; transition: opacity .25s;
  background-color: var(--sgb);
  background-image:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,.07) 2px, transparent 3px),
    radial-gradient(circle at 75% 75%, rgba(255,255,255,.07) 2px, transparent 3px),
    linear-gradient(45deg, rgba(0,0,0,.12) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.12) 75%),
    linear-gradient(45deg, rgba(0,0,0,.12) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.12) 75%);
  background-size: 24px 24px, 24px 24px, 48px 48px, 48px 48px; background-position: 0 0, 0 0, 0 0, 24px 24px; }
.dex[hidden] { display: none; }
.dex.in { opacity: 1; }
.dex-scroll { position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: max(56px, env(safe-area-inset-top)) 12px 40px; }
.dex-card { position: relative; max-width: 1040px; margin: 0 auto; background: var(--paper); color: var(--paper-ink);
  border: 4px solid var(--paper-ink); border-radius: 6px 6px 28px 6px;
  box-shadow: 0 0 0 4px var(--sgb-3), 0 0 0 8px var(--sgb-2), 0 0 0 12px var(--paper-ink), 0 24px 60px rgba(0,0,0,.45);
  padding: clamp(16px, 4vw, 40px); transform: translateY(16px); transition: transform .35s cubic-bezier(.2,.9,.3,1.2); }
.dex.in .dex-card { transform: none; }
.dex-head { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: clamp(16px, 3vw, 36px); align-items: start; }
.dex-shot { margin: 0; background: var(--paper-ink); padding: 8px; border-radius: 4px 4px 18px 4px; display: grid; place-items: center; }
.dex-shot img { display: block; max-width: 100%; height: auto; max-height: min(72vh, 640px); max-height: min(72svh, 640px); object-fit: contain; image-rendering: auto; }
.dex.fresh .dex-shot img { animation: flood 1.6s .15s ease-out both; }
@keyframes flood {
  0% { filter: grayscale(1) sepia(1) hue-rotate(48deg) saturate(1.9) contrast(1.5) brightness(.95); }
  100% { filter: none; }
}
.dex-id { min-width: 0; }
.dex-no { margin: 0 0 8px; font-size: 16px; letter-spacing: .06em; color: var(--paper-muted); display: flex; gap: 10px; align-items: center; }
.dex-ball { color: var(--sgb-2); }
.dex-ball[hidden] { display: none; }
.dex-name { margin: 0; font-weight: normal; font-size: clamp(24px, 4.2vw, 48px); line-height: 1.15; text-transform: uppercase; letter-spacing: .02em; overflow-wrap: anywhere; }
.dex-client { margin: 12px 0 0; }
.dex-client span { display: inline-block; padding: 6px 12px 4px; background: var(--sgb); color: #fff; font-size: 16px; letter-spacing: .1em; border-radius: 3px; }
.dex-entry { margin: 20px 0 0; font-size: 16px; line-height: 1.75; border-top: 4px dotted var(--paper-ink); padding-top: 18px; }
.dex-work { margin-top: clamp(24px, 4vw, 44px); }
.dex-work.ab-media { --ab-fg: var(--paper-ink); --ab-muted: var(--paper-muted); --ab-accent: var(--sgb-2); --ab-chrome: 150px; --ab-gap: 18px; font-size: 16px; line-height: 1.7; }
.dex-work .ab-heading { font-size: 16px; text-transform: uppercase; letter-spacing: .06em; padding: 6px 10px 4px; background: var(--paper-ink); color: var(--paper); justify-self: start; }
.dex-work .ab-frame { border: 4px solid var(--paper-ink); border-radius: 4px; box-sizing: content-box; }
.dex-work .ab-portrait .ab-frame { border-width: 4px; }
.dex-work .ab-credits { border-top: 4px dotted var(--paper-ink); padding-top: 16px; font-size: 14px; line-height: 1.7; }
.dex-work figcaption { font-size: 14px; }
.dex-work audio { filter: sepia(.2); }
.dex-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; }
.dex-nav button { border: 3px solid var(--paper-ink); background: var(--paper); padding: 10px 14px 8px; font-size: 16px; cursor: pointer; border-radius: 4px; }
.dex-nav button:hover, .dex-nav button:focus-visible { background: var(--paper-ink); color: var(--paper); outline: none; }
.dex-nav button[hidden] { visibility: hidden; display: block; }
.dex-close { position: fixed; z-index: 11; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 38% 32%, var(--btn-hi), var(--btn) 55%, var(--btn-lo)); color: #fff; font-size: 18px; box-shadow: 0 3px 0 #4a0c26, 0 0 0 3px var(--paper); }
.dex-close span { position: relative; top: 1px; }
.dex-close:focus-visible { outline: 3px solid var(--sgb-3); outline-offset: 3px; }

/* the trainer card */
.card .dex-card { max-width: 760px; }
.card-head { display: grid; gap: 4px; }
.card-title { margin: 8px 0 0; font-size: 16px; letter-spacing: .06em; color: var(--sgb); }
.card-contact { margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 10px 20px; font-size: 16px; }
.card-contact a { color: var(--paper-ink); }
.card-exp { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 18px; border-top: 4px dotted var(--paper-ink); padding-top: 20px; }
.card-exp strong { display: block; font-weight: normal; font-size: 16px; text-transform: uppercase; letter-spacing: .04em; }
.card-exp p { margin: 6px 0 0; font-size: 14px; line-height: 1.7; color: var(--paper-muted); }

@media (max-width: 720px) {
  .dex-head { grid-template-columns: minmax(0, 1fr); }
  .dex-shot img { max-height: 62svh; }
  .dex-scroll { padding: 60px 10px 32px; }
  .dex-card { box-shadow: 0 0 0 3px var(--sgb-3), 0 0 0 6px var(--sgb-2), 0 0 0 9px var(--paper-ink); }
}
@media (prefers-reduced-motion: reduce) { .dex, .dex-card { transition: none; } .dex.fresh .dex-shot img { animation: none; } }
/* bigger thumbs than the plastic: an invisible margin around the small buttons */
.pill::before { content: ''; position: absolute; inset: -16px -10px; }
.btn::before { content: ''; position: absolute; inset: -8px; border-radius: 50%; }
/* portrait films: fewer, bigger columns on a wide dex page */
.dex-work .ab-portrait { grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); }
