:root {
  --bg: #f7f8f6;
  --surface: #fff;
  --soft: #f0f3f1;
  --ink: #17211d;
  --muted: #66716c;
  --line: #dce2de;
  --green: #176b4d;
  --green-dark: #10543c;
  --green-soft: #e6f2ec;
  --danger: #a33a32;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); scroll-behavior: smooth; }
body { min-height: 100vh; margin: 0; overflow-x: hidden; color: var(--ink); background: var(--bg); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button { color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: rgba(23, 107, 77, .12); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid rgba(23, 107, 77, .24); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden] { display: none !important; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { scroll-margin-top: 80px; text-wrap: balance; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 50; padding: 10px 14px; border-radius: 8px; color: #fff; background: var(--green); transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.site-header { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line); background: rgba(247, 248, 246, .94); backdrop-filter: blur(14px); }
.header-inner { width: min(760px, calc(100% - 40px)); min-height: 60px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 20px; font-weight: 750; letter-spacing: -.5px; text-decoration: none; }
.brand svg { width: 30px; height: 30px; border-radius: 7px; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.icon-button:not(:disabled):hover { border-color: #bdc8c1; background: var(--soft); }
.icon-button svg { width: 19px; height: 19px; }

.main-content { width: min(760px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 max(40px, env(safe-area-inset-bottom)); }
.runtime-banner { min-height: 44px; margin-bottom: 12px; padding: 10px 13px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); background: var(--surface); font-size: 12px; }
.runtime-banner.error { border-color: #edcbc8; color: #7d302a; background: #fff4f2; }
.runtime-banner.ready { color: var(--green-dark); background: var(--green-soft); }
.spinner { width: 14px; height: 14px; flex: 0 0 auto; border: 2px solid #cad3ce; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
.runtime-banner.error .spinner, .runtime-banner.ready .spinner, .runtime-banner.warning .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius); background: #edf0ed; }
.mode-switch button { min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; }
.mode-switch button:hover { color: var(--ink); background: rgba(255, 255, 255, .55); }
.mode-switch button.active { color: var(--green-dark); background: var(--surface); box-shadow: 0 1px 3px rgba(17, 39, 29, .09); }
.mode-switch svg { width: 20px; height: 20px; }
.mode-switch strong { font-size: 14px; }

.mode-panel { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2, .section-heading h3 { margin: 0; font-size: 17px; letter-spacing: -.3px; }
.section-heading h3 { font-size: 13px; }
.section-heading > span { color: var(--muted); font-size: 11px; }
.section-heading.compact { min-height: 28px; }
.peers-heading { margin-top: 26px; }

.file-picker, .pair-row, .peer-row { width: 100%; display: grid; align-items: center; gap: 12px; border: 1px solid var(--line); background: var(--surface); text-align: left; cursor: pointer; }
.file-picker { min-height: 76px; margin-top: 12px; padding: 12px 14px; grid-template-columns: 42px minmax(0, 1fr) 18px; border-radius: 11px; }
.file-picker:not(:disabled):hover, .pair-row:not(:disabled):hover, .peer-row:hover { background: var(--soft); }
.file-picker > span:nth-child(2), .pair-row > span:nth-child(2), .peer-copy { min-width: 0; display: flex; flex-direction: column; }
.file-picker strong, .pair-row strong, .peer-copy strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.file-picker small, .pair-row small, .peer-copy small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.file-picker > svg, .pair-row > svg, .peer-row > svg { width: 17px; height: 17px; color: #89938e; }
.symbol { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 10px; color: var(--green); background: var(--green-soft); }
.symbol svg { width: 21px; height: 21px; }

.selected-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.file-list { margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.file-row { min-width: 0; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.file-row + .file-row { border-top: 1px solid var(--line); }
.file-copy { min-width: 0; display: flex; flex-direction: column; }
.file-copy strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.file-copy small { margin-top: 2px; color: var(--green); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.file-size { color: var(--muted); font-size: 10px; white-space: nowrap; }

.peer-list { margin-top: 12px; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.peer-row { min-height: 64px; padding: 9px 13px; grid-template-columns: 38px minmax(0, 1fr) auto 17px; border: 0; }
.peer-row + .peer-row { border-top: 1px solid var(--line); }
.peer-avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--green-dark); background: var(--green-soft); font-size: 13px; font-weight: 750; }
.peer-route { color: var(--green); font-size: 10px; font-weight: 650; white-space: nowrap; }
.empty-state { padding: 24px 16px; color: var(--muted); font-size: 12px; text-align: center; }
.pair-row { min-height: 64px; margin-top: 9px; padding: 10px 13px; grid-template-columns: 42px minmax(0, 1fr) 17px; border-radius: 11px; }

.primary-button, .secondary-button { min-height: 42px; padding: 0 16px; border-radius: 10px; font-weight: 700; cursor: pointer; }
.primary-button { border: 1px solid var(--green); color: #fff; background: var(--green); }
.primary-button:not(:disabled):hover { border-color: var(--green-dark); background: var(--green-dark); }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); }
.secondary-button:not(:disabled):hover { border-color: #bdc8c1; background: var(--soft); }
.secondary-button svg { width: 16px; height: 16px; }
.text-button, .text-icon-button { padding: 3px; border: 0; color: var(--green); background: transparent; font-size: 11px; font-weight: 700; cursor: pointer; }
.text-button:hover { text-decoration: underline; }
.text-button.danger { color: var(--danger); }
.text-icon-button { display: flex; align-items: center; gap: 6px; }
.text-icon-button svg { width: 15px; height: 15px; }
.text-icon-button.spinning svg { animation: spin .7s linear; }

.receive-header { max-width: 580px; margin: 2px auto 20px; text-align: center; }
.receive-state { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 9px; padding: 5px 9px; border-radius: 999px; color: var(--muted); background: var(--soft); font-size: 10px; font-weight: 700; }
.receive-state.ready { color: var(--green-dark); background: var(--green-soft); }
.receive-state i { width: 7px; height: 7px; border-radius: 50%; background: #97a19c; }
.receive-state.ready i { background: #2b9a67; }
.receive-header h2 { margin: 0; font-size: 22px; letter-spacing: -.55px; }
.receive-header p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.pairing-card, .incoming-card { max-width: 560px; margin: 0 auto; padding: 18px; border: 1px solid var(--line); border-radius: 11px; }
.pairing-content { margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 22px; }
.qr-code { width: 180px; height: 180px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: #fff; image-rendering: pixelated; }
.pair-code-block { display: flex; flex-direction: column; align-items: flex-start; }
.pair-code-block small { color: var(--muted); font-size: 10px; }
.pair-code-block strong { margin: 3px 0 12px; font-size: 21px; letter-spacing: .1em; }
.timer { padding: 4px 7px; border-radius: 7px; color: var(--green-dark) !important; background: var(--green-soft); font-variant-numeric: tabular-nums; font-weight: 700; }
.security-note { margin: 13px 0 0; display: flex; align-items: flex-start; gap: 7px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.security-note svg { width: 14px; height: 14px; flex: 0 0 auto; color: var(--green); }
.incoming-card { margin-top: 12px; }
.incoming-card h3 { margin: 0 0 5px; font-size: 16px; }
.incoming-card > strong { font-size: 12px; }
.incoming-files { margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.button-row { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }

.transfer-panel { margin-top: 12px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.transfer-panel p { margin: 5px 0 12px; color: var(--muted); font-size: 11px; }
.transfer-panel .danger { margin-top: 12px; }
.progress-track { width: 100%; height: 7px; overflow: hidden; border: 0; border-radius: 99px; background: #e5e9e6; color: var(--green); }
.progress-track::-webkit-progress-bar { border-radius: inherit; background: #e5e9e6; }
.progress-track::-webkit-progress-value { border-radius: inherit; background: var(--green); transition: inline-size .2s linear; }
.progress-track::-moz-progress-bar { border-radius: inherit; background: var(--green); }
body.modal-open { overflow: hidden; }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; padding: 20px; display: none; place-items: center; background: rgba(10, 20, 15, .46); overscroll-behavior: contain; }
.modal-backdrop.open { display: grid; }
.modal { position: relative; width: min(500px, 100%); max-height: min(720px, calc(100dvh - 40px)); overflow: auto; padding: 26px; border-radius: 15px; background: var(--surface); box-shadow: 0 18px 50px rgba(10, 25, 18, .18); }
.modal-close { position: absolute; top: 13px; right: 13px; width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; background: var(--soft); cursor: pointer; }
.modal-close:hover { background: #e5e9e6; }
.modal-close svg { width: 17px; height: 17px; }
.modal-heading { padding-right: 38px; }
.modal-heading h2 { margin: 0; font-size: 20px; letter-spacing: -.4px; }
.modal-heading p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.modal-actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }
.integrity-note { margin-top: 13px; padding: 11px; display: flex; align-items: flex-start; gap: 8px; border-radius: 9px; color: var(--green-dark); background: var(--green-soft); font-size: 10px; line-height: 1.5; }
.integrity-note svg { width: 15px; height: 15px; flex: 0 0 auto; }
.scan-area { margin-top: 16px; }
.camera-preview { width: 100%; aspect-ratio: 4/3; display: none; border-radius: 10px; background: #101713; object-fit: cover; }
.camera-preview.active { display: block; }
.scan-status { margin: 9px 0 0; color: var(--muted); font-size: 10px; text-align: center; }
.divider { margin: 19px 0; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 10px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.manual-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.field-label { display: grid; gap: 6px; margin-top: 16px; font-size: 11px; font-weight: 650; }
.field-input { min-width: 0; height: 43px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: var(--surface); }
.field-input::placeholder { color: #909a95; }
.setting-list { margin-top: 16px; border-block: 1px solid var(--line); }
.setting-row { min-height: 61px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.setting-row + .setting-row { border-top: 1px solid var(--line); }
.setting-copy { display: flex; flex-direction: column; }
.setting-copy strong { font-size: 11px; }
.setting-copy small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.switch { position: relative; width: 42px; height: 24px; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #bbc4bf; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .18s ease; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid rgba(23, 107, 77, .24); outline-offset: 3px; }

.toast { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); z-index: 40; max-width: calc(100% - 32px); padding: 10px 14px; display: flex; align-items: center; gap: 8px; border-radius: 9px; color: #fff; background: var(--ink); box-shadow: 0 8px 24px rgba(9, 25, 17, .2); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast svg { width: 15px; height: 15px; }
.toast span:last-child { font-size: 11px; }

@media (max-width: 640px) {
  .header-inner, .main-content { width: min(100% - 28px, 760px); }
  .header-inner { min-height: 58px; }
  .main-content { padding-top: 16px; }
  .mode-panel { padding: 18px 14px; }
  .file-picker { grid-template-columns: 42px minmax(0, 1fr) 17px; }
  .peer-row { grid-template-columns: 38px minmax(0, 1fr) 17px; }
  .peer-route { display: none; }
  .pairing-content { flex-direction: column; }
  .pair-code-block { align-items: center; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { width: 100%; max-height: calc(100dvh - 20px); padding: 25px 19px max(22px, env(safe-area-inset-bottom)); border-radius: 17px 17px 0 0; }
}

@media (max-width: 420px) {
  .mode-switch { gap: 4px; }
  .file-picker small { display: none; }
  .file-row { grid-template-columns: 1fr; gap: 3px; }
  .manual-form { grid-template-columns: 1fr; }
}

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

.runtime-banner.warning { border-color: #e6d7ae; color: #6b551f; background: #fdf8ea; }
.paired-list { display: flex; flex-direction: column; gap: 2px; }
