:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2027;
  --line: #262c34;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4f9cff;
  --accent-2: #2b6fd1;
  --ok: #3ecf8e;
  --warn: #f1b24b;
  --bad: #ff5d6c;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* The hidden HTML attribute must always win, even when an element has an
   explicit display rule (flex, grid, etc.). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  overflow: hidden;
}

body {
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  max-width: 640px;
  margin: 0 auto;
  height: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  letter-spacing: 0.2px;
}

.status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.status[data-state="connecting"] { color: var(--warn); border-color: rgba(241,178,75,0.4); }
.status[data-state="waiting"]    { color: var(--accent); border-color: rgba(79,156,255,0.4); }
.status[data-state="connected"]  { color: var(--ok); border-color: rgba(62,207,142,0.4); }
.status[data-state="idle"]       { color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.hint.small { font-size: 12px; }

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

.link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  flex: 0 0 auto;
}
.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.dot[data-state="ok"]         { background: var(--ok); box-shadow: 0 0 0 4px rgba(62,207,142,0.18); }
.dot[data-state="connecting"] { background: var(--warn); }
.dot[data-state="warn"]       { background: var(--warn); }
.dot[data-state="bad"]        { background: var(--bad); }
.link-row .speed {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.link-row .speed:empty { display: none; }

.pin-display {
  flex: 0 0 auto;
  text-align: center;
}
.pin-display .hint { text-align: center; }
.big-pin {
  font-size: clamp(56px, 14vmin, 96px);
  font-weight: 700;
  letter-spacing: clamp(6px, 2vmin, 12px);
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  padding: 4px 0;
  line-height: 1;
}

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  background: var(--panel-2);
  transition: border-color 120ms ease, background 120ms ease;
  flex: 0 0 auto;
}
.dropzone.over {
  border-color: var(--accent);
  background: rgba(79,156,255,0.08);
}
.dropzone p { margin: 0; }

.receive-row {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.receive-row .hint { text-align: center; }

.pin-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.pin-input {
  flex: 1;
  font-size: 22px;
  letter-spacing: 4px;
  text-align: center;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  outline: none;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.pin-input:focus { border-color: var(--accent); }

button, .primary, .secondary, .file-pick {
  font: inherit;
  font-size: 15px;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 120ms ease, transform 60ms ease;
}
button:active, .primary:active, .secondary:active, .file-pick:active {
  transform: translateY(1px);
}
button.small { padding: 6px 10px; font-size: 13px; }

.primary, .file-pick {
  background: var(--accent);
  color: #fff;
}
.primary:hover, .file-pick:hover { background: var(--accent-2); }
.primary:disabled { opacity: 0.55; cursor: progress; }

.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.secondary:hover { background: #232932; }

.file-pick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.transfers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

.tr-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tr-row.queued .tr-bar { opacity: 0.4; }

.tr-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.tr-arrow {
  font-weight: 700;
  color: var(--muted);
}
.tr-row.send .tr-arrow { color: var(--accent); }
.tr-row.recv .tr-arrow { color: var(--ok); }
.tr-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tr-size {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.tr-bar {
  height: 5px;
  background: #0d1116;
  border-radius: 4px;
  overflow: hidden;
}
.tr-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6db3ff);
  transition: width 120ms linear;
}
.tr-row.done .tr-fill {
  background: linear-gradient(90deg, var(--ok), #6fe2af);
}
.tr-row.err .tr-fill { background: var(--bad); }
.tr-row.cancelled { opacity: 0.5; }

.actions {
  display: flex;
  gap: 8px;
  font-size: 13px;
}
.actions:empty { display: none; }
.save-btn {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.save-btn:hover { text-decoration: underline; }

.history-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.history-toggle {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  text-align: left;
}
.history-toggle:hover { color: var(--text); }
.history-toggle .caret {
  display: inline-block;
  transition: transform 120ms ease;
  font-size: 10px;
}
.history-toggle[aria-expanded="true"] .caret {
  transform: rotate(90deg);
}
.history-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  transition: background 100ms ease;
}
.hist-tap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 0;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
}
.hist-tap:hover { color: var(--accent); }
.hist-info-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hist-info-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}
.hist-icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: 4px;
  background: rgba(0,0,0,0.2);
  overflow: hidden;
}
.hist-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hist-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item.send .hist-name::before { content: "↑ "; color: var(--accent); }
.history-item.recv .hist-name::before { content: "↓ "; color: var(--ok); }
.hist-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.history-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.history-pager button:disabled { opacity: 0.3; cursor: default; }

.file-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 420px;
  width: 92%;
}
.file-dialog::backdrop {
  background: rgba(0,0,0,0.6);
}
.file-dialog-name {
  margin: 0 0 12px;
  font-size: 15px;
  word-break: break-all;
}
.file-dialog-details {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 12px;
  font-size: 13px;
}
.file-dialog-details dt { color: var(--muted); }
.file-dialog-details dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.file-dialog-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 16px; }
  .pin-form { flex-direction: row; }
  .pin-input { font-size: 24px; padding: 9px 10px; }
}
