/* Final Seinfeld 7 standalone browser & mobile WASM player. */
:root {
  --bg: #000;
  --fg: #eee;
  --muted: #a29c91;
  --accent: #e6b84a;
  --panel: #16130e;
  --card: #1d1913;
  --line: #362f26;
  --pad-scale: 1;
  --pad-opacity: .55;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden;
  font: 15px/1.38 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; }
#app, #pad, #stage, #bar {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: none;
}
button {
  font: inherit; color: var(--fg); background: #2a241c;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer;
}
button:hover { border-color: #5b4e3c; }
button.icon { background: transparent; border: 0; font-size: 19px; padding: 6px 10px; line-height: 1; }
button.icon.active { color: var(--accent); }
button.pill {
  background: #211d16; border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; font-weight: 700; padding: 4px 9px; line-height: 1.2; color: var(--muted);
}
button.pill.active { background: var(--accent); border-color: var(--accent); color: #111; }
button.primary { background: var(--accent); color: #111; border: 0; font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.current { border-color: var(--accent); color: var(--accent); }
button.danger { background: #331c1a; border-color: #5c2e2a; color: #f2a9a2; padding: 8px 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; margin: 6px 0; }

#app { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- top bar */
#bar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--sat) + 2px) calc(var(--sar) + 6px) 2px calc(var(--sal) + 6px);
  z-index: 5; min-height: 42px; flex: none;
  transition: opacity .25s ease; will-change: opacity;
}
#title {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#title b { color: var(--accent); font-weight: 700; letter-spacing: .01em; }
#disc-badge {
  font-size: 12px; padding: 2px 7px; border-radius: 999px;
  background: #211d16; border: 1px solid var(--line); color: var(--fg);
}
#pad-badge { font-size: 16px; }
#btn-pad.off { opacity: .42; }
body.desktop:not(.forcepad) #btn-pad { display: none; }
@media (max-width: 410px) {
  #bar { gap: 2px; }
  button.icon { padding: 6px 7px; }
  #title { gap: 5px; font-size: 13px; }
  #disc-badge { padding: 2px 6px; font-size: 11px; flex: none; }
}

/* ---------------------------------------------------------------- workspace & stage */
#workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
#stage {
  position: relative; flex: 1; min-height: 0; min-width: 0;
  display: flex; align-items: center; justify-content: center; background: #000;
}
#screen { display: block; aspect-ratio: 4 / 3; background: #000; }

#overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: rgba(0, 0, 0, .78); text-align: center; padding: 20px; z-index: 3;
}
#overlay[hidden] { display: none; }
#overlay-text { max-width: 30em; white-space: pre-line; font-size: 16px; }
#overlay-bar { width: min(260px, 70%); height: 4px; background: #333; border-radius: 2px; overflow: hidden; }
#overlay-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#overlay-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#overlay-go {
  font-size: 17px; font-weight: 600; padding: 12px 24px;
  background: var(--accent); color: #111; border: 0; min-width: 210px;
}
#overlay-resume {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 10px;
  background: var(--accent); color: #111; border: 0; text-align: left;
}
#overlay-resume[hidden] { display: none; }
#overlay-resume img { width: 96px; height: 72px; object-fit: cover; border-radius: 4px; background: #000; }
#overlay-resume b { display: block; font-size: 16px; }
#overlay-resume small { display: block; font-size: 12px; opacity: .82; }
#overlay-resume:not([hidden]) + #overlay-go {
  background: #262119; color: var(--fg); border: 1px solid var(--line); font-size: 14px; font-weight: 500; padding: 10px 18px;
}
#overlay-sub { max-width: 30em; margin: 0; }
#overlay-sub[hidden] { display: none; }

#tap-sound {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4;
  font-size: 16px; font-weight: 600; padding: 10px 18px;
  background: var(--accent); color: #111; border: 0; border-radius: 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .55);
}
#tap-sound[hidden] { display: none; }
#toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(22, 19, 14, .94); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; z-index: 4; max-width: 90%; text-align: center;
}
#netwait {
  position: absolute; right: calc(10px + var(--sar)); top: 10px; z-index: 4;
  font-size: 18px; opacity: .8; animation: fs7pulse 1s ease-in-out infinite alternate;
  pointer-events: none;
}
#netwait[hidden] { display: none; }
@keyframes fs7pulse { from { opacity: .35; } to { opacity: .9; } }
#hint { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }

/* ---------------------------------------------------------------- desktop controls panel */
#controls {
  display: none;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px 16px; overflow-y: auto; font-size: 13px;
  -webkit-user-select: text; user-select: text; touch-action: pan-y;
  contain: layout style;
}
#controls h3 {
  margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--accent);
}
.ctrl-section + .ctrl-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.ctrl-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 5px 10px;
  align-items: center; margin: 0;
}
.ctrl-grid dt { margin: 0; white-space: nowrap; }
.ctrl-grid dd { margin: 0; color: #ddd6cb; }
.ctrl-grid dd strong { color: var(--accent); font-weight: 700; }
kbd {
  display: inline-block; min-width: 20px; text-align: center;
  padding: 1px 5px; margin-right: 2px; border-radius: 4px;
  background: #27221b; border: 1px solid #483f33; border-bottom-width: 2px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: #f4efe6;
}
.ctrl-check { display: flex; align-items: center; gap: 8px; margin-top: 8px; cursor: pointer; font-size: 13px; color: #ddd6cb; }
.ctrl-tip { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; }
#gp-status.connected { color: #7ee098; }

/* Desktop non-fullscreen layout */
body.desktop:not(.fullscreen) #controls { display: block; }
body.desktop:not(.forcepad) #pad,
body.desktop:not(.forcepad) #hint { display: none; }

@media (min-width: 960px) and (orientation: landscape) {
  body.desktop:not(.fullscreen) #workspace { flex-direction: row; }
  body.desktop:not(.fullscreen) #controls { width: 268px; flex: none; }
  body.desktop:not(.fullscreen) #screen {
    max-height: calc(100vh - 46px); max-width: 100%;
    height: min(calc(100vh - 46px), calc((100vw - 268px) * 3 / 4));
    width: auto;
  }
}
@media (max-width: 959px), (orientation: portrait) {
  body.desktop:not(.fullscreen) #workspace { flex-direction: column; }
  body.desktop:not(.fullscreen) #controls {
    border-left: 0; border-top: 1px solid var(--line);
    flex: 0 0 auto; max-height: 215px; padding: 10px 14px;
  }
  body.desktop:not(.fullscreen) #controls .ctrl-grid {
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    display: flex; flex-wrap: wrap; gap: 6px 14px;
  }
  body.desktop:not(.fullscreen) #controls .ctrl-grid dt,
  body.desktop:not(.fullscreen) #controls .ctrl-grid dd { display: inline; }
  body.desktop:not(.fullscreen) #screen {
    max-height: 100%; max-width: 100%;
    width: min(100vw, calc((100vh - 265px) * 4 / 3)); height: auto;
  }
}

/* ---------------------------------------------------------------- fullscreen (hides descriptions) */
body.fullscreen #controls,
body.fullscreen #hint,
:fullscreen #controls,
:fullscreen #hint,
:-webkit-full-screen #controls,
:-webkit-full-screen #hint { display: none !important; }

body.fullscreen.desktop #bar {
  position: absolute; top: 0; left: 0; right: 0;
  background: linear-gradient(rgba(0, 0, 0, .72), transparent);
}
body.fullscreen.desktop.bar-idle #bar { opacity: 0; pointer-events: none; }
body.fullscreen.desktop #workspace,
body.fullscreen.desktop #stage { position: absolute; inset: 0; }
body.fullscreen.desktop #screen {
  height: min(100vh, 75vw); height: min(100dvh, 75vw); width: auto; max-width: 100vw; max-height: 100dvh;
}

/* ---------------------------------------------------------------- touch pad */
#pad { position: relative; flex: 1; min-height: 0; padding-bottom: var(--sab); contain: layout style; }
#pad button, #pad .arm, #pad .hub { opacity: var(--pad-opacity); }
#pad button {
  position: absolute; padding: 0; border-radius: 50%;
  background: rgba(60, 55, 48, .85); border: 2px solid rgba(255, 255, 255, .18);
  color: #ddd; display: flex; align-items: center; justify-content: center; pointer-events: none;
}
#pad button.on, #pad .arm.on { background: rgba(230, 184, 74, .9); color: #111; opacity: 1; }
.cluster { position: absolute; }
.dpad { width: calc(150px * var(--pad-scale)); height: calc(150px * var(--pad-scale)); }
.dpad .arm { position: absolute; width: 34%; height: 34%; background: rgba(60, 55, 48, .85); border: 2px solid rgba(255, 255, 255, .18); }
.dpad .up { left: 33%; top: 0; border-radius: 8px 8px 0 0; border-bottom: 0; }
.dpad .down { left: 33%; bottom: 0; border-radius: 0 0 8px 8px; border-top: 0; }
.dpad .left { top: 33%; left: 0; border-radius: 8px 0 0 8px; border-right: 0; }
.dpad .right { top: 33%; right: 0; border-radius: 0 8px 8px 0; border-left: 0; }
.dpad .hub { position: absolute; left: 33%; top: 33%; width: 34%; height: 34%; background: rgba(60, 55, 48, .85); }
.dpad .arm::after { content: ""; position: absolute; inset: 0; margin: auto; width: 0; height: 0; border: 7px solid transparent; }
.dpad .up::after { border-bottom-color: #aaa; border-top-width: 0; }
.dpad .down::after { border-top-color: #aaa; border-bottom-width: 0; }
.dpad .left::after { border-right-color: #aaa; border-left-width: 0; }
.dpad .right::after { border-left-color: #aaa; border-right-width: 0; }
.face { width: calc(170px * var(--pad-scale)); height: calc(170px * var(--pad-scale)); }
.face button { width: 36%; height: 36%; font-size: calc(26px * var(--pad-scale)); }
#pad .face .tri { left: 32%; top: 0; color: #6fd6b0; }
#pad .face .cir { right: 0; top: 32%; color: #ff7c7c; }
#pad .face .crs { left: 32%; bottom: 0; color: #8fb2ff; }
#pad .face .sqr { left: 0; top: 32%; color: #f0a0dc; }
.shoulder { position: absolute; display: flex; gap: 8px; }
#pad .shoulder button { position: static; width: calc(64px * var(--pad-scale)); height: calc(36px * var(--pad-scale)); border-radius: 10px; font-size: 14px; }
.mid { position: absolute; display: flex; gap: 12px; }
#pad .mid button { position: static; width: calc(70px * var(--pad-scale)); height: calc(28px * var(--pad-scale)); border-radius: 14px; font-size: 11px; letter-spacing: .05em; }
#pad .mid button.ff-btn { width: calc(52px * var(--pad-scale)); pointer-events: auto; font-weight: 700; letter-spacing: .04em; }
#pad .mid button.ff-btn.on { background: rgba(230, 184, 74, .92); border-color: var(--accent); color: #111; opacity: 1; }
body.nopad #pad, body.nopad #hint { display: none; }

/* Mobile portrait: picture on top, pad below */
@media (orientation: portrait) {
  body:not(.desktop) #workspace { flex: 0 0 auto; }
  body:not(.desktop) #stage { flex: 0 0 auto; }
  body:not(.desktop) #screen {
    --pic-h: min(56vh, calc(100vh - 360px - var(--sat) - var(--sab)));
    height: auto; max-height: var(--pic-h); width: min(100vw, var(--pic-h) * 4 / 3);
  }
  .shoulder.left { left: calc(12px + var(--sal)); top: 8px; flex-direction: row; }
  .shoulder.right { right: calc(12px + var(--sar)); top: 8px; flex-direction: row; }
  .dpad { left: calc(14px + var(--sal)); top: calc(50% - 75px * var(--pad-scale) - 6px); }
  .face { right: calc(10px + var(--sar)); top: calc(50% - 85px * var(--pad-scale) - 6px); }
  .mid { left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--sab)); }
}

/* Mobile landscape: full-height picture with pad halves overlaid on sides */
@media (orientation: landscape) {
  body:not(.desktop) #app { display: block; }
  body:not(.desktop) #bar {
    position: absolute; top: 0; left: 0; right: 0;
    background: linear-gradient(rgba(0, 0, 0, .6), transparent);
  }
  body:not(.desktop) #workspace,
  body:not(.desktop) #stage { position: absolute; inset: 0; }
  body:not(.desktop) #screen { height: 100vh; height: 100dvh; width: auto; max-width: 100vw; }
  body:not(.desktop) #tap-sound { top: calc(var(--sat) + 50px); z-index: 7; }
  body:not(.desktop) #netwait { top: calc(var(--sat) + 50px); }
  body:not(.desktop) #toast { bottom: calc(58px + var(--sab)); pointer-events: none; }
  body:not(.desktop) #hint { position: absolute; top: calc(var(--sat) + 12px); left: 0; right: 0; pointer-events: none; z-index: 6; }
  body:not(.desktop) #pad { position: absolute; inset: 0; z-index: 2; }
  .shoulder.left { left: calc(10px + var(--sal)); top: calc(48px + var(--sat)); flex-direction: column; }
  .shoulder.right { right: calc(10px + var(--sar)); top: calc(48px + var(--sat)); flex-direction: column-reverse; }
  .dpad { left: calc(18px + var(--sal)); bottom: calc(28px + var(--sab)); }
  .face { right: calc(14px + var(--sar)); bottom: calc(22px + var(--sab)); }
  .mid { left: 50%; transform: translateX(-50%); bottom: calc(18px + var(--sab)); }
}

/* Desktop with forced touch pad */
body.desktop.forcepad #pad {
  position: absolute; inset: 0; z-index: 2; pointer-events: auto;
}

#haptic { position: fixed; left: -100px; top: -100px; width: 1px; height: 1px; overflow: hidden; opacity: 0; }

/* ---------------------------------------------------------------- menu sheet */
#sheet {
  position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .58);
  display: flex; justify-content: flex-start;
}
#sheet[hidden] { display: none; }
.sheet-inner {
  width: min(440px, 100vw); height: 100%; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: calc(var(--sat) + 12px) 14px calc(var(--sab) + 22px) calc(var(--sal) + 14px);
  -webkit-user-select: text; user-select: text; touch-action: pan-y; overscroll-behavior: contain;
}
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head b { color: var(--accent); font-size: 16px; }
.sheet-head #sheet-ver { flex: 1; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; margin: 10px 0 6px; }
.tabs button { flex: 1; padding: 7px 4px; background: transparent; }
.tabs button.on { background: #2a241c; border-color: var(--accent); color: var(--accent); }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list li {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
.list li img { width: 80px; height: 60px; object-fit: cover; border-radius: 4px; background: #000; flex: none; }
.list li .what { flex: 1; min-width: 0; font-size: 14px; }
.list li .what small { display: block; color: var(--muted); font-size: 12px; }
.list li button { flex: none; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
h4 { margin: 16px 0 4px; color: var(--accent); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.set { display: flex; align-items: center; gap: 10px; margin: 10px 0; cursor: pointer; }
.set input[type=range] { flex: 1; }
.set select {
  flex: 1; background: #0e0c09; color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px; font: inherit;
}
