:root {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #121c33;
  --line: rgba(186, 214, 255, 0.14);
  --text: #f8fafc;
  --muted: #94a3b8;
  --blue: #38bdf8;
  --blue-deep: #2563eb;
  --danger: #fecaca;
  font-family: Outfit, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(37, 99, 235, 0.28), transparent 60%),
    var(--bg);
  color: var(--text);
}

#home {
  width: min(440px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(24px, 8vh, 64px) 0 32px;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.logo {
  width: 64px;
  height: 64px;
  display: block;
  flex: none;
}

h1 {
  margin: 0;
  font-family: Fraunces, serif;
  font-size: clamp(32px, 12vw, 52px);
  font-weight: 560;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

form {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

label[hidden] { display: none; }

.saved-server {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b1220;
}

.saved-server[hidden] { display: none; }

.saved-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.saved-name {
  font-size: 16px;
  font-weight: 600;
}

.change {
  background: transparent;
  color: var(--blue);
  padding: 8px 4px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: 500 16px Outfit, sans-serif;
}

input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font: 600 15px Outfit, sans-serif;
  cursor: pointer;
}

#submit {
  background: linear-gradient(135deg, #38bdf8, #2563eb 55%, #4f46e5);
  color: #fff;
}

#submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

#session {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #070d18;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  user-select: none;
}

#session[hidden] { display: none; }

.session-bar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: #121c33;
  border-bottom: 1px solid var(--line);
}

#session-state {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#disconnect {
  flex: none;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

#stage {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

#stage iron-remote-desktop {
  display: block;
  width: 100%;
  height: 100%;
}

#touch-tools,
#keypad {
  background: #121c33;
  border-top: 1px solid var(--line);
}

#touch-tools[hidden],
#keypad[hidden] { display: none !important; }

#touch-tools {
  display: flex;
  gap: 6px;
  padding: 8px;
}

#touch-tools button {
  flex: 1 1 0;
  min-width: 0;
}

#touch-tools button[hidden] { display: none !important; }

#touch-tools button,
#keypad button {
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--line);
  min-height: 44px;
  padding: 8px 4px;
}

#keypad {
  display: grid;
  gap: 3px;
  padding: 4px 6px 6px;
}

#keypad button {
  min-height: 30px;
  padding: 2px;
  font-size: 12px;
  border-radius: 8px;
}

.key-page {
  display: grid;
  gap: 3px;
}

.key-page[hidden] { display: none !important; }

.key-row.fn button,
#keypad button.swap {
  min-height: 28px;
  font-size: 11px;
}

#local-cursor {
  position: fixed;
  z-index: 30;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #0b1220, 0 0 0 4px rgba(56, 189, 248, 0.45);
  pointer-events: none;
}

#local-cursor[hidden] { display: none !important; }

.key-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
}

#touch-tools button.on,
#keypad button.on {
  color: #fff;
  border-color: var(--blue);
  background: #1d4ed8;
}

@media (max-width: 640px) {
  #home { width: min(440px, calc(100% - 20px)); }
  .logo { width: 48px; height: 48px; }
  header { gap: 12px; margin-bottom: 18px; }
  .session-bar { height: 44px; padding: 0 10px; }
  #keypad button,
  #touch-tools button { font-size: 13px; }
}
