:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --card: #ffffff;
  --raised: #ffffff;
  --text: #000000;
  --muted: #6c6c70;
  --line: rgba(60, 60, 67, 0.2);
  --fill: rgba(120, 120, 128, 0.14);
  --accent: #007aff;
  --danger: #ff3b30;
  --ok: #248a3d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --raised: #2c2c2e;
    --text: #ffffff;
    --muted: #98989f;
    --line: rgba(84, 84, 88, 0.65);
    --fill: rgba(120, 120, 128, 0.3);
    --accent: #0a84ff;
    --danger: #ff453a;
    --ok: #30d158;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
}

h1 {
  margin: 20px 0 2px;
  font-size: 34px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.sub {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.mouse,
.pick {
  display: none;
}

.hint-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 16px;
}

.select-actions {
  display: flex;
  gap: 20px;
  margin-left: auto;
}

.select-actions button {
  /* Tall enough to tap without making the row taller */
  margin: -8px 0;
  padding: 10px 0;
}

.choosing .pick {
  display: inline;
}

@media (hover: hover) and (pointer: fine) {
  .mouse {
    display: inline;
  }

  .touch {
    display: none;
  }
}

.hint-row.choosing .touch,
.hint-row.choosing .mouse {
  display: none;
}

/* Devices */

.peers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  margin-top: 20px;
}

.peers:empty {
  display: none;
}

.peer {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 12px 4px;
  border: 0;
  border-radius: 14px;
  background: none;
  text-align: center;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.peer:active {
  transform: scale(0.96);
}

.peer.drop,
.peer:focus-visible {
  outline: none;
  background: var(--fill);
}

.avatar {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--fill);
  color: var(--accent);
}

.avatar svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.peer.drop .avatar,
.peer.chosen .avatar {
  background: var(--accent);
  color: #ffffff;
}

.avatar-wrap {
  position: relative;
}

/* Selection mark at the corner of each device while several are being chosen */
.tick {
  display: none;
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--bg);
  box-shadow: inset 0 0 0 1.5px var(--muted);
}

.peers.selecting .tick {
  display: grid;
}

.peer.chosen .tick {
  background: var(--accent);
  box-shadow: none;
}

.tick svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.peer.chosen .tick svg {
  opacity: 1;
}

.peer-name {
  max-width: 100%;
  margin-top: 8px;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.peer-kind {
  font-size: 13px;
  color: var(--muted);
}

/* Nobody here yet */

.empty {
  padding: 8px 16px 20px;
  text-align: center;
}

.empty-title {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.radar {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 20px auto 16px;
}

.radar i {
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  animation: radar 3s ease-out infinite;
}

.radar i:nth-child(2) {
  animation-delay: 1s;
}

.radar i:nth-child(3) {
  animation-delay: 2s;
}

@keyframes radar {
  from {
    transform: scale(0.2);
    opacity: 0.7;
  }

  to {
    transform: scale(1);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .radar i {
    animation: none;
    opacity: 0.3;
  }

  .radar i:nth-child(2) {
    transform: scale(0.66);
  }

  .radar i:nth-child(3) {
    transform: scale(0.33);
  }

  .peer,
  .bar-fill {
    transition: none;
  }
}

/* Transfers */

.card,
.invite {
  margin-top: 12px;
  border-radius: 14px;
  background: var(--card);
}

.card {
  padding: 14px 16px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.card-who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.card-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* How a transfer travels: straight between the devices, or through the server.
   The label says it; the dot's colour only reinforces it. */
.route {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 7px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.route::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.route[data-route='direct']::before {
  background: var(--ok);
}

.route[data-route='blocked']::before {
  background: var(--danger);
}

.alert-body .route {
  margin-top: 12px;
}

.card-files,
.card-status {
  font-size: 15px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.card-status {
  font-variant-numeric: tabular-nums;
}

.card[data-status='done'] .card-status {
  color: var(--ok);
}

.card[data-status='declined'] .card-status,
.card[data-status='failed'] .card-status {
  color: var(--danger);
}

.bar {
  height: 6px;
  margin: 10px 0 8px;
  border-radius: 3px;
  background: var(--fill);
  overflow: hidden;
}

.bar-fill {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.2s linear;
}

.card[data-status='done'] .bar-fill {
  background: var(--ok);
}

.send-chosen {
  min-height: 50px;
  margin-top: 16px;
}

.send-chosen:disabled {
  opacity: 0.4;
  cursor: default;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
}

.card-cancel {
  flex: none;
  /* Larger hit area than the text alone */
  margin: -12px -8px;
  padding: 12px 8px;
}

.card-save,
.send-chosen {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Add a device */

.invite summary {
  min-height: 44px;
  padding: 11px 16px;
  color: var(--accent);
  cursor: pointer;
}

.invite-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 4px 16px 16px;
}

.qr {
  flex: none;
  width: 168px;
  margin: 0 auto;
  padding: 10px;
  border-radius: 12px;
  /* Always black on white so cameras can read it in dark mode too */
  background: #ffffff;
  line-height: 0;
}

.qr:empty {
  display: none;
}

.invite-text {
  flex: 1 1 220px;
  font-size: 15px;
}

.invite-text p {
  margin: 0 0 8px;
  color: var(--muted);
}

.urls {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.urls button {
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  text-align: left;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}

.urls button[aria-pressed='true'] {
  color: var(--text);
  font-weight: 600;
}

.code {
  margin: 4px 0 14px;
  font: 600 28px/1.2 ui-monospace, 'SF Mono', Menlo, monospace;
  letter-spacing: 0.06em;
  user-select: all;
  -webkit-user-select: all;
}

.join label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

.join-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.join input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--fill);
  color: var(--text);
  /* 17px keeps iOS from zooming the page when the field is focused */
  font: 17px ui-monospace, 'SF Mono', Menlo, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.join input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.join button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

#new-code {
  min-height: 32px;
}

/* Footer and messages */

footer {
  padding: 12px 16px 16px;
  font-size: 15px;
  color: var(--muted);
  text-align: center;
}

footer .link {
  font-weight: 600;
}

.notice {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 56px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  text-align: center;
}

.offscreen {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Incoming offer */

dialog.alert {
  width: min(290px, calc(100vw - 48px));
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--raised);
  color: var(--text);
  text-align: center;
  overflow: hidden;
}

dialog.alert::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.alert-body {
  padding: 20px 16px 18px;
}

.alert-title {
  margin: 12px 0 4px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.alert-text {
  margin: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.alert-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 0.5px solid var(--line);
}

.alert-actions button {
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--accent);
}

.alert-actions button + button {
  border-left: 0.5px solid var(--line);
  font-weight: 600;
}

.alert-actions button:active {
  background: var(--fill);
}
