/* the remote control. a dark plastic handset that floats over the page.
   desktop: a tall handset you can drag anywhere. phone: docked along the bottom. */

.remote {
  --body: #1c1c1f;
  --edge: #2c2c31;
  --key: #3b3b41;
  --key-hi: #4a4a52;
  --key-text: #e8e8e8;
  --u: 1px;

  position: fixed;
  right: 20px;
  bottom: calc(var(--row, 26px) * 2 + 12px);
  z-index: 50;
  width: 184px;
  padding: 10px 14px 14px;
  border-radius: 30px 30px 40px 40px;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255,255,255,0.07), transparent 60%),
    linear-gradient(180deg, #26262a, var(--body) 40%, #151517);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -2px 0 rgba(0,0,0,0.5),
    0 0 0 1px #000,
    0 18px 40px rgba(0,0,0,0.6);
  font-family: "Bedstead", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1;
  color: var(--key-text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: grid;
  gap: 10px;
  grid-template-areas: "grip" "top" "fn" "pad" "nav" "fast" "brand";
}
.remote[hidden] { display: none; }
.remote.is-placed { right: auto; bottom: auto; }
.remote.is-dragging { box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 0 0 1px #000, 0 26px 60px rgba(0,0,0,0.75); }

.remote__grip { grid-area: grip; height: 12px; cursor: grab; display: grid; place-items: center; touch-action: none; }
.remote.is-dragging .remote__grip { cursor: grabbing; }
.remote__grip span { width: 40px; height: 4px; border-radius: 2px; background: #45454c; }

.remote__top { grid-area: top; display: flex; gap: 8px; align-items: center; }
.remote__lcd {
  flex: 1;
  height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px #0b0b0c, inset 0 2px 6px rgba(0,0,0,0.9);
  color: var(--w, #fff);
  font-size: 16px;
  letter-spacing: 0.04em;
  white-space: nowrap; overflow: hidden;
}
.remote__lcd.is-typing { color: var(--y, #ff0); }
.remote__lcd.is-missing { color: var(--r, #f00); }
.remote__lcd.is-link { color: var(--c, #0ff); font-size: 13px; }

/* every key */
.rk {
  font: inherit;
  color: var(--key-text);
  background: linear-gradient(180deg, var(--key-hi), var(--key));
  border: 0;
  border-radius: 10px;
  min-height: 34px;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 2px 0 #0c0c0e, 0 3px 4px rgba(0,0,0,0.5);
  transition: transform 60ms, box-shadow 60ms, filter 60ms;
  -webkit-tap-highlight-color: transparent;
}
.rk:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 #0c0c0e; }
.rk:focus-visible { outline: 2px solid var(--y, #ff0); outline-offset: 2px; }
.rk:disabled { opacity: 0.35; cursor: default; }
.rk:hover:not(:disabled) { filter: brightness(1.15); }

.rk--small { width: 30px; min-height: 30px; border-radius: 50%; font-size: 15px; }

.remote__fn { grid-area: fn; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rk--fn { font-size: 10px; min-height: 26px; border-radius: 13px; letter-spacing: 0.02em; }
.rk--fn[data-act="reveal"] { color: var(--m, #f0f); }
.rk--fn[data-act="hold"] { color: var(--r, #f00); }
.rk--fn[data-act="mix"] { color: var(--c, #0ff); }

.remote__pad { grid-area: pad; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rk--num { font-size: 18px; min-height: 38px; border-radius: 50%; aspect-ratio: 1.15 / 1; }
.rk--pm { font-size: 13px; color: var(--y, #ff0); }

.remote__nav { grid-area: nav; display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 6px; align-items: center; }
.rk--nav { font: 15px/1 system-ui, -apple-system, "Segoe UI", sans-serif; }
.rk--ok { min-height: 40px; border-radius: 50%; font-size: 14px; color: var(--w, #fff);
  background: linear-gradient(180deg, #55555e, #3f3f46); }

.remote__fast { grid-area: fast; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rk--fast { min-height: 18px; border-radius: 9px; }
.rk--fast[data-fast="0"] { background: linear-gradient(180deg, #ff4a4a, #d00000); }
.rk--fast[data-fast="1"] { background: linear-gradient(180deg, #4dff4d, #00b800); }
.rk--fast[data-fast="2"] { background: linear-gradient(180deg, #ffff66, #d8d800); }
.rk--fast[data-fast="3"] { background: linear-gradient(180deg, #66ffff, #00c4c4); }

.remote__brand { grid-area: brand; text-align: center; font-size: 9px; letter-spacing: 0.25em; color: #6a6a72; padding-top: 2px; }

/* the tab that brings it back */
.remote-tab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--row, 26px) * 2 + 12px);
  z-index: 50;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 10px;
  border: 0; border-radius: 20px;
  background: linear-gradient(180deg, #2a2a2f, #18181a);
  box-shadow: 0 0 0 1px #000, 0 8px 20px rgba(0,0,0,0.6);
  color: #ddd;
  font: 12px/1 "Bedstead", ui-monospace, monospace;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.remote-tab[hidden] { display: none; }
.remote-tab:focus-visible { outline: 2px solid var(--y, #ff0); outline-offset: 2px; }
.remote-tab__dots {
  width: 14px; height: 14px; border-radius: 3px;
  background:
    radial-gradient(circle, #ff3030 2px, transparent 2.5px) 0 0 / 7px 7px,
    radial-gradient(circle, #ffff40 2px, transparent 2.5px) 7px 7px / 7px 7px no-repeat;
  background-color: #444;
}

/* the link the remote is pointing at */
.is-remote-focus { outline: none; background: var(--y, #ff0) !important; color: var(--k, #000) !important; }
.ttimg__reveal.is-remote-focus { box-shadow: 0 0 0 2px var(--y, #ff0); }

/* ---- phone: docked to the bottom, wider and shorter ---- */
@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) {
  .remote {
    left: 0; right: 0; bottom: 0; top: auto;
    width: auto;
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    gap: 8px;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "top   top"
      "fn    fn"
      "pad   pad"
      "nav   fast";
    font-size: 12px;
  }
  .remote__grip, .remote__brand { display: none; }
  .remote__top { min-width: 0; }
  .remote__lcd { height: 34px; }
  .remote__fn { grid-template-columns: repeat(6, 1fr); gap: 5px; }
  .rk--fn { padding: 0 2px; min-height: 34px; border-radius: 17px; font-size: 10px; }

  /* digits in two rows of five, with P− and P+ on the ends */
  .remote__pad { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .rk--num { aspect-ratio: auto; min-height: 44px; border-radius: 12px; }
  .remote__pad > :nth-child(1)  { order: 1; }
  .remote__pad > :nth-child(2)  { order: 2; }
  .remote__pad > :nth-child(3)  { order: 3; }
  .remote__pad > :nth-child(4)  { order: 4; }
  .remote__pad > :nth-child(5)  { order: 5; }
  .remote__pad > [data-act="prev"] { order: 6; }
  .remote__pad > :nth-child(6)  { order: 7; }
  .remote__pad > :nth-child(7)  { order: 8; }
  .remote__pad > :nth-child(8)  { order: 9; }
  .remote__pad > :nth-child(9)  { order: 10; }
  .remote__pad > [data-num="0"] { order: 11; }
  .remote__pad > [data-act="next"] { order: 12; }

  .remote__nav { grid-template-columns: repeat(3, 52px); }
  .rk--nav, .rk--ok { min-height: 44px; border-radius: 12px; }
  .remote__fast { align-self: stretch; }
  .rk--fast { min-height: 44px; min-width: 40px; border-radius: 12px; }

  .remote-tab { right: 12px; bottom: calc(var(--row, 26px) * 2 + 10px + env(safe-area-inset-bottom, 0px)); }

  /* while it's out, the remote carries the coloured keys, so the bar steps aside
     and the page gets room to scroll clear of the handset */
  html.remote-open body { padding-bottom: calc(270px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  .rk { transition: none; }
}
