:root {
  --pink: #f64986;
  --purple: #8b45d6;
  --blue: #029ef6;
  --grad: linear-gradient(120deg, var(--pink), var(--purple) 50%, var(--blue));
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #1c1d2b;
  --muted: #5d6075;
  --border: #e1e3ee;
  --field: #ffffff;
  --shadow: 0 18px 50px rgba(40, 30, 90, 0.12);
  --font: Vazirmatn, "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --card: #1d1f2b;
    --text: #eceef7;
    --muted: #a3a7bd;
    --border: #2d3040;
    --field: #161823;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.8; }
[hidden] { display: none !important; }
a { color: var(--purple); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; transition: transform .15s, box-shadow .2s;
}
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 8px 22px rgba(139, 69, 214, .3); }
.btn.primary:hover { transform: translateY(-1px); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }

/* Connect page */
.connect-view {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; padding: 0 16px;
  background: radial-gradient(700px 360px at 100% 0, color-mix(in srgb, var(--purple) 14%, transparent), transparent), var(--bg);
}
.connect-top { width: min(460px, 100%); display: flex; align-items: center; justify-content: space-between; padding: 24px 0 8px; }
.brand img { height: 38px; width: auto; border-radius: 9px; display: block; }
.lang-btn { font: inherit; font-size: .9rem; padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; }
.connect-card {
  width: min(460px, 100%); margin: 16px 0; padding: 28px 26px; border-radius: 22px;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.connect-card h1 { margin: 0; font-size: 1.6rem; font-weight: 800; }
.subtitle { margin: 4px 0 20px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-weight: 600; font-size: .95rem; }
.field input {
  font: inherit; font-size: 1.15rem; padding: 10px 14px; border-radius: 12px; text-align: left;
  border: 1px solid var(--border); background: var(--field); color: var(--text); letter-spacing: .04em;
}
.field input:focus { outline: 2px solid color-mix(in srgb, var(--purple) 50%, transparent); border-color: var(--purple); }
.hint { margin: -6px 0 18px; color: var(--muted); font-size: .85rem; }
#connect-form .btn { width: 100%; font-size: 1.05rem; }
.recent { margin-top: 18px; font-size: .88rem; color: var(--muted); }
.recent-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.recent-list button {
  font: inherit; direction: ltr; padding: 2px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--field); color: var(--text);
}
.warn { margin: 16px 0 0; padding: 10px 14px; border-radius: 12px; font-size: .9rem; background: rgba(246, 73, 134, .1); border: 1px solid rgba(246, 73, 134, .35); }
.connect-foot { width: min(460px, 100%); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; color: var(--muted); font-size: .85rem; padding-bottom: 24px; }

/* Session */
.session-view { height: 100%; display: flex; flex-direction: column; background: #0d0e14; color: #eceef7; }
.toolbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 6px 10px; background: #181a24; border-bottom: 1px solid #2b2e3d;
}
.peer { font-weight: 700; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.peer small { font-weight: 400; color: #a3a7bd; margin-inline-start: 8px; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tool, .tool-select {
  font: inherit; font-size: .85rem; padding: 4px 12px; border-radius: 9px; white-space: nowrap; cursor: pointer;
  border: 1px solid #2f3242; background: #232634; color: #eceef7;
}
.tool:hover, .tool-select:hover { border-color: var(--purple); }
.tool.danger { background: #3a1830; border-color: #5a2446; }
.screen { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.screen.actual { overflow: auto; align-items: flex-start; justify-content: flex-start; }
#canvas { display: block; background: #000; outline: none; touch-action: none; }
.screen.fit #canvas { max-width: 100%; max-height: 100%; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(13, 14, 20, .82); text-align: center; padding: 16px;
}
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--pink); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.overlay .btn.ghost { color: #eceef7; border-color: #3a3d4f; }

/* Dialog and toasts */
.dialog {
  width: min(420px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: 20px; padding: 22px;
  background: var(--card); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 8, 25, .55); }
.dialog h2 { margin: 0 0 6px; font-size: 1.2rem; }
.dialog p { margin: 0 0 14px; color: var(--muted); white-space: pre-line; }
.dialog input, .dialog textarea {
  width: 100%; font: inherit; font-size: 1.05rem; padding: 9px 12px; border-radius: 10px; margin-bottom: 16px;
  border: 1px solid var(--border); background: var(--field); color: var(--text);
}
.dialog textarea { direction: auto; resize: vertical; }
.dialog-buttons { display: flex; gap: 10px; }
.toasts { position: fixed; bottom: 16px; inset-inline: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 10; }
.toast {
  pointer-events: auto; max-width: 520px; display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 14px;
  background: #232634; color: #eceef7; border: 1px solid #3a3d4f; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); font-size: .92rem;
}
.toast button { font: inherit; font-size: .85rem; padding: 2px 12px; border-radius: 8px; border: 0; background: var(--grad); color: #fff; cursor: pointer; }

@media (max-width: 640px) {
  .peer small { display: none; }
  .tool, .tool-select { padding: 3px 9px; font-size: .8rem; }
}
