/* Phone first (iPhone 390 to 430 px wide), light and dark from the system. */

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #000000;
  --muted: #6c6c70;
  --line: #d1d1d6;
  --accent: #2f6bff;
  --accent-text: #ffffff;
  --theirs: #e9e9eb;
  --theirs-text: #000000;
  --danger: #d70015;
  --note: #8e8e93;
  --banner: #fff4d6;
  --banner-text: #5c4400;
  --bar: rgba(249, 249, 249, 0.94);
  color-scheme: light;
}

/* The system decides; data-theme on <html> overrides it (a setting, and how screenshots show both). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #ffffff;
    --muted: #98989f;
    --line: #38383a;
    --accent: #3d7bff;
    --accent-text: #ffffff;
    --theirs: #262629;
    --theirs-text: #ffffff;
    --danger: #ff453a;
    --note: #8e8e93;
    --banner: #3a2f0b;
    --banner-text: #ffd66b;
    --bar: rgba(22, 22, 24, 0.94);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --text: #ffffff;
  --muted: #98989f;
  --line: #38383a;
  --accent: #3d7bff;
  --accent-text: #ffffff;
  --theirs: #262629;
  --theirs-text: #ffffff;
  --danger: #ff453a;
  --note: #8e8e93;
  --banner: #3a2f0b;
  --banner-text: #ffd66b;
  --bar: rgba(22, 22, 24, 0.94);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { height: 100%; }
.view { display: none; height: 100%; }
.app[data-view="loading"] .view-loading,
.app[data-view="unpaired"] .view-unpaired { display: flex; }
.app[data-view="thread"] .view-thread { display: flex; flex-direction: column; }

/* Loading and unpaired */

.view-loading, .view-unpaired {
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.pair-card { width: 100%; max-width: 360px; text-align: center; }
.pair-icon { width: 88px; height: 88px; border-radius: 20px; }
.view-loading .pair-icon { opacity: 0.6; }
.pair-card h1 { font-size: 28px; margin: 20px 0 8px; }
.muted { color: var(--muted); margin: 0 0 28px; }
.error { color: var(--danger); margin: 16px 0 0; }

.big-button {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 18px;
  font-weight: 600;
}
.big-button:disabled { opacity: 0.5; }

.text-button {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 10px 6px;
  min-height: 44px;
}
.text-button.strong { font-weight: 600; }
.text-button.danger { color: var(--danger); }

/* Bars */

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  background: var(--bar);
  border-bottom: 0.5px solid var(--line);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  flex: none;
}
.bar-side { width: 64px; display: flex; justify-content: flex-end; }
.bar-side:first-child { justify-content: flex-start; }
.bar-title { flex: 1; text-align: center; min-width: 0; padding-top: 6px; }
.bar-title h1, .bar-title h2 { font-size: 17px; font-weight: 600; margin: 0; }
.sub { font-size: 12px; color: var(--muted); margin: 1px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub.down { color: var(--danger); }
/* The time in "Your Mac has not answered since ..." must always show. */
#last-answered { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.3; }

.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner {
  flex: none;
  background: var(--banner);
  color: var(--banner-text);
  font-size: 14px;
  text-align: center;
  padding: 8px 16px;
}

/* Thread */

.thread {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
}

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.bubble {
  max-width: 78%;
  padding: 8px 13px;
  border-radius: 19px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.bubble.theirs, .bubble.in { align-self: flex-start; background: var(--theirs); color: var(--theirs-text); border-bottom-left-radius: 6px; }
.bubble.pending { opacity: 0.6; }
.bubble .meta { display: block; font-size: 11px; margin-top: 3px; opacity: 0.85; text-align: right; }

.note { align-self: center; color: var(--note); font-size: 13px; text-align: center; padding: 6px 12px; max-width: 90%; }

.working { display: inline-flex; gap: 5px; margin-top: 4px; padding: 13px 15px; }
.working .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite ease-in-out; }
.working .dot:nth-child(2) { animation-delay: 0.2s; }
.working .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .working .dot { animation: none; opacity: 0.7; } }

.flash {
  flex: none;
  margin: 0;
  padding: 8px 16px;
  font-size: 14px;
  text-align: center;
  color: var(--danger);
  background: var(--surface);
  border-top: 0.5px solid var(--line);
}

/* Composer: sticky at the bottom, above the home indicator. */

.composer {
  position: sticky;
  bottom: 0;
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--bar);
  border-top: 0.5px solid var(--line);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 9px 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px; /* 16px or more keeps iOS from zooming in */
  line-height: 1.3;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }

.send {
  flex: none;
  min-width: 76px;
  height: 44px;
  border: 0;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 14px;
}
.send:active { opacity: 0.8; }

/* Settings sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.group-title { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin: 24px 16px 6px; }
.group { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.group-foot { font-size: 13px; color: var(--muted); margin: 6px 16px 0; }

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  min-height: 48px;
  padding: 8px 16px;
  border-bottom: 0.5px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-label { flex: 1; min-width: 0; }
.row-note { font-size: 13px; color: var(--muted); }
/* A device: the name takes the whole row, the meta and Revoke sit beneath. */
.row.device { align-items: baseline; }
.row.device .row-label { flex: 1 1 100%; overflow-wrap: anywhere; }
.row.device .row-note { flex: 1 1 0; min-width: 0; }
.row.device .text-button { flex: none; }
.row.disabled .row-label { color: var(--muted); }

.row-button {
  flex: 1;
  text-align: left;
  background: none;
  border: 0;
  color: var(--accent);
  padding: 6px 0;
  min-height: 36px;
}
.row-button.danger { color: var(--danger); }
.row-button:disabled { color: var(--muted); }

.switch {
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--line);
  position: relative;
  opacity: 0.6;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
}

@media (min-width: 700px) {
  .view-thread, .sheet-body { max-width: 680px; margin: 0 auto; width: 100%; }
}
