:root {
  --room: #1a1821;
  --pad: #25222e;
  --key: #322e3d;
  --key-pressed: #4a4558;
  --ink: #f0ecf5;
  --muted: #aaa4b6;
  --glow: #ffc46b;
  --gutter: 16px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--room);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

#remote {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: max(var(--gutter), env(safe-area-inset-top)) var(--gutter) max(var(--gutter), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#pad {
  position: relative;
  flex: 1;
  min-height: 180px;
  border-radius: 36px;
  background: var(--pad);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

#glow {
  position: absolute;
  left: 0;
  top: 0;
  width: 260px;
  height: 260px;
  margin: -130px 0 0 -130px;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(255 196 107 / 0.38), rgb(255 196 107 / 0.1) 45%, transparent 70%);
  opacity: 0;
  transform: translate(var(--x, 0), var(--y, 0));
  transition: opacity 320ms ease-out;
  pointer-events: none;
  will-change: transform, opacity;
}

#pad.touching #glow {
  opacity: 1;
  transition-duration: 40ms;
}

/* Each move the Pi receives flashes the edge it moved toward. */
.edge {
  position: absolute;
  border-radius: 2px;
  background: var(--glow);
  opacity: 0;
  pointer-events: none;
}

.edge[data-move="up"],
.edge[data-move="down"] {
  left: 30%;
  right: 30%;
  height: 4px;
}

.edge[data-move="left"],
.edge[data-move="right"] {
  top: 30%;
  bottom: 30%;
  width: 4px;
}

.edge[data-move="up"] { top: 8px; }
.edge[data-move="down"] { bottom: 8px; }
.edge[data-move="left"] { left: 8px; }
.edge[data-move="right"] { right: 8px; }

#lamp {
  position: absolute;
  top: 18px;
  right: 20px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.45;
}

#remote[data-state="off"] #lamp,
#remote[data-state="waking"] #lamp,
#remote[data-state="disconnected"] #lamp {
  background: var(--glow);
  opacity: 1;
}

#status {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

#keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 76px);
  gap: 14px;
  justify-items: center;
}

.key {
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--key);
  color: var(--ink);
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: pointer;
  transition: background-color 160ms ease-out, transform 160ms ease-out;
}

.key.pressed {
  background: var(--key-pressed);
  transform: scale(0.95);
  transition-duration: 0ms;
}

.key svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.key svg .solid {
  fill: currentColor;
}

#volume {
  grid-column: 3;
  grid-row: 1 / span 2;
  width: 76px;
  border-radius: 38px;
  background: var(--key);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#volume .key {
  flex: 1;
  height: auto;
  width: 100%;
  border-radius: 0;
  background: transparent;
}

#volume .key.pressed {
  background: var(--key-pressed);
  transform: none;
}

:focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: 3px;
}

#pad:focus-visible {
  outline-offset: -3px;
}

#actions {
  display: flex;
  gap: 14px;
}

.action {
  height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 26px;
  background: var(--key);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: none;
  cursor: pointer;
  transition: background-color 160ms ease-out, color 160ms ease-out;
}

.action:active {
  background: var(--key-pressed);
  transition-duration: 0ms;
}

.action svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.action.round {
  width: 52px;
  padding: 0;
}

#open-keyboard {
  flex: 1;
}

/* The TV has a text box open. */
#open-keyboard.ready,
#open-keyboard.ready:active,
#voice.listening,
#voice.listening:active {
  background: var(--glow);
  color: var(--room);
}

/* Typing: the pad stays usable above, and the arrows sit right above the phone's keyboard. */
#remote.typing {
  position: fixed;
  top: var(--viewport-top, 0);
  left: 0;
  right: 0;
  height: var(--viewport-height, 100dvh);
  padding-bottom: 10px;
  gap: 10px;
}

#remote.typing #actions,
#remote.typing #keys {
  display: none;
}

#remote.typing #pad {
  min-height: 72px;
}

#typing {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#typing-row {
  display: flex;
  gap: 8px;
}

#field {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 26px;
  background: var(--pad);
  color: var(--ink);
  font: inherit;
  font-size: 17px; /* iPhones zoom the page when a text box is under 16px. */
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

#field::placeholder {
  color: var(--muted);
}

#typing-keys {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

#typing-keys .key {
  width: 100%;
  height: 52px;
  border-radius: 26px;
  font: inherit;
  font-size: 17px;
}

@media (max-height: 560px) {
  #keys {
    grid-template-rows: repeat(2, 60px);
    gap: 10px;
  }

  .key {
    width: 60px;
    height: 60px;
  }

  #volume {
    width: 60px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #glow,
  .key,
  .action {
    transition: none;
  }

  .key.pressed {
    transform: none;
  }
}
