/* TDT ADVENTURE — shell. The game is one canvas; this file places it and builds the touch consoles.
   body.d-desk  desktop / TV: canvas fills the screen (16:9..21:9)
   body.d-port  phone portrait: vertical Game Boy — 3:4 game screen in a bezel, console with stick + A/B/↻ below
   body.d-land  phone landscape: GBA / Wii U GamePad — 3:2 screen centred between two control wings
   body.d-over  tablet / no room for wings: fullscreen + floating translucent stick and buttons while playing
   body.d-pad   phone used as a controller: second screen (minimap, stats, tips) + the console */
@font-face { font-family: Rubik; src: url(../assets/fonts/rubik-latin.woff2) format('woff2'); font-weight: 300 900; font-display: swap; }
:root { --o: #ff5a14; --o2: #ff8a3a; --o3: #d8430a; --ink: #2a1408; --cream: #fff8ec; --wing: min(46vh, 38vw); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #120a1e; overflow: hidden; overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; font-family: Rubik, system-ui, sans-serif; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; z-index: 2; }
#cv { display: block; background: #120a1e; }
#pad { display: none; position: relative; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- console pieces ---------------- */
#lzone { position: absolute; touch-action: none; }
#stick { position: absolute; width: 150px; height: 150px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(255, 255, 255, .16), rgba(42, 20, 8, .55) 70%); box-shadow: inset 0 6px 14px rgba(0, 0, 0, .45), 0 2px 0 rgba(255, 255, 255, .25); }
#stick::before { content: ''; position: absolute; inset: 14%; border-radius: 50%; border: 2px dashed rgba(255, 255, 255, .25); }
#knob { position: absolute; left: 28%; top: 28%; width: 44%; height: 44%; border-radius: 50%; transition: transform .05s linear;
  background: radial-gradient(circle at 38% 30%, #ffffff 0%, #ffe2c8 22%, #ff8a3a 58%, #c23d06 100%); box-shadow: 0 8px 14px rgba(0, 0, 0, .45), inset 0 -5px 8px rgba(0, 0, 0, .25); }
#stick.on #knob { transition: none; }
#rzone { position: absolute; touch-action: none; }
#rzone button { position: absolute; border-radius: 50%; border: 0; color: #fff; font-weight: 900; padding: 0;
  box-shadow: 0 7px 0 rgba(0, 0, 0, .38), 0 10px 18px rgba(0, 0, 0, .35), inset 0 -6px 10px rgba(0, 0, 0, .22), inset 0 6px 10px rgba(255, 255, 255, .35); }
#rzone button span { display: block; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
#rzone .ba { background: radial-gradient(circle at 35% 28%, #ffd0b0, #ff5a14 45%, #b8320a 100%); }
#rzone .bb { background: radial-gradient(circle at 35% 28%, #fff4b8, #f2b705 48%, #b07d00 100%); color: var(--ink); }
#rzone .bb span { text-shadow: 0 2px 0 rgba(255, 255, 255, .5); }
#rzone .bs { background: radial-gradient(circle at 35% 28%, #e6d6ff, #8c5cf0 50%, #4f2aa8 100%); }
#rzone button.on { transform: translateY(5px) scale(.96); box-shadow: 0 2px 0 rgba(0, 0, 0, .38), inset 0 -3px 8px rgba(0, 0, 0, .25), inset 0 5px 10px rgba(255, 255, 255, .3); filter: brightness(1.12); }
#pills { position: absolute; display: flex; gap: 14px; z-index: 3; }
#pills button { min-width: 62px; height: 30px; padding: 0 14px; border-radius: 15px; border: 0; background: linear-gradient(#4a2c1c, #2a1408); color: #ffe7cf;
  font-weight: 800; font-size: 13px; letter-spacing: 1.5px; box-shadow: 0 3px 0 rgba(0, 0, 0, .4), inset 0 2px 3px rgba(255, 255, 255, .15); }
#pills button.on { transform: translateY(2px); background: #ffd23f; color: var(--ink); }
#brand, #grille { display: none; }

/* a console body: TDT orange with a soft sunburst */
body.d-port #pad, body.d-land #pad, body.d-pad #pad {
  display: block; background: repeating-conic-gradient(from 0deg at 50% 0%, rgba(255, 255, 255, .06) 0 6deg, transparent 6deg 12deg),
  radial-gradient(130% 90% at 50% 0%, var(--o2) 0%, var(--o) 45%, var(--o3) 100%); }
body.d-port #brand, body.d-pad #brand, body.d-land #brand { display: block; position: absolute; color: #fff; font-weight: 900; letter-spacing: 4px; font-size: 13px; opacity: .95; }
#brand b { background: var(--cream); color: var(--o); padding: 1px 8px; border-radius: 7px; margin-right: 7px; letter-spacing: 2px; }
body.d-port #grille, body.d-pad #grille { display: flex; position: absolute; gap: 7px; transform: rotate(-28deg); }
#grille i { width: 6px; height: 46px; border-radius: 3px; background: rgba(42, 20, 8, .45); box-shadow: inset 0 2px 2px rgba(0, 0, 0, .4); }
body.d-port #stage canvas, body.d-land #stage canvas, body.d-pad #stage canvas { border-radius: 10px; box-shadow: 0 0 0 6px #1b0d05, 0 0 0 9px rgba(255, 255, 255, .25), 0 12px 24px rgba(0, 0, 0, .4); }

/* ---------------- portrait: vertical Game Boy ---------------- */
body.d-port #app, body.d-pad #app { flex-direction: column; }
body.d-port #stage { order: 0; flex: 0 0 auto; height: min(calc((100vw - 28px) * 4 / 3), 64vh); margin: calc(12px + env(safe-area-inset-top)) 14px 0; background: #1b0d05; border-radius: 18px 18px 28px 28px; padding: 10px; }
body.d-port #pad { order: 1; flex: 1 1 auto; margin-top: -40px; padding-top: 40px; }
body.d-port #lzone, body.d-pad #lzone { left: 0; top: 0; bottom: 0; width: 52%; }
body.d-port #stick, body.d-pad #stick { width: min(40vw, 32vh, 190px); height: min(40vw, 32vh, 190px); left: 6vw; top: 50%; margin-top: calc(min(40vw, 32vh, 190px) / -2 + 10px); }
body.d-port #rzone, body.d-pad #rzone { right: 0; top: 0; bottom: 0; width: 48%; }
body.d-port #rzone .ba, body.d-pad #rzone .ba { width: min(21vw, 17vh, 100px); height: min(21vw, 17vh, 100px); right: 5vw; top: calc(50% - min(21vw, 17vh, 100px) * .95); font-size: 30px; }
body.d-port #rzone .bb, body.d-pad #rzone .bb { width: min(19vw, 15vh, 90px); height: min(19vw, 15vh, 90px); right: calc(5vw + min(21vw, 17vh, 100px) + 8px); top: calc(50% - min(19vw, 15vh, 90px) * .2); font-size: 27px; }
body.d-port #rzone .bs, body.d-pad #rzone .bs { width: min(13vw, 10vh, 60px); height: min(13vw, 10vh, 60px); right: calc(5vw + 8px); top: calc(50% + min(21vw, 17vh, 100px) * .25); font-size: 24px; }
body.d-port #pills, body.d-pad #pills { left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); }
body.d-port #brand, body.d-pad #brand { left: 0; right: 0; text-align: center; top: 52px; }
body.d-port #grille, body.d-pad #grille { right: 9vw; bottom: max(40px, calc(env(safe-area-inset-bottom) + 28px)); }

/* ---------------- landscape: GBA / Wii U GamePad wings ---------------- */
body.d-land #pad, body.d-pad.land #pad { position: absolute; inset: 0; }
body.d-land #stage { position: absolute; top: 0; bottom: 0; left: calc(50% - 75vh + 10px); width: calc(150vh - 20px); padding: max(10px, env(safe-area-inset-top)) 0 10px; }
body.d-land #lzone { left: 0; top: 0; bottom: 0; width: calc(50% - 75vh + 10px); }
body.d-land #rzone { right: 0; top: 0; bottom: 0; width: calc(50% - 75vh + 10px); }
body.d-land #stick { width: min(34vh, 21vw, 170px); height: min(34vh, 21vw, 170px); left: 50%; top: 58%; transform: translate(-50%, -50%); }
body.d-land #rzone .ba { width: min(24vh, 12vw, 88px); height: min(24vh, 12vw, 88px); right: 8%; top: 24%; font-size: 28px; }
body.d-land #rzone .bb { width: min(20vh, 10vw, 74px); height: min(20vh, 10vw, 74px); right: calc(100% - min(20vh, 10vw, 74px) - 6px); top: 48%; font-size: 24px; }
body.d-land #rzone .bs { width: min(14vh, 7vw, 52px); height: min(14vh, 7vw, 52px); right: 12%; top: 72%; font-size: 20px; }
body.d-land #pills { right: calc((50% - 75vh + 10px) / 2); transform: translateX(50%); top: max(10px, env(safe-area-inset-top)); flex-direction: column; gap: 8px; }
body.d-land #brand { left: 0; width: calc(50% - 75vh + 10px); text-align: center; top: max(12px, env(safe-area-inset-top)); font-size: 11px; letter-spacing: 2px; }

/* ---------------- tablet / no room: translucent floating controls while playing ---------------- */
body.d-over.playing #pad { display: block; position: absolute; inset: 0; pointer-events: none; z-index: 3; }
body.d-over.playing #pad > * { pointer-events: auto; }
body.d-over #lzone { left: 0; bottom: 0; width: 45%; height: 70%; }
body.d-over #stick { width: 150px; height: 150px; left: 40px; bottom: 30px; top: auto; opacity: .8; }
body.d-over #rzone { right: 0; bottom: 0; width: 40%; height: 60%; }
body.d-over #rzone .ba { width: 96px; height: 96px; right: 40px; bottom: 110px; font-size: 30px; opacity: .88; }
body.d-over #rzone .bb { width: 84px; height: 84px; right: 150px; bottom: 50px; font-size: 26px; opacity: .88; }
body.d-over #rzone .bs { width: 58px; height: 58px; right: 52px; bottom: 30px; font-size: 22px; opacity: .88; }
body.d-over #pills { top: 12px; left: 50%; transform: translateX(-50%); opacity: .85; }
body.d-over #pills button[data-b="back"] { display: none; }

/* ---------------- the phone as a controller: second screen on top (portrait) or between the wings (landscape) ---------------- */
body.d-pad #stage { order: 0; flex: 0 0 auto; height: min(calc(100vw - 28px), 50vh); margin: calc(12px + env(safe-area-inset-top)) 14px 0; background: #1b0d05; border-radius: 18px; padding: 8px; }
body.d-pad #pad { order: 1; flex: 1 1 auto; margin-top: -40px; padding-top: 40px; }
@media (orientation: landscape) {
  body.d-pad #app { flex-direction: row; }
  body.d-pad #pad { position: absolute; inset: 0; margin: 0; padding: 0; }
  body.d-pad #stage { position: absolute; top: 0; bottom: 0; left: 26vw; width: 48vw; height: auto; margin: 0; padding: 10px 0; background: none; }
  body.d-pad #lzone { width: 26vw; } body.d-pad #rzone { width: 26vw; }
  body.d-pad #stick { left: 50%; top: 56%; transform: translate(-50%, -50%); margin: 0; }
  body.d-pad #rzone .ba { right: 12%; top: 30%; } body.d-pad #rzone .bb { right: 50%; top: 50%; } body.d-pad #rzone .bs { right: 18%; top: 70%; }
  body.d-pad #pills { left: auto; right: 13vw; transform: translateX(50%); top: 10px; bottom: auto; }
  body.d-pad #brand { width: 26vw; left: 0; right: auto; top: 12px; } body.d-pad #grille { display: none; }
}
