/* =====================================================================
   Googline phone-side join page.
   Mobile-first. Dark mode. Safe-area aware. Designed for one-hand use.
===================================================================== */

:root {
  color-scheme: light dark;
  --blue: #4285f4;
  --red: #ea4335;
  --yellow: #fbbc05;
  --green: #34a853;

  --ink: #0c1428;
  --muted: #4d5b75;
  --soft: #f3f6fb;
  --line: rgba(40, 55, 85, 0.1);
  --panel: rgba(255, 255, 255, 0.72);
  --panel-deep: rgba(255, 255, 255, 0.94);
  --shadow: 0 16px 40px rgba(61, 86, 122, 0.12);
  --shadow-soft: 0 6px 18px rgba(61, 86, 122, 0.08);
  --radius: 18px;
  --radius-lg: 22px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-inline: env(safe-area-inset-left, 0px);

  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f3f6fc;
    --muted: #a9b6cb;
    --soft: #1a2030;
    --line: rgba(255, 255, 255, 0.1);
    --panel: rgba(28, 36, 54, 0.72);
    --panel-deep: rgba(28, 36, 54, 0.96);
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.32);
  }
}

* { box-sizing: border-box; }
*:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

html, body { min-height: 100vh; min-height: 100dvh; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 6%, rgba(66, 133, 244, 0.22), transparent 32%),
    radial-gradient(circle at 92% 12%, rgba(234, 67, 53, 0.14), transparent 30%),
    radial-gradient(circle at 12% 96%, rgba(251, 188, 5, 0.18), transparent 30%),
    radial-gradient(circle at 92% 90%, rgba(52, 168, 83, 0.16), transparent 30%),
    linear-gradient(180deg, #f8fbff 0%, #eef6ff 60%, #eafaf3 100%);
}

@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(circle at 12% 6%, rgba(66, 133, 244, 0.18), transparent 34%),
      radial-gradient(circle at 92% 12%, rgba(234, 67, 53, 0.12), transparent 30%),
      radial-gradient(circle at 92% 90%, rgba(52, 168, 83, 0.12), transparent 30%),
      linear-gradient(180deg, #0d1320 0%, #131a2a 100%);
  }
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

[hidden], .hidden { display: none !important; }

.noscript-fallback {
  width: min(420px, 100% - 32px);
  margin: 80px auto;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--panel);
  text-align: center;
}

/* =====================================================================
   Shell — vertical stack with safe-area padding.
===================================================================== */
.shell {
  display: grid;
  gap: 14px;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: max(14px, var(--safe-top)) max(14px, var(--safe-inline)) calc(28px + var(--safe-bottom));
}

/* =====================================================================
   Topbar — branding + language picker.
===================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 900;
  font-size: 18px;
}

.brand-mark {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-deep);
  box-shadow: var(--shadow-soft);
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 14px;
  background: conic-gradient(from 0deg, var(--blue), var(--red), var(--yellow), var(--green), var(--blue));
  filter: blur(8px);
  opacity: 0;
  z-index: -1;
  transition: opacity 200ms ease;
}
.brand:hover .brand-mark::after { opacity: 0.45; }

.brand-mark .dot { border-radius: 999px; }
.dot.blue { background: var(--blue); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }

.locale-picker {
  position: relative;
  display: inline-grid;
}

.locale-picker select {
  appearance: none;
  min-height: 40px;
  padding: 0 32px 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

[dir="rtl"] .locale-picker select { padding: 0 14px 0 32px; }

.locale-picker::after {
  content: "";
  position: absolute;
  top: 50%;
  inset-inline-end: 14px;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
  opacity: 0.6;
}

/* =====================================================================
   State card — large, color-coded connection status.
   data-state in: idle | connecting | connected | retrying | expired | blocked
===================================================================== */
.state-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.state-card .state-actions {
  grid-column: 1 / -1;
}

.state-card .state-action {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  margin-top: 4px;
  color: white;
  font-weight: 800;
  background: linear-gradient(90deg, var(--blue), var(--green));
  cursor: pointer;
}

.state-indicator {
  position: relative;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
}

.state-pulse {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--blue);
  opacity: 0.18;
  animation: pulse 1.6s ease-out infinite;
}

.state-pulse.offset { animation-delay: 0.8s; }

@keyframes pulse {
  0% { transform: scale(0.6); opacity: 0.32; }
  100% { transform: scale(1.4); opacity: 0; }
}

.state-indicator::before {
  content: "";
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--blue);
  box-shadow: 0 0 0 6px rgba(66, 133, 244, 0.16);
}

.state-card[data-state="connected"] .state-pulse { animation: none; opacity: 0; }
.state-card[data-state="connected"] .state-indicator::before {
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(52, 168, 83, 0.18);
}

.state-card[data-state="retrying"] .state-pulse { background: var(--yellow); opacity: 0.24; }
.state-card[data-state="retrying"] .state-indicator::before {
  background: var(--yellow);
  box-shadow: 0 0 0 6px rgba(251, 188, 5, 0.22);
}

.state-card[data-state="expired"] .state-pulse,
.state-card[data-state="blocked"] .state-pulse { animation: none; opacity: 0; }

.state-card[data-state="expired"] .state-indicator::before,
.state-card[data-state="blocked"] .state-indicator::before {
  background: var(--red);
  box-shadow: 0 0 0 6px rgba(234, 67, 53, 0.18);
}

.state-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.state-copy strong {
  font-size: 16px;
  font-weight: 900;
}

.state-copy span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

/* =====================================================================
   Session card — token + host device.
===================================================================== */
.session-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.session-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
}

.session-card-row > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.session-card-row strong {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.5px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

.host-device {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(66, 133, 244, 0.16), rgba(52, 168, 83, 0.10));
  border: 1px solid rgba(66, 133, 244, 0.22);
  color: #0f3d80;
  font-size: 13px;
  font-weight: 800;
}

[dir="rtl"] .host-device { padding: 4px 4px 4px 12px; }

@media (prefers-color-scheme: dark) {
  .host-device {
    color: #ffffff;
    background: linear-gradient(90deg, rgba(66, 133, 244, 0.32), rgba(52, 168, 83, 0.22));
    border-color: rgba(66, 133, 244, 0.4);
  }
}

.host-device .device-tag {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 900;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--green));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2), var(--shadow-soft);
}

/* =====================================================================
   Roster card — list of all devices in the session.
===================================================================== */
.roster-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.roster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 28px;
  padding: 0 4px;
}

.roster-head strong {
  font-size: 14px;
  font-weight: 800;
}

.roster-count {
  min-width: 26px;
  min-height: 26px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: #0f6f3f;
  background: rgba(52, 168, 83, 0.16);
  font-size: 12px;
  font-weight: 900;
}

.roster-list {
  display: grid;
  gap: 6px;
}

.roster-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 8px;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  min-height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.32);
  border: 1px solid var(--line);
}

@media (prefers-color-scheme: dark) {
  .roster-row { background: rgba(255, 255, 255, 0.04); }
}

.roster-row.self {
  background: rgba(66, 133, 244, 0.1);
}

.peer-icon,
.device-tag {
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0;
  color: white;
  background: linear-gradient(135deg, var(--blue), #1a4a96);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), var(--shadow-soft);
}

.peer-icon { width: 30px; height: 30px; border-radius: 9px; font-size: 11px; }

.peer-icon.ios, .peer-icon.mac,
.device-tag.ios, .device-tag.mac {
  color: white;
  background: linear-gradient(135deg, #313746, #5a6678);
}

.peer-icon.android,
.device-tag.android {
  color: white;
  background: linear-gradient(135deg, var(--green), #1f7a3f);
}

.peer-icon.windows,
.device-tag.windows {
  color: white;
  background: linear-gradient(135deg, var(--blue), #1a4a96);
}

.peer-icon.linux,
.device-tag.linux {
  color: #2a1d00;
  background: linear-gradient(135deg, var(--yellow), #d99a00);
}

.peer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
  font-size: 14px;
}

.peer-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.roster-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(150, 162, 184, 0.4);
}

.roster-row.connected .roster-dot { background: var(--green); }

/* =====================================================================
   Picker — large tap target, photo/file chooser.
===================================================================== */
.picker {
  position: relative;
  display: grid;
  gap: 6px;
  justify-items: center;
  align-items: center;
  padding: 22px 18px;
  min-height: 132px;
  border-radius: var(--radius-lg);
  border: 1.5px dashed rgba(66, 133, 244, 0.4);
  background:
    linear-gradient(135deg, rgba(66, 133, 244, 0.1), rgba(52, 168, 83, 0.06)),
    var(--panel);
  text-align: center;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
  -webkit-tap-highlight-color: rgba(66, 133, 244, 0.18);
}

.picker:active { transform: scale(0.99); }
.picker:focus-within { border-color: var(--blue); }

.picker input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.picker-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 14px;
  color: #1a4a96;
  background: linear-gradient(135deg, rgba(66, 133, 244, 0.18), rgba(52, 168, 83, 0.12));
  border: 1px solid rgba(66, 133, 244, 0.18);
  box-shadow: var(--shadow-soft);
}

@media (prefers-color-scheme: dark) {
  .picker-icon { color: #b9d2ff; background: rgba(66, 133, 244, 0.2); border-color: rgba(66, 133, 244, 0.3); }
}

.picker strong { font-size: 16px; font-weight: 800; }
.picker > span { color: var(--muted); font-size: 13px; line-height: 1.45; max-width: 320px; }

/* =====================================================================
   Files section.
===================================================================== */
.files-section { display: grid; gap: 10px; min-width: 0; }

.files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 0 4px;
}

.files-header h2 { margin: 0; font-size: 18px; font-weight: 900; }

.selected-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.selected-pill {
  min-width: 26px;
  min-height: 28px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: #12366f;
  font-weight: 900;
  font-size: 13px;
  background: rgba(66, 133, 244, 0.15);
}

@media (prefers-color-scheme: dark) {
  .selected-pill { color: #cad9ff; background: rgba(66, 133, 244, 0.22); }
}

.selected-tools button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.selected-save {
  color: white;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.selected-clear {
  color: #344155;
  background: rgba(100, 112, 132, 0.14);
}

@media (prefers-color-scheme: dark) {
  .selected-clear { color: #d4dbe6; background: rgba(255, 255, 255, 0.08); }
}

.files-empty {
  padding: 18px;
  margin: 0;
  border-radius: var(--radius);
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.32);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  .files-empty { background: rgba(255, 255, 255, 0.04); }
}

.file-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

@media (max-width: 360px) {
  .file-list { grid-template-columns: 1fr; gap: 12px; }
}

.file-card {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(40px, auto) auto;
  gap: 8px;
  padding: 8px;
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.file-card.save-attention {
  outline: 3px solid rgba(66, 133, 244, 0.55);
  outline-offset: 3px;
  animation: shake 600ms ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.preview {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 14px;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--green));
}

.preview.kind-image { background: linear-gradient(135deg, #4285f4, #34a853); }
.preview.kind-video { background: linear-gradient(135deg, #ea4335, #fbbc05); }
.preview.kind-audio { background: linear-gradient(135deg, #9c27b0, #4285f4); }
.preview.kind-archive { background: linear-gradient(135deg, #ff9800, #f44336); }
.preview.kind-pdf { background: linear-gradient(135deg, #ef5350, #c62828); }
.preview.kind-text { background: linear-gradient(135deg, #607d8b, #455a64); }
.preview.kind-doc { background: linear-gradient(135deg, #1976d2, #0d47a1); }
.preview.kind-file { background: linear-gradient(135deg, #607d8b, #34a853); }

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-fallback {
  display: grid;
  place-items: center;
  gap: 4px;
  text-align: center;
  font-weight: 900;
}

.preview-fallback .ext {
  font-size: 22px;
  letter-spacing: 0.5px;
}

.preview-fallback .label {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.86;
}

.file-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.file-name {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  overflow-wrap: anywhere;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.32;
  word-break: break-all;
}

.file-state {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.file-action {
  display: grid;
}

.file-action .save-button {
  min-height: 36px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  color: white;
  font-weight: 800;
  font-size: 13px;
  background: linear-gradient(90deg, var(--blue), var(--green));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.remove-file {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  z-index: 2;
  width: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  color: #9b2118;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-soft);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.select-file {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  z-index: 2;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.select-file input { position: absolute; opacity: 0; pointer-events: none; }

.select-file span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.select-file span::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 999px;
  transition: background 120ms ease;
}

.select-file input:checked + span::after { background: var(--blue); }

.own-badge {
  position: absolute;
  inset-inline-end: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 4px 8px;
  border-radius: 999px;
  color: #0f6f3f;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
}

.footer-note {
  margin-top: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 0 4px;
}

/* =====================================================================
   iOS save viewer (long-press save fallback).
===================================================================== */
.ios-save-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: auto;
  padding: max(12px, var(--safe-top)) max(12px, var(--safe-inline)) calc(20px + var(--safe-bottom));
  color: var(--ink);
  background: var(--soft);
}

.ios-save-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 8px 0;
  background: var(--soft);
}

.ios-save-bar > strong { font-size: 16px; font-weight: 900; }

.ios-save-bar > div { display: flex; gap: 8px; }

.ios-save-bar button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  color: white;
  font-weight: 800;
  font-size: 13px;
  background: linear-gradient(90deg, var(--blue), var(--green));
  cursor: pointer;
}

.ios-save-bar button:last-child {
  color: #344155;
  background: rgba(100, 112, 132, 0.14);
}

@media (prefers-color-scheme: dark) {
  .ios-save-bar button:last-child { color: #d4dbe6; background: rgba(255, 255, 255, 0.08); }
}

.ios-save-copy {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  color: #17396f;
  background: rgba(66, 133, 244, 0.12);
  line-height: 1.5;
  font-size: 14px;
}

@media (prefers-color-scheme: dark) {
  .ios-save-copy { color: #cad9ff; background: rgba(66, 133, 244, 0.18); }
}

.ios-save-images {
  display: grid;
  gap: 16px;
  padding-bottom: 24px;
}

.ios-save-images figure {
  margin: 0;
  display: grid;
  gap: 8px;
}

.ios-save-images img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  background: white;
  -webkit-touch-callout: default;
}

.ios-save-images figcaption {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-all;
  text-align: start;
}

.ios-save-images figure a {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  border-radius: 10px;
  color: white;
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

/* =====================================================================
   Responsive — tablet+.
===================================================================== */
@media (min-width: 600px) {
  .file-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .shell { width: min(640px, 100%); }
}
