:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #162033;
  --muted: #5c667a;
  --line: #d9dfeb;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --ready: #166534;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -moz-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
  user-select: none;
}

button,
input,
textarea {
  font: inherit;
}

input,
textarea {
  user-select: text;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 8px 12px;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.popup {
  width: 280px;
  min-height: 180px;
}

.popup-shell {
  padding: 18px;
}

.popup-shell h1,
.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.popup-shell p,
.topbar p,
.notes p {
  margin: 6px 0 0;
  color: var(--muted);
}

.popup-shell button,
#createRoom {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.popup-shell button:hover:not(:disabled),
#createRoom:hover:not(:disabled) {
  background: var(--accent-strong);
}

#sendFile {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

#sendFile:hover:not(:disabled) {
  background: #7f1d1d;
  border-color: #7f1d1d;
}

.app-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.status-pill {
  min-width: 96px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 7px 12px;
  text-align: center;
}

.status-pill.ready {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--ready);
}

.status-pill.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.connection-panel.collapsed .panel-head {
  margin-bottom: 0;
}

.connection-panel .panel-head h2 {
  flex: 0 0 auto;
}

.connection-panel .panel-head .header-status {
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.connection-panel .panel-head .header-status span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-panel .panel-head .header-status .countdown-text {
  flex: 0 0 auto;
}

.connection-panel.collapsed .panel-head .header-status {
  display: flex;
  justify-content: flex-end;
  text-align: right;
}

.connection-panel.collapsed .settings-options {
  display: none;
}

.connection-panel.collapsed #connectionPanelBody {
  display: none;
}

.connection-panel.collapsible .panel-head {
  cursor: pointer;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
}

.collapse-button {
  min-height: 32px;
  border-color: #cbd5e1;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
}

.collapse-button:hover {
  background: #eef6f5;
  color: var(--accent-strong);
}

.settings-options {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
  user-select: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.toggle-row input {
  accent-color: var(--accent);
}

.clipboard-panel {
  border-color: #cbd5e1;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.clipboard-panel .panel-head {
  margin-bottom: 10px;
}

.clipboard-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.clipboard-actions button {
  flex: 0 0 auto;
}

.clipboard-text {
  min-height: 82px;
  max-height: 150px;
  border-color: #cbd5e1;
  background: #fff;
  line-height: 1.55;
}

.clipboard-text:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.16);
  outline-offset: 1px;
}

.clipboard-text:read-only {
  background: #f8fafc;
  color: var(--muted);
  cursor: default;
}

.clipboard-panel .status-text {
  margin-top: 8px;
}

.secondary-button {
  min-height: 34px;
  border-color: #cbd5e1;
  background: #f8fafc;
  color: var(--accent-strong);
  font-weight: 600;
}

.secondary-button:hover:not(:disabled) {
  background: #eef6f5;
}

.mode-grid,
.signal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 76px;
  padding: 14px;
  text-align: left;
}

.mode-card strong {
  font-size: 16px;
}

.mode-card span,
.signal-grid label > span {
  color: var(--muted);
}

.signal-grid {
  margin-top: 14px;
}

.identity-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.identity-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.identity-card label {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.identity-card > div:not(.avatar) {
  flex: 1;
  min-width: 0;
}

.identity-card span {
  color: var(--muted);
}

.identity-card strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity-card .remote-name-display {
  min-height: 38px;
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.identity-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
}

.dice-button,
.disconnect-button {
  position: relative;
  display: grid;
  min-height: 38px;
  padding: 0;
  place-items: center;
}

.dice-button::before,
.dice-button::after,
.dice-button span,
.dice-button span::before,
.dice-button span::after {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.dice-button::before {
  left: 10px;
  top: 10px;
}

.dice-button::after {
  right: 10px;
  bottom: 10px;
}

.dice-button span {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.dice-button span::before {
  right: 8px;
  top: -9px;
}

.dice-button span::after {
  left: 8px;
  top: 9px;
}

.disconnect-button {
  color: var(--danger);
}

.disconnect-button::before,
.disconnect-button::after {
  position: absolute;
  content: "";
}

.disconnect-button::before {
  top: 10px;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 -4px 0 -1px currentColor;
}

.disconnect-button::after {
  top: 15px;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 3px 3px;
}

.disconnect-button span {
  position: absolute;
  top: 18px;
  width: 2px;
  height: 9px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: -4px 0 0 currentColor, 4px 0 0 currentColor;
}

.avatar {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.connect-actions {
  display: grid;
  grid-template-columns: auto auto minmax(160px, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.pair-code-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  justify-items: stretch;
  gap: 12px;
  margin-top: 14px;
}

.pair-code-card,
.pair-qr-card {
  display: grid;
  align-items: center;
  justify-items: center;
  align-self: stretch;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  text-align: center;
}

.pair-code-card {
  container-type: inline-size;
  grid-template-rows: auto 1fr;
  padding: 10px;
}

.pair-qr-card {
  gap: 6px;
  padding: 10px;
  color: var(--muted);
}

.pair-code-box span {
  display: block;
  color: var(--muted);
  text-align: center;
}

.pair-code-copy {
  display: block;
  align-self: center;
  width: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(34px, 8vw, 72px);
  font-size: clamp(34px, 18cqw, 72px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0;
  padding: 0;
}

.pair-code-copy:hover:not(:disabled) {
  border-color: transparent;
  color: var(--accent-strong);
}

.pair-code-copy:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18);
  outline-offset: 2px;
}

.pair-qr {
  display: grid;
  width: 100%;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
}

.pair-qr svg {
  display: block;
  width: min(100%, 208px);
  height: auto;
}

.join-pair {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.join-pair > span {
  color: var(--muted);
  text-align: center;
}

.digit-code {
  display: grid;
  grid-template-columns: repeat(6, 44px);
  gap: 8px;
}

input[type="text"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 10px;
}

.digit-code input[type="text"] {
  width: 44px;
  height: 48px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  padding: 0;
  text-align: center;
}

.digit-code input[type="text"]:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.18);
  outline-offset: 1px;
}

.signal-grid label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

textarea {
  width: 100%;
  min-height: 168px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 10px;
  word-break: break-all;
}

.actions,
.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.file-row input {
  display: none;
}

.file-row span {
  color: var(--muted);
}

.file-picker,
#sendFile,
#receiveFile {
  flex: 0 0 auto;
}

.file-picker span {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 8px 12px;
}

.file-row.drag-over {
  border-color: var(--accent);
  background: #ecfdf5;
}

.transfer-record-section {
  margin-top: 14px;
}

.transfer-record-section h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.file-list,
.send-history {
  display: grid;
  gap: 8px;
}

.file-list-item,
.send-history-item,
.history-record-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 9px 10px;
}

.file-list-item,
.history-record-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow: hidden;
}

.transfer-progress-item {
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.16) var(--transfer-progress, 0%), transparent 0),
    #f8fafc;
}

.file-list-info,
.history-record-info {
  position: relative;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-remove-button {
  min-height: 30px;
  border: 1px solid #fecaca;
  border-radius: 7px;
  background: #fff;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
}

.file-remove-button:hover {
  background: #fef2f2;
}

.send-history-item strong {
  display: block;
}

.send-history-item small {
  color: var(--muted);
}

.history-record-info strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-record-info small {
  color: var(--muted);
}

.status-text {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.countdown-text {
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 760px) {
  .mode-grid,
  .signal-grid,
  .join-pair {
    grid-template-columns: 1fr;
  }

  .connect-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .identity-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .identity-card {
    align-items: center;
    gap: 8px;
    padding: 10px;
  }

  .identity-card .avatar {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .identity-card small {
    max-width: 100%;
  }

  .pair-code-box {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-items: stretch;
    gap: 8px;
  }

  .pair-code-card,
  .pair-qr-card {
    min-width: 0;
    padding: 8px;
  }

  .pair-code-copy {
    font-size: clamp(30px, 13vw, 52px);
    font-size: clamp(30px, 16cqw, 52px);
  }

  .pair-qr svg {
    width: min(35vw, 150px);
    height: auto;
  }

  .join-pair {
    align-items: center;
  }

  .digit-code {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .digit-code input[type="text"] {
    width: 100%;
  }
}

.progress-area {
  margin-top: 16px;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.transfer-actions,
.record-actions {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}

.transfer-pause-button {
  min-height: 30px;
  font-size: 12px;
  padding: 5px 9px;
}

progress {
  width: 100%;
  height: 14px;
  accent-color: var(--accent);
}

.downloads {
  display: grid;
  gap: 10px;
}

.download-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.download-item > div {
  min-width: 0;
}

.download-item a {
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.download-save-button.saved {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--ready);
}

.download-save-button:disabled:not(.saved) {
  color: var(--muted);
  cursor: default;
  opacity: 0.72;
}

.download-item small {
  color: var(--muted);
}

.notes {
  color: var(--muted);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding: 14px 0;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .transfer-panel .panel-head,
  .clipboard-panel .panel-head {
    align-items: center;
    flex-direction: row;
  }

  .connection-panel .panel-head {
    align-items: center;
    flex-flow: row wrap;
  }

  .connection-panel .panel-head h2 {
    flex: 0 0 auto;
    min-width: 0;
    order: 1;
  }

  .connection-panel .panel-head .header-status {
    flex: 1 1 0;
    order: 1;
  }

  .connection-panel .collapse-button {
    flex: 0 0 auto;
    order: 1;
  }

  .clipboard-actions {
    flex-shrink: 0;
  }

  .clipboard-actions button {
    padding-left: 10px;
    padding-right: 10px;
  }

  .settings-options {
    flex-basis: 100%;
    order: 2;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .mode-grid,
  .signal-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
  }

  .status-pill {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }
}
