/* AnyConN web viewer — เลย์เอาต์แบบ AnyDesk โทนดำ-เหลือง (เข้าชุดกับแอปเดสก์ท็อป) */
:root {
  color-scheme: dark;

  --bg: #0d0d0d;
  --sheet: #1a1a17;
  --sheet-2: #121210;
  --ink: #f5f1e6;
  --ink-2: #ddd6bf;
  --muted: #b0a88f;
  --line: #2f2c22;
  --line-strong: #4d4830;
  --field-line: #8f885f;    /* ขอบช่องกรอก (คอนทราสต์ ≥ 3:1) */

  --accent: #ffc400;
  --accent-ink: #141100;
  --accent-text: #ffd23f;
  --accent-soft: #3a3000;

  --btn-bg: var(--accent);
  --btn-ink: var(--accent-ink);

  --live: #5fdc9a;
  --live-soft: #123222;
  --wait: #ff9f43;
  --wait-soft: #3a2410;
  --danger: #ff6b6b;
  --danger-soft: #3c1517;

  /* แผงด้านซ้ายและแถบบนในหน้าควบคุม */
  --pane: #151512;
  --pane-ink: #f5f1e6;
  --pane-muted: #b0a88f;
  --pane-line: #3a3626;
  --pane-live: #ffc400;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;

  --font: "Segoe UI Variable Text", "Segoe UI", "Leelawadee UI", "Thonburi", system-ui, -apple-system, "Noto Sans Thai", sans-serif;
  --font-num: "Segoe UI Variable Display", "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- หน้าเชื่อมต่อ: แบ่งสองฝั่ง ---------- */
.split { display: grid; grid-template-columns: minmax(340px, 5fr) minmax(380px, 6fr); min-height: 100%; }

.intro {
  display: flex; flex-direction: column; justify-content: center; gap: 28px;
  padding: 48px clamp(28px, 6vw, 80px);
  color: var(--pane-ink); background: var(--pane); border-right: 1px solid var(--pane-line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 650; }
.mark-img { width: 42px; height: 42px; flex: none; }
.mark { width: 28px; height: 28px; fill: none; stroke: var(--pane-ink); stroke-width: 1.7; stroke-linejoin: round; }

/* ภาพจอสองเครื่องเชื่อมกัน: เส้นเชื่อมจะ "ไหล" ตอนกำลังเชื่อมต่อเท่านั้น */
.link-art { width: min(100%, 340px); height: auto; }
.link-art .scr { fill: none; stroke: var(--pane-muted); stroke-width: 2; }
.link-art .stand { fill: none; stroke: var(--pane-muted); stroke-width: 2; stroke-linecap: round; }
.link-art .wire { fill: none; stroke: var(--pane-line); stroke-width: 2; stroke-dasharray: 5 6; stroke-linecap: round; }
.link-art .node { fill: var(--pane-muted); }
body[data-state="connecting"] .wire, body[data-state="waiting"] .wire {
  stroke: var(--pane-live); animation: flow 1s linear infinite;
}
body[data-state="connecting"] .node, body[data-state="waiting"] .node { fill: var(--pane-live); }
@keyframes flow { to { stroke-dashoffset: -11; } }

.intro h1 { margin: 0; font-size: clamp(24px, 3vw, 32px); line-height: 1.3; font-weight: 600; letter-spacing: -.005em; max-width: 16em; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 12px; }
.steps li { position: relative; padding-left: 38px; color: var(--pane-muted); counter-increment: s; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: -1px; display: grid; place-items: center;
  width: 26px; height: 26px; border: 1px solid var(--pane-line); border-radius: 50%;
  font: 600 13px/1 var(--font-num); color: var(--pane-ink);
}

/* ---------- ฟอร์ม ---------- */
.form-side { display: flex; justify-content: center; align-items: flex-start; padding: 32px 24px; }
.acct-col { display: grid; gap: 16px; width: 100%; max-width: 420px; margin: auto 0; justify-items: stretch; }
.acct-col .card, .acct-col .ac-bar, .acct-col .ac-lists { max-width: none; }
.card { width: 100%; max-width: 420px; padding: 30px 30px 26px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card h2 { margin: 0 0 22px; font-size: 22px; font-weight: 650; }

.field { display: block; margin-bottom: 18px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
.field em { margin-left: 6px; font-style: normal; font-weight: 400; color: var(--muted); font-size: 12.5px; }
input {
  display: block; width: 100%; height: 46px; padding: 0 12px;
  font: inherit; color: var(--ink); background: var(--sheet); border: 1px solid var(--field-line); border-radius: var(--r-sm);
}
input::placeholder { color: var(--muted); opacity: .6; }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.input-id { height: 54px; font: 400 24px/1 var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.input-wrap { position: relative; }
.input-wrap input { padding-right: 46px; }
.input-wrap .icon-btn { position: absolute; top: 6px; right: 6px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  color: var(--ink-2); background: none; border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 13px 16px;
  font: inherit; font-size: 16px; font-weight: 600; color: var(--btn-ink); background: var(--btn-bg);
  border: 0; border-radius: var(--r-sm); cursor: pointer; transition: transform .06s ease, opacity .15s ease;
}
.btn:hover { opacity: .9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }

.status { display: none; margin: 16px 0 0; padding: 10px 12px; font-size: 14px; border-radius: var(--r-sm); }
.status.info, .status.error { display: flex; align-items: center; gap: 10px; }
.status.info { color: var(--ink-2); background: var(--sheet); border: 1px solid var(--line); }
.status.error { color: var(--danger); background: var(--danger-soft); }
.status.info::before {
  content: ""; width: 14px; height: 14px; flex: none; border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- หน้าจอควบคุม ---------- */
#screen-panel { position: fixed; inset: 0; background: #000; }
#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; outline: none; user-select: none; }
#screen { width: 100%; height: 100%; object-fit: contain; background: #000; }
/* แถบเครื่องมือถูกตรึง: ภาพเริ่มใต้แถบ ไม่ทับหน้าจอเครื่องปลายทาง (ปลดตรึงแล้วแถบจะลอยและซ่อนเอง) */
#screen-panel.docked #stage { top: 48px; }
#screen-panel.docked .toolbar { transform: none; opacity: 1; pointer-events: auto; }
#screen-panel.docked .tb-handle { display: none; }
.tb-btn.is-on { color: var(--accent-text); background: rgba(255, 196, 0, .22); }
.notice {
  position: fixed; top: 58px; left: 50%; z-index: 2; display: flex; align-items: flex-start; gap: 10px;
  width: max-content; max-width: min(620px, calc(100vw - 24px)); padding: 10px 12px 10px 16px; transform: translateX(-50%);
  color: var(--ink); font-size: 13.5px; line-height: 1.5; background: var(--wait-soft, #fff4dc);
  border: 1px solid var(--wait, #e0a526); border-radius: var(--r-md); box-shadow: 0 8px 24px rgba(0, 0, 0, .6);
}
.notice[hidden] { display: none; }
.notice { pointer-events: none; } /* ไม่บังการคลิกบนหน้าจอปลายทาง ยกเว้นปุ่มปิด */
.notice-x { pointer-events: auto; }
.notice p { margin: 0; }
.notice-x { flex: none; width: 24px; height: 24px; padding: 0; color: inherit; font: inherit; font-size: 18px; line-height: 1; background: transparent; border: 0; border-radius: 6px; cursor: pointer; }
.notice-x:hover { background: rgba(255, 255, 255, .1); }

.toolbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 12px 0 16px; color: var(--pane-ink); font-size: 13.5px;
  background: var(--pane); border-bottom: 1px solid var(--pane-line);
  transition: transform .22s ease, opacity .22s ease;
}
.toolbar.idle { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); }
.tb-status { font-weight: 650; }
.tb-stats { color: var(--pane-muted); font-variant-numeric: tabular-nums; }
.tb-stats:empty { display: none; }
.tb-sep { width: 1px; height: 20px; background: var(--pane-line); }
.tb-tabs + .tb-sep { margin-left: auto; visibility: hidden; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px;
  color: inherit; font: inherit; font-weight: 600; background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.tb-btn:hover { background: rgba(255, 255, 255, .08); }
.tb-danger { color: #fff; background: var(--danger); }
.tb-danger:hover { background: var(--danger); opacity: .9; }
.tb-danger { color: #2a0a0d; }
.tb-handle {
  position: fixed; top: 6px; left: 50%; z-index: 1; width: 56px; height: 4px; border-radius: 2px;
  background: rgba(255, 196, 0, .85); transform: translateX(-50%); pointer-events: none;
}
.toolbar:not(.idle) ~ .tb-handle { opacity: 0; }

/* ---------- จอแคบ ---------- */
@media (max-width: 820px) {
  .card { padding: 24px 20px 22px; }
  .split { grid-template-columns: 1fr; }
  .intro { gap: 18px; padding: 28px 24px; border-right: 0; border-bottom: 1px solid var(--pane-line); }
  .link-art, .steps { display: none; }
  .intro h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- แท็บไฟล์ ---------- */
.btn-sm { width: auto; padding: 9px 16px; font-size: 14px; }
.btn-quiet { color: var(--accent-text); background: transparent; border: 1px solid var(--line-strong); }
.btn-quiet:hover { background: var(--accent-soft); opacity: 1; }

.tb-tabs { display: flex; gap: 4px; }
.tb-tab {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 16px;
  color: var(--pane-ink); font: inherit; font-weight: 600; background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.tb-tab:hover { background: rgba(255, 255, 255, .08); }
.tb-tab[aria-selected="true"] { color: var(--ink); background: var(--sheet); box-shadow: 0 1px 0 var(--pane-line); }
.tb-badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  color: var(--accent-ink); background: var(--accent); font: 700 11px/1 var(--font-num);
}

.files-view { position: absolute; inset: 0; z-index: 1; overflow: auto; padding: 76px 20px 48px; color: var(--ink); background: var(--bg); }
.fv-inner { max-width: 680px; margin: 0 auto; }
.fv-inner h2 { margin: 0 0 16px; font-size: 22px; font-weight: 650; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; padding: 34px 24px 28px; text-align: center;
  background: var(--sheet); border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg);
  transition: border-color .15s ease, background-color .15s ease;
}
.dropzone:focus-visible, .dropzone.is-over { border-color: var(--accent); outline: none; }
.dropzone.is-over { background: var(--accent-soft); }
.dropzone.is-disabled { opacity: .6; }
.dz-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 14px; color: var(--accent-text); background: var(--accent-soft); border-radius: 50%; }
.dz-icon .i { width: 24px; height: 24px; }
.dz-title { margin: 0; font-size: 17px; font-weight: 600; }
.dz-sub { margin: 4px 0 18px; color: var(--muted); font-size: 14px; }
.dz-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.dz-actions .btn { width: auto; }
.fv-note { margin: 12px 2px 0; color: var(--muted); font-size: 13px; }
.fv-title { margin: 28px 2px 10px; font-size: 14px; font-weight: 600; }
.fv-empty { margin: 0; padding: 22px 0; text-align: center; color: var(--muted); font-size: 14px; }

.xfer-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.xfer-list:empty { display: none; }
.xfer { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); }
.xfer-ico { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%; color: var(--accent-text); background: var(--accent-soft); }
.xfer-main { flex: 1; min-width: 0; }
.xfer-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.xfer progress {
  display: block; width: 100%; height: 4px; margin: 7px 0 5px; border: 0; border-radius: 2px; background: var(--line);
  -webkit-appearance: none; appearance: none; overflow: hidden;
}
.xfer progress::-webkit-progress-bar { background: var(--line); }
.xfer progress::-webkit-progress-value { background: var(--accent); transition: width .15s linear; }
.xfer-meta { display: flex; gap: 12px; color: var(--muted); font-size: 13px; }
.xfer-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xfer.is-done progress, .xfer.is-fail progress { display: none; }
.xfer.is-done .xfer-ico { color: var(--live); background: var(--live-soft); }
.xfer.is-done .xfer-status { color: var(--live); }
.xfer.is-fail .xfer-ico { color: var(--danger); background: var(--danger-soft); }
.xfer.is-fail .xfer-status { color: var(--danger); }
.xfer-act { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; background: transparent; border: 1px solid var(--line-strong); border-radius: var(--r-sm); cursor: pointer; }
.xfer-act:hover { background: var(--accent-soft); }
.xfer-act .i { width: 16px; height: 16px; }

.drop-overlay { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; pointer-events: none; background: rgba(0, 0, 0, .72); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.drop-overlay p { margin: 0; padding: 40px 56px; color: #fff; font-size: 20px; font-weight: 600; border: 2px dashed var(--accent-text); border-radius: var(--r-lg); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 6; max-width: calc(100% - 40px); padding: 10px 18px;
  color: var(--btn-ink); background: var(--btn-bg); font-size: 14px; font-weight: 550; border-radius: 999px;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: #fff; background: var(--danger); }
.toast.error { color: #2a0a0d; }

@media (max-width: 720px) { .tb-stats { display: none; } .tb-btn.tb-danger { padding: 0 10px; } }

.tb-tab[aria-selected="true"] { background: var(--accent-soft); box-shadow: none; }

/* สัญญาณภาพสะดุด: แถบบนเปลี่ยนเป็นโทนเตือนจนกว่าจะกู้การเชื่อมต่อได้ */
.toolbar.is-unstable { background: var(--danger-soft); border-bottom-color: var(--danger); }
.toolbar.is-unstable .tb-status { color: var(--danger); }
.toolbar.is-unstable .live-dot { background: var(--danger); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.8); } }

/* ---------- เมนูเมาส์ ---------- */
#stage { touch-action: none; }
#stage[data-cursor="dot"] { cursor: url('/cursor-dot.svg') 7 7, crosshair; }
#stage[data-cursor="none"] { cursor: none; }

.tb-menu { position: relative; }
.tb-btn.is-view { color: var(--wait); background: var(--wait-soft); }
.tb-pop {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 3; width: min(340px, calc(100vw - 24px));
  padding: 6px 16px 14px; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.opt { margin: 0; padding: 12px 0 0; border: 0; min-width: 0; }
.opt + .opt { border-top: 1px solid var(--line); margin-top: 12px; }
.opt legend { float: left; width: 100%; padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 650; color: var(--ink-2); }
.opt-row { clear: both; display: flex; gap: 6px; }
.seg { position: relative; flex: 1; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: block; padding: 8px 6px; text-align: center; font-size: 13.5px; font-weight: 600; color: var(--accent-text);
  background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
}
.seg:hover span { background: var(--accent-soft); }
.seg input:checked + span { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt-hint { margin: 8px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }

/* ---------- เมนูคุณภาพภาพ / คลิปบอร์ด ---------- */
.opt-list { clear: both; display: grid; gap: 4px; }
.opt-item { position: relative; display: block; }
.opt-item input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.opt-t {
  display: block; padding: 8px 12px; font-size: 13.5px; font-weight: 600; color: var(--accent-text);
  background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
}
.opt-item:hover .opt-t { background: var(--accent-soft); }
.opt-item input:checked + .opt-t { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.opt-item input:focus-visible + .opt-t { outline: 2px solid var(--accent); outline-offset: 2px; }
.tb-btn.is-off { opacity: .6; }
.field-sm { clear: both; display: block; margin-top: 10px; }
.field-sm > span { display: block; margin-bottom: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field-sm textarea {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 64px; max-height: 160px; padding: 8px 10px;
  font: inherit; font-size: 13px; line-height: 1.45; color: var(--ink); background: var(--bg-soft, var(--sheet));
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
}
.opt-actions { clear: both; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.opt-actions .btn { flex: 1 1 auto; white-space: nowrap; }
@media (max-width: 1240px) { .tb-lbl { display: none; } }
@media (max-width: 1100px) { .tb-stats { display: none; } }
@media (max-width: 720px) {
  .tb-pop { position: fixed; top: 54px; right: 12px; }
}

/* ---------- ดาวน์โหลดโปรแกรม ---------- */
.dl { max-width: 340px; padding-top: 22px; border-top: 1px solid var(--pane-line); }
.dl h2 { margin: 0; font-size: 16px; font-weight: 650; }
.dl-sub { margin: 2px 0 12px; font-size: 13px; color: var(--pane-muted); }
.dl-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.dl-btn {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; text-decoration: none; color: var(--pane-ink);
  background: transparent; border: 1px solid var(--pane-line); border-radius: var(--r-sm);
}
.dl-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.dl-item.is-mine .dl-btn { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.dl-item.is-mine .dl-btn:hover { opacity: .92; }
.dl-os { font-weight: 650; }
.dl-meta { font-size: 12.5px; color: var(--pane-muted); }
.dl-item.is-mine .dl-meta { color: var(--accent-ink); opacity: .8; }
.dl-hash { margin-top: 6px; font-size: 12px; color: var(--pane-muted); }
.dl-hash summary { cursor: pointer; }
.dl-hash code { display: block; margin-top: 4px; font: 11.5px/1.4 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; color: var(--pane-ink); }
.dl-note { margin: 6px 0 0; font-size: 12.5px; color: var(--pane-muted); }
.dl-item.is-empty .dl-btn { cursor: default; border-style: dashed; color: var(--pane-muted); }
.dl-item.is-empty .dl-btn:hover { border-color: var(--pane-line); background: transparent; }

.dl-server { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--pane-line); }
.dl-server-label { font-size: 12.5px; color: var(--pane-muted); }
.dl-server-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.dl-server-row code { flex: 1; min-width: 0; font: 12.5px/1.4 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; color: var(--pane-ink); }
.dl-copy { flex: none; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--pane-line); background: transparent; color: var(--pane-ink); font: inherit; font-size: 13px; cursor: pointer; }
.dl-copy:hover { border-color: var(--accent); background: var(--accent-soft); }
