/* ============================================================
   P2P Share — design system
   ============================================================ */

:root {
  /* Brand */
  --accent: #2162ff;
  --accent-strong: #1548c3;
  --accent-soft: rgba(33, 98, 255, 0.12);
  --accent-contrast: #ffffff;

  /* Light theme surfaces */
  --bg: #eef3fc;
  --bg-grad-a: #f5f8ff;
  --bg-grad-b: #dde8fb;
  --surface: #ffffff;
  --surface-2: #f4f7fe;
  --surface-3: #eaf0fd;
  --border: #dbe3f2;
  --border-strong: #c4d0e8;

  /* Text */
  --text: #111b2e;
  --muted: #5a6a86;
  --faint: #8a97ae;

  /* Feedback */
  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, 0.12);
  --success: #12875a;
  --success-soft: rgba(18, 135, 90, 0.14);
  --warn: #b7791f;

  /* Shape & motion */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;
  --shadow-sm: 0 2px 6px rgba(17, 27, 46, 0.06);
  --shadow: 0 16px 40px rgba(17, 27, 46, 0.12);
  --shadow-pop: 0 20px 55px rgba(17, 27, 46, 0.22);
  --ring: 0 0 0 3px var(--accent-soft);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --qr-fg: #111b2e;
  --qr-bg: #ffffff;

  color-scheme: light;
}

/* Dark tokens, shared by manual toggle and system preference */
[data-theme="dark"] {
  --accent: #5b8bff;
  --accent-strong: #7aa2ff;
  --accent-soft: rgba(91, 139, 255, 0.16);
  --accent-contrast: #0a1020;

  --bg: #070b14;
  --bg-grad-a: #0c1424;
  --bg-grad-b: #070b14;
  --surface: #121a2b;
  --surface-2: #17203444;
  --surface-3: #1b2740;
  --border: #243149;
  --border-strong: #32425f;

  --text: #eaf0fb;
  --muted: #9fb0cc;
  --faint: #6f809e;

  --danger: #ff6b5e;
  --danger-soft: rgba(255, 107, 94, 0.16);
  --success: #45d69f;
  --success-soft: rgba(69, 214, 159, 0.16);
  --warn: #e0b04a;

  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 22px 60px rgba(0, 0, 0, 0.6);

  --qr-fg: #eaf0fb;
  --qr-bg: #121a2b;

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #5b8bff;
    --accent-strong: #7aa2ff;
    --accent-soft: rgba(91, 139, 255, 0.16);
    --accent-contrast: #0a1020;

    --bg: #070b14;
    --bg-grad-a: #0c1424;
    --bg-grad-b: #070b14;
    --surface: #121a2b;
    --surface-2: #172034;
    --surface-3: #1b2740;
    --border: #243149;
    --border-strong: #32425f;

    --text: #eaf0fb;
    --muted: #9fb0cc;
    --faint: #6f809e;

    --danger: #ff6b5e;
    --danger-soft: rgba(255, 107, 94, 0.16);
    --success: #45d69f;
    --success-soft: rgba(69, 214, 159, 0.16);
    --warn: #e0b04a;

    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
    --shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
    --shadow-pop: 0 22px 60px rgba(0, 0, 0, 0.6);

    --qr-fg: #eaf0fb;
    --qr-bg: #121a2b;

    color-scheme: dark;
  }
}

/* ---------- reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 12% -8%, var(--accent-soft), transparent 60%),
    linear-gradient(160deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- layout ---------- */
.app {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: var(--shadow-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 1.02rem;
}

.brand-tag {
  font-size: 0.76rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* connection pill */
.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 0 currentColor;
}

.conn-pill[data-state="connecting"] {
  color: var(--warn);
}
.conn-pill[data-state="connecting"] .conn-dot {
  background: var(--warn);
  animation: pulse 1.3s var(--ease) infinite;
}
.conn-pill[data-state="connected"] {
  color: var(--success);
  border-color: var(--success-soft);
}
.conn-pill[data-state="connected"] .conn-dot {
  background: var(--success);
}
.conn-pill[data-state="error"] {
  color: var(--danger);
  border-color: var(--danger-soft);
}
.conn-pill[data-state="error"] .conn-dot {
  background: var(--danger);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), transform 0.12s var(--ease),
    box-shadow 0.18s var(--ease), border-color 0.18s var(--ease), color 0.18s var(--ease);
}

.btn.primary {
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 10px 24px -8px var(--accent);
}
.btn.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px -8px var(--accent);
}
.btn.primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn.ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn.ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.btn.small {
  padding: 8px 12px;
  font-size: 0.85rem;
  border-radius: 9px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease),
    transform 0.12s var(--ease), color 0.18s var(--ease);
}
.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}
.icon-btn:active {
  transform: scale(0.94);
}
.icon-btn.ghost {
  border-color: transparent;
  background: transparent;
  width: 34px;
  height: 34px;
  color: var(--muted);
}
.icon-btn.ghost:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* theme toggle icon swap */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

/* ---------- hero ---------- */
.hero {
  margin-bottom: 20px;
}
.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.55rem, 5vw, 2.15rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.subtitle {
  margin: 0;
  max-width: 48ch;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.5;
}

/* ---------- tabs ---------- */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 5px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s var(--ease);
}
.tab.is-active {
  color: var(--accent-contrast);
}
.tab-indicator {
  position: absolute;
  z-index: 0;
  top: 5px;
  left: 5px;
  width: calc(50% - 7px);
  height: calc(100% - 10px);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 18px -8px var(--accent);
  transition: transform 0.28s var(--ease);
}
.tabs[data-active="receive"] .tab-indicator {
  transform: translateX(calc(100% + 4px));
}

/* ---------- card / panel ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.panel {
  padding: 22px;
  display: grid;
  gap: 16px;
  animation: rise 0.35s var(--ease);
}
.panel[hidden] {
  display: none;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head h2 {
  margin: 0 0 4px;
  font-size: 1.18rem;
  font-weight: 700;
}
.panel-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- dropzone ---------- */
.dropzone {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 30px 20px;
  text-align: center;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease),
    transform 0.12s var(--ease);
}
.dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}
.dropzone-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 16px;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 4px;
}
.dropzone-title {
  font-weight: 600;
  font-size: 1rem;
}
.link-text {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.dropzone-hint {
  font-size: 0.82rem;
  color: var(--faint);
}

/* ---------- file chip ---------- */
.file-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  animation: rise 0.25s var(--ease);
}
.file-chip[hidden] {
  display: none;
}
.file-chip.success {
  border-color: var(--success-soft);
  background: var(--success-soft);
}
.file-chip-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 11px;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
}
.file-chip.success .file-chip-icon {
  color: var(--success);
}
.file-chip-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}
.file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---------- share section ---------- */
.share {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  animation: rise 0.3s var(--ease);
}
.share[hidden] {
  display: none;
}
.share-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 8px;
}
.share-pin {
  display: grid;
  gap: 12px;
  justify-items: start;
}
.pin-display {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pin-digit {
  display: grid;
  place-items: center;
  width: 46px;
  height: 56px;
  border-radius: 12px;
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent-strong);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.share-qr {
  display: grid;
  justify-items: center;
  gap: 8px;
}
.qr-box {
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: var(--radius);
  background: #ffffff; /* QR stays dark-on-white for reliable scanning in any theme */
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.qr-box svg,
.qr-box canvas {
  display: block;
  width: 168px;
  height: 168px;
}
.qr-hint {
  font-size: 0.8rem;
  color: var(--faint);
}

.link-row {
  display: flex;
  gap: 8px;
}
.link-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font: inherit;
  font-size: 0.86rem;
  color: var(--muted);
  background: var(--surface);
}
.link-input:focus-visible {
  border-color: var(--accent);
}

/* ---------- PIN entry ---------- */
.pin-inputs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.pin-box {
  width: 100%;
  aspect-ratio: 3 / 4;
  text-align: center;
  font-size: clamp(1.4rem, 7vw, 1.9rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease),
    background-color 0.15s var(--ease);
}
.pin-box:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--ring);
}
.pin-box.filled {
  border-color: var(--accent);
  color: var(--accent-strong);
}

/* ---------- transfer progress ---------- */
.transfer {
  display: grid;
  gap: 8px;
  animation: rise 0.25s var(--ease);
}
.transfer[hidden] {
  display: none;
}
.transfer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.transfer-file {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.transfer-percent {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-strong);
}
.bar {
  position: relative;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.25s var(--ease);
}
.bar-fill.indeterminate {
  width: 35% !important;
  animation: indeterminate 1.1s var(--ease) infinite;
}
@keyframes indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

/* ---------- status ---------- */
.status {
  margin: 0;
  min-height: 20px;
  font-size: 0.9rem;
  color: var(--muted);
}
.status.error {
  color: var(--danger);
  font-weight: 600;
}
.status.success {
  color: var(--success);
  font-weight: 600;
}

/* ---------- footer ---------- */
.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
  color: var(--faint);
  font-size: 0.8rem;
}
.foot-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.foot-sep {
  opacity: 0.6;
}

/* ---------- toasts ---------- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  gap: 10px;
  width: min(420px, calc(100% - 28px));
  z-index: 50;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  pointer-events: auto;
  animation: toast-in 0.28s var(--ease);
}
.toast.leaving {
  animation: toast-out 0.25s var(--ease) forwards;
}
.toast-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 7px;
}
.toast.success .toast-icon { color: var(--success); background: var(--success-soft); }
.toast.error .toast-icon { color: var(--danger); background: var(--danger-soft); }
.toast.info .toast-icon { color: var(--accent); background: var(--accent-soft); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px) scale(0.98); }
}

/* ---------- responsive ---------- */
@media (max-width: 420px) {
  .panel { padding: 18px; }
  .pin-digit { width: 40px; height: 50px; font-size: 1.45rem; }
  .pin-inputs { gap: 6px; }
  .brand-tag { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
