/* The remote: a well-loved silver cable remote. Everything is sized in em so
   one font-size scales the whole object for desktop, portrait and landscape.
   Wear comes from three texture layers (grain, scratches, grime) and a noise
   mask that rubs the printed labels thin in places. */

:root { --rfs: clamp(8px, 0.98vh, 12px); }

#remote {
  --peek: 5.4em;
  position: fixed;
  right: 18px;
  top: 50%;
  z-index: 30;
  font-size: var(--rfs);
  transform: translateY(-50%);
  transform-origin: 50% 0%;
  transition: opacity 0.4s, transform 0.65s cubic-bezier(.22,1,.36,1), filter 0.65s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* put down: the remote tips back and drops to the bottom edge, its top peeking */
body.remote-down #remote {
  transform: translateY(calc(50vh - var(--peek))) perspective(1100px) rotateX(28deg) scale(0.95);
  filter: brightness(0.9);
}
#remote-lift {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
body.remote-down #remote-lift { display: block; }

.rm {
  position: relative;
  width: 17.5em;
  padding: 3.3em 1.5em 1.4em;
  border-radius: 8.75em 8.75em 5.2em 5.2em / 6.8em 6.8em 3.6em 3.6em;
  background:
    linear-gradient(90deg, #6d7074 0%, #a9aaa9 7%, #d4d3cf 22%, #e6e5e0 44%, #dedcd6 58%, #c3c1bb 82%, #95979a 94%, #66696d 100%);
  box-shadow:
    0 0.35em 0.3em rgba(0,0,0,0.45),
    0 2.4em 3.4em rgba(0,0,0,0.6),
    inset 0 0 0 0.12em #5b5e62,
    inset 0 0.4em 0.45em rgba(255,255,255,0.55),
    inset 0.5em 0 0.8em rgba(255,255,255,0.14),
    inset -0.6em 0 0.9em rgba(0,0,0,0.22),
    inset 0 -0.7em 1em rgba(40,32,24,0.22);
  isolation: isolate;
}

/* grain + fine scratches */
.rm::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: -1;
  opacity: 0.55;
  mix-blend-mode: multiply;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='520' viewBox='0 0 220 520'%3E%3Cg stroke-linecap='round' fill='none'%3E%3Cpath d='M20 40 l60 14' stroke='%23000' stroke-opacity='.18' stroke-width='.6'/%3E%3Cpath d='M140 90 l52 -9' stroke='%23000' stroke-opacity='.14' stroke-width='.5'/%3E%3Cpath d='M30 160 l90 22' stroke='%23000' stroke-opacity='.12' stroke-width='.5'/%3E%3Cpath d='M160 210 l-40 30' stroke='%23000' stroke-opacity='.16' stroke-width='.6'/%3E%3Cpath d='M12 280 l38 -5' stroke='%23000' stroke-opacity='.2' stroke-width='.7'/%3E%3Cpath d='M110 330 l85 12' stroke='%23000' stroke-opacity='.12' stroke-width='.5'/%3E%3Cpath d='M40 400 l30 26' stroke='%23000' stroke-opacity='.15' stroke-width='.6'/%3E%3Cpath d='M150 450 l-70 18' stroke='%23000' stroke-opacity='.13' stroke-width='.5'/%3E%3Cpath d='M70 500 l60 -6' stroke='%23000' stroke-opacity='.18' stroke-width='.6'/%3E%3Cpath d='M190 20 l-30 40' stroke='%23000' stroke-opacity='.1' stroke-width='.4'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 100% 100% no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .42 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 180px 180px;
}

/* grime settles along the edges and toward the bottom where hands hold it */
.rm::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(120% 40% at 50% 100%, rgba(70,56,40,0.28), transparent 70%),
    radial-gradient(30% 90% at 0% 50%, rgba(60,50,38,0.22), transparent 70%),
    radial-gradient(30% 90% at 100% 50%, rgba(60,50,38,0.22), transparent 70%),
    radial-gradient(60% 12% at 50% 0%, rgba(255,255,255,0.35), transparent 70%);
}

.rm-ir {
  position: absolute;
  top: 0.85em;
  left: calc(50% - 1.7em);
  width: 3.4em;
  height: 0.95em;
  border-radius: 0.4em;
  background: radial-gradient(60% 80% at 40% 30%, #4a3036 0%, #1a0f12 60%, #0a0507 100%);
  box-shadow: inset 0 0.1em 0.2em rgba(0,0,0,0.9), 0 0.08em 0 rgba(255,255,255,0.6);
}

/* printed labels, rubbed thin in places */
.rm i,
.rm-brand {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5' numOctaves='3' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 -3 2.35'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5' numOctaves='3' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 -3 2.35'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E");
  -webkit-mask-size: 90px 90px;
  mask-size: 90px 90px;
}

.rm i {
  display: block;
  font-style: normal;
  font-family: 'Archivo', system-ui, sans-serif;
  font-weight: 800;
  font-size: 0.54em;
  letter-spacing: 0.08em;
  color: #3d4045;
  text-align: center;
  line-height: 1.15;
  margin: 0.5em 0 0;
  white-space: nowrap;
  text-shadow: 0 0.08em 0 rgba(255,255,255,0.5);
}

.k { display: flex; flex-direction: column; align-items: center; }
.k > i:first-child { margin: 0 0 0.45em; }

/* ---------- rubber buttons ---------- */

.b {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Archivo', system-ui, sans-serif;
  font-size: 1em;
  font-weight: 800;
  color: #e9e8e4;
  background: radial-gradient(ellipse 70% 60% at 50% 32%, #777a80 0%, #4b4e53 55%, #2d2f33 100%);
  box-shadow:
    0 0 0 0.15em rgba(28,24,20,0.5),
    0 0.22em 0 #151618,
    0 0.32em 0.4em rgba(0,0,0,0.35),
    inset 0 0.14em 0.12em rgba(255,255,255,0.22),
    inset 0 -0.2em 0.3em rgba(0,0,0,0.35);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.07s, box-shadow 0.07s, filter 0.07s;
}
/* the worn shine where thumbs have polished the rubber */
.b::before {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: 9%;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.22), rgba(255,255,255,0) 70%);
  pointer-events: none;
}
.b > span {
  position: relative;
  font-size: 0.6em;
  letter-spacing: 0.05em;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 -0.06em 0 rgba(0,0,0,0.5);
}
.b:active, .b.pressed {
  transform: translateY(0.16em);
  box-shadow:
    0 0 0 0.15em rgba(28,24,20,0.5),
    0 0.06em 0 #151618,
    0 0.1em 0.15em rgba(0,0,0,0.3),
    inset 0 0.14em 0.12em rgba(255,255,255,0.14),
    inset 0 -0.1em 0.2em rgba(0,0,0,0.3);
  filter: brightness(1.12);
}
.b:focus-visible { outline: 0.18em solid #ffd451; outline-offset: 0.18em; }

.b-oval { width: 2.8em; height: 1.8em; border-radius: 50%; }
.b-lbl > span { font-size: 0.48em; }

.b-power,
.b-red,
.dp-ok {
  color: #fff2ee;
  background: radial-gradient(ellipse 70% 60% at 50% 30%, #e4574b 0%, #b92c22 55%, #7c1812 100%);
  box-shadow:
    0 0 0 0.15em rgba(40,14,10,0.45),
    0 0.22em 0 #4f100b,
    0 0.32em 0.4em rgba(0,0,0,0.35),
    inset 0 0.14em 0.12em rgba(255,255,255,0.3),
    inset 0 -0.2em 0.3em rgba(0,0,0,0.3);
}
.b-power { width: 4.2em; height: 2.35em; border-radius: 50%; }
.b-power > span { font-size: 0.5em; }
.b-red { width: 3.7em; height: 2.05em; border-radius: 50%; }
.b-red > span { font-size: 0.5em; }
.b-sm { width: 3em; height: 1.75em; }

.b-sil {
  width: 3.4em;
  height: 2.05em;
  border-radius: 0.8em;
  background: radial-gradient(ellipse 70% 60% at 50% 30%, #8e9297 0%, #5d6166 55%, #3d4044 100%);
}
.b-sil > span { font-size: 0.7em; letter-spacing: -0.1em; }
.b-txt > span { font-size: 0.48em; letter-spacing: 0.05em; }

.b-abc { width: 2.4em; height: 2.4em; border-radius: 50%; }
.b-abc svg { position: relative; width: 1.1em; height: 1.1em; pointer-events: none; opacity: 0.92; }

.b-page { width: 2.4em; height: 3.1em; border-radius: 0.85em; }
.b-page > span { font-size: 0.75em; }

.b-num { width: 3.2em; height: 2.1em; border-radius: 50%; }
.b-num > span { font-size: 0.92em; font-weight: 800; }
.b-fn > span { font-size: 0.44em; }
#r-year.armed { background: radial-gradient(ellipse 70% 60% at 50% 30%, #f0b54a 0%, #b57a18 60%, #7c500b 100%); }

/* ---------- sections ---------- */

.rm-cap {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  column-gap: 0.3em;
}
.rm-cap .k-side { margin-bottom: 0.15em; }
.rm-cap .k-side:first-child { transform: rotate(-11deg) translateY(-0.2em); }
.rm-cap .k-side:last-child { transform: rotate(11deg) translateY(-0.2em); }

.rm-lcd { position: relative; width: 12.2em; margin: 1.2em auto 1.05em; }
.rm-lcd-tag {
  position: absolute;
  left: 50%;
  top: -0.6em;
  transform: translateX(-50%);
  z-index: 1;
  padding: 0.16em 0.7em;
  border-radius: 0.2em;
  background: #b9271e;
  color: #fff4f0;
  font: 800 0.48em/1.2 'Archivo', system-ui, sans-serif;
  letter-spacing: 0.14em;
  white-space: nowrap;
  box-shadow: 0 0.1em 0.15em rgba(0,0,0,0.3);
}
.rm-lcd-win {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65em 0.9em 0.4em;
  border-radius: 0.55em;
  background:
    linear-gradient(160deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 35%),
    linear-gradient(180deg, #0f1d14, #06100a);
  box-shadow:
    inset 0 0.18em 0.4em rgba(0,0,0,0.95),
    0 0 0 0.2em #2b2d31,
    0 0 0 0.3em rgba(255,255,255,0.35);
  font-family: 'Jersey 15', 'Archivo', sans-serif;
  font-size: 1.2em;
  letter-spacing: 0.06em;
}
#lcd-ch { color: #46ff7c; text-shadow: 0 0 0.4em rgba(70,255,124,0.7); }
#lcd-year { color: #ffb54a; text-shadow: 0 0 0.4em rgba(255,181,74,0.6); }

.rm-panel {
  border-radius: 1.05em;
  background: linear-gradient(180deg, #bdbcb7, #a9a9a5);
  box-shadow:
    inset 0 0.16em 0.35em rgba(0,0,0,0.4),
    inset 0 -0.1em 0.2em rgba(255,255,255,0.25),
    0 0.1em 0 rgba(255,255,255,0.65);
  padding: 0.85em 0.7em 0.7em;
}
.rm-transport {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  row-gap: 0.75em;
  column-gap: 0;
  justify-items: center;
}

/* Every three-across row shares one grid and one side inset, so the left,
   middle and right keys stack on the same center lines top to bottom. */
.rm-transport,
.rm-abc,
.rm-gm,
.rm-elh,
.rm-rockers,
.rm-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  align-items: center;
  padding-left: 0.7em;
  padding-right: 0.7em;
}

.rm-abc { margin: 1.05em 0 0.35em; }

.rm-nav {
  display: grid;
  grid-template-columns: 2.9em 1fr 2.9em;
  align-items: center;
  column-gap: 0.35em;
  margin: 0.2em 0 0;
}
.rm-nav .k-page { align-self: center; }

.rm-dpad {
  position: relative;
  width: 9em;
  height: 9em;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle, #d3d2cd 0 54%, #9d9d9a 56%, #bdbcb7 72%, #cfcec9 100%);
  box-shadow:
    inset 0 0.18em 0.4em rgba(0,0,0,0.35),
    0 0.12em 0 rgba(255,255,255,0.7);
}
.dp { position: absolute; }
.dp > span { font-size: 0.74em; }
.dp-up, .dp-down { left: calc(50% - 1.75em); width: 3.5em; height: 2.3em; }
.dp-up { top: 0.35em; border-radius: 1.55em 1.55em 0.6em 0.6em; }
.dp-down { bottom: 0.35em; border-radius: 0.6em 0.6em 1.55em 1.55em; }
.dp-left, .dp-right { top: calc(50% - 1.75em); width: 2.3em; height: 3.5em; }
.dp-left { left: 0.35em; border-radius: 1.55em 0.6em 0.6em 1.55em; }
.dp-right { right: 0.35em; border-radius: 0.6em 1.55em 1.55em 0.6em; }
.dp-ok {
  position: absolute;
  left: calc(50% - 1.85em);
  top: calc(50% - 1.85em);
  width: 3.7em;
  height: 3.7em;
  border-radius: 50%;
}
.dp-ok > span { font-size: 0.6em; display: flex; flex-direction: column; align-items: center; }
.dp-ok small { font-size: 0.6em; margin-top: 0.2em; letter-spacing: 0.06em; }

.rm-gm { margin: 0.85em 0 0; }
.rm-gm #r-guide { grid-column: 1; }
.rm-gm #r-menu { grid-column: 3; }
.rm-elh { margin: 0.9em 0 1.15em; }
.rk {
  width: 3.15em;
  height: 8.4em;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-radius: 1.35em;
  overflow: hidden;
  background: linear-gradient(90deg, #3f4247, #26282b 55%, #36393d);
  box-shadow:
    0 0 0 0.15em rgba(28,24,20,0.5),
    0 0.24em 0 #121315,
    0 0.35em 0.45em rgba(0,0,0,0.35),
    inset 0 0.14em 0.12em rgba(255,255,255,0.16);
}
.rk .b-rk {
  flex: 1;
  width: 100%;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.rk .b-rk::before { display: none; }
.rk .b-rk:active { background: rgba(255,255,255,0.1); transform: none; box-shadow: none; }
.rk .b-rk > span { font-size: 0.86em; }
.rk i {
  margin: 0;
  padding: 0.3em 0;
  color: #d4d3cf;
  font-size: 0.5em;
  text-shadow: none;
  border-top: 0.12em solid #16171a;
  border-bottom: 0.12em solid #16171a;
}
.rk-year i { color: #ffc766; }

.rm-mute { display: flex; justify-content: center; margin: 0.95em 0 1.1em; }

.rm-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  row-gap: 0.7em;
  column-gap: 0;
  justify-items: center;
  padding-top: 0.95em;
  padding-bottom: 0.95em;
  border-radius: 1.25em;
  background: linear-gradient(180deg, #c9c8c3, #b5b4af);
  box-shadow: inset 0 0.14em 0.3em rgba(0,0,0,0.3), 0 0.1em 0 rgba(255,255,255,0.6);
}

.rm-brand {
  margin-top: 1.15em;
  text-align: center;
  font: 900 1em/1 'Archivo', system-ui, sans-serif;
  letter-spacing: 0.03em;
  color: #2c2e32;
  text-shadow: 0 0.08em 0 rgba(255,255,255,0.45);
}
.rm-brand span { color: #b9271e; }

/* hide / show: a plainly labelled button beside the remote, readable at any size */
#remote-toggle {
  position: fixed;
  z-index: 31;
  right: 18px;
  bottom: 18px;
  width: calc(17.5 * var(--rfs));
  min-width: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  background: rgba(12, 12, 16, 0.74);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  color: #ecebe7;
  font: 700 13px/1 'Archivo', system-ui, sans-serif;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.3s, visibility 0.3s, background 0.2s;
}
#remote-toggle:hover { background: rgba(32, 32, 38, 0.88); }
#remote-toggle .rt-arrow {
  display: inline-block;
  color: #ffb54a;
  transition: transform 0.5s cubic-bezier(.22,1,.36,1);
}
/* once it's down, the peeking remote itself is the way back */
body.remote-down #remote-toggle { opacity: 0; visibility: hidden; pointer-events: none; }

/* ---------- desktop behaviour ---------- */
body.zoomed:not(.remote-down) #remote { opacity: 0.2; }
body.zoomed:not(.remote-down) #remote:hover { opacity: 1; }

#remote-tab { display: none; }

/* ---------- portrait: the phone is the remote, scrolling under the TV ---------- */
@media (max-aspect-ratio: 1 / 1) {
  #remote {
    --peek: 5.6em;
    top: var(--tv-bottom, 55vh);
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    transform-origin: 50% 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    font-size: min(4.3vw, 17px);
    padding: 1.4em 0 calc(env(safe-area-inset-bottom, 0px) + 2.5em);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 1.3em, #000 calc(100% - 2.2em), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 1.3em, #000 calc(100% - 2.2em), transparent 100%);
  }
  #remote .rm {
    margin: 0 auto;
    transform-origin: 50% 0%;
    transition: transform 0.65s cubic-bezier(.22,1,.36,1);
  }
  body.remote-down #remote {
    top: calc(100dvh - var(--peek) - env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    transform: none;
    filter: none;
    -webkit-mask-image: none;
    mask-image: none;
    transition: top 0.65s cubic-bezier(.22,1,.36,1);
  }
  body.remote-down #remote:hover { transform: none; }
  body.remote-down #remote .rm { transform: perspective(900px) rotateX(22deg) scale(0.96); }

  #remote-toggle {
    right: 12px;
    bottom: auto;
    top: calc(var(--tv-bottom, 55vh) - 46px);
    width: auto;
    min-width: 0;
    padding: 9px 13px;
    font-size: 12px;
  }
  body.zoomed #remote { opacity: 1; }
}

/* ---------- landscape phones: TV owns the screen, remote swings out ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  #remote {
    top: 0;
    bottom: 0;
    right: 0;
    transform: translateX(108%) perspective(900px) rotateY(-38deg);
    transform-origin: 100% 50%;
    transition: transform 0.55s cubic-bezier(.22,1,.36,1);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    font-size: 11px;
    padding: 1.2em calc(env(safe-area-inset-right, 0px) + 1em) 1.6em 1em;
    background: rgba(5, 4, 10, 0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  body.remote-open #remote { transform: none; }
  body.remote-down #remote,
  body.remote-down #remote:hover { transform: translateX(108%) perspective(900px) rotateY(-38deg); filter: none; }
  body.remote-down.remote-open #remote { transform: none; }
  #remote-lift { display: none !important; }
  #remote-toggle { display: none; }
  body.zoomed #remote { opacity: 1; }

  #remote-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: env(safe-area-inset-right, 0px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 29;
    width: 30px;
    height: 104px;
    border: 0;
    border-radius: 8px 0 0 8px;
    background: linear-gradient(90deg, #8f9398, #e3e5e8 55%, #c3c6ca);
    box-shadow: -4px 6px 16px rgba(0,0,0,0.5);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.25s, transform 0.35s;
  }
  #remote-tab span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font: 800 10px 'Archivo', system-ui, sans-serif;
    letter-spacing: 0.22em;
    color: #33373c;
  }
  body.remote-open #remote-tab { opacity: 0; pointer-events: none; transform: translateY(-50%) translateX(20px); }
}
