/* =====================================================
   رنگامیز — طراحی بصری
   پالت الهام‌گرفته از کاشی‌کاری ایرانی: نیلی شب، فیروزه‌ای، زعفرانی
   ===================================================== */

:root {
  --ink-950: #14101f;
  --ink-900: #1b1530;
  --ink-800: #241d3d;
  --ink-700: #322a52;
  --ink-600: #443a6b;
  --paper: #f7f3ec;
  --cream: #efe8db;
  --turquoise: #2bb3a3;
  --turquoise-dim: #1f8578;
  --saffron: #e8a33d;
  --saffron-dim: #c8862a;
  --danger: #e0574f;
  --text-hi: #f6f2e9;
  --text-lo: #b9aed6;
  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 26px;
  --shadow-deep: 0 24px 60px -20px rgba(10, 6, 24, 0.55);
  --ease: cubic-bezier(.22,.9,.32,1);
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink-950);
  color: var(--text-hi);
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input {
  font-family: inherit;
  color: inherit;
}
button { cursor: pointer; }
svg { display: block; width: 1.15em; height: 1.15em; }

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
}

/* ===================== دکمه‌ها ===================== */
.btn {
  border: none;
  border-radius: var(--radius-s);
  padding: 13px 22px;
  font-size: 0.98rem;
  font-weight: 600;
  transition: transform .15s var(--ease), background .2s, box-shadow .2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn--block { width: 100%; }
.btn--primary {
  background: linear-gradient(135deg, var(--turquoise), var(--turquoise-dim));
  color: #08201d;
  box-shadow: 0 10px 24px -8px rgba(43, 179, 163, .55);
}
.btn--primary:hover { box-shadow: 0 14px 30px -8px rgba(43, 179, 163, .7); }
.btn--ghost {
  background: transparent;
  border: 1.5px solid var(--ink-600);
  color: var(--text-hi);
}
.btn--ghost:hover { border-color: var(--turquoise); }
.btn--danger { background: var(--danger); color: #2b0503; }
.btn--small { padding: 8px 14px; font-size: .85rem; }
.btn:disabled { opacity: .55; pointer-events: none; }

.btn-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.25); border-top-color: currentColor;
  animation: spin .7s linear infinite;
}
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--ink-600); border-top-color: var(--turquoise);
  animation: spin .7s linear infinite;
}
.spinner--lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: block; margin-bottom: 14px; text-align: right; }
.field-label { display: block; font-size: .85rem; color: var(--text-lo); margin-bottom: 6px; }
.field-input {
  width: 100%; padding: 13px 16px; border-radius: var(--radius-s);
  border: 1.5px solid var(--ink-600); background: var(--ink-800);
  color: var(--text-hi); font-size: 1rem; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field-input::placeholder { color: #7b7196; }
.field-input:focus { border-color: var(--turquoise); box-shadow: 0 0 0 3px rgba(43,179,163,.25); }
.field-input--ltr { direction: ltr; text-align: left; font-family: "Vazirmatn", monospace; }
.field-error { color: var(--danger); font-size: .85rem; min-height: 1.1em; margin: 2px 0 8px; }

/* ===================== صفحه ورود ===================== */
.screen--auth {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-backdrop { position: absolute; inset: 0; overflow: hidden; z-index: 0; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: .35;
}
.blob--a { width: 480px; height: 480px; background: var(--turquoise); top: -160px; right: -120px; }
.blob--b { width: 420px; height: 420px; background: var(--saffron); bottom: -140px; left: -100px; }

.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: rgba(27, 21, 48, .85);
  backdrop-filter: blur(18px);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius-l);
  padding: 34px 30px 30px;
  box-shadow: var(--shadow-deep);
  animation: rise .5s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.brand { text-align: center; margin-bottom: 26px; }
.brand-mark {
  display: block; font-size: 2.1rem; font-weight: 800;
  background: linear-gradient(90deg, var(--turquoise), var(--saffron));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-tag { display: block; margin-top: 6px; color: var(--text-lo); font-size: .9rem; }

.auth-tabs {
  display: flex; background: var(--ink-800); border-radius: 999px;
  padding: 4px; margin-bottom: 24px;
}
.auth-tab {
  flex: 1; border: none; background: transparent; color: var(--text-lo);
  padding: 10px 0; border-radius: 999px; font-weight: 600; transition: all .25s var(--ease);
}
.auth-tab.is-active { background: var(--turquoise); color: #08201d; }

.auth-form { display: none; }
.auth-form.is-active { display: block; animation: fadeIn .3s var(--ease); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===================== داشبورد ===================== */
.screen--dashboard { background: var(--ink-950); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 26px; border-bottom: 1px solid var(--ink-800);
  position: sticky; top: 0; background: rgba(20, 16, 31, .9); backdrop-filter: blur(10px); z-index: 5;
}
.topbar-brand { font-weight: 800; font-size: 1.3rem; color: var(--turquoise); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--saffron);
  color: #2b1a04; display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.user-name { font-weight: 600; }

.dash-hero { padding: 40px 26px 10px; max-width: 780px; }
.dash-hero h1 { font-size: 1.8rem; margin: 0 0 10px; }
.dash-hero p { color: var(--text-lo); margin: 0; line-height: 1.9; }

.dash-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  padding: 24px 26px; max-width: 900px;
}
.action-card {
  border: none; text-align: right; border-radius: var(--radius-l);
  padding: 26px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  transition: transform .2s var(--ease), box-shadow .2s;
}
.action-card:hover { transform: translateY(-4px); }
.action-card--create {
  background: linear-gradient(155deg, var(--turquoise), var(--turquoise-dim));
  color: #06211d; box-shadow: 0 20px 40px -18px rgba(43,179,163,.6);
}
.action-card--join {
  background: var(--ink-800); border: 1.5px solid var(--ink-600); color: var(--text-hi);
}
.action-icon {
  width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.18);
}
.action-card--join .action-icon { background: var(--ink-700); color: var(--saffron); }
.action-title { font-size: 1.15rem; font-weight: 700; }
.action-desc { font-size: .88rem; opacity: .85; line-height: 1.7; }

.dash-list-section { padding: 10px 26px 60px; max-width: 900px; }
.dash-list-section h2 { font-size: 1.1rem; color: var(--text-lo); font-weight: 600; margin-bottom: 14px; }
.canvas-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.canvas-item {
  background: var(--ink-800); border: 1px solid var(--ink-700); border-radius: var(--radius-m);
  padding: 18px; text-align: right; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .2s, transform .2s;
}
.canvas-item:hover { border-color: var(--turquoise); transform: translateY(-2px); }
.canvas-item-title { font-weight: 700; }
.canvas-item-meta { font-size: .8rem; color: var(--text-lo); }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--text-lo); padding: 10px 0; }
.empty-state { text-align: center; padding: 40px 0; color: var(--text-lo); display: flex; flex-direction: column; gap: 16px; align-items: center; }

/* ===================== مودال‌ها ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 7, 20, .65); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 18px;
  animation: fadeIn .2s var(--ease);
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%; max-width: 420px; background: var(--ink-900); border: 1px solid var(--ink-700);
  border-radius: var(--radius-l); padding: 26px; box-shadow: var(--shadow-deep);
  animation: rise .3s var(--ease);
}
.modal h3 { margin: 0 0 8px; font-size: 1.2rem; }
.modal p { color: var(--text-lo); font-size: .92rem; line-height: 1.8; margin: 0 0 16px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.link-row { display: flex; gap: 8px; margin-bottom: 6px; }
.link-row .field-input { flex: 1; }

/* ===================== بوم نقاشی ===================== */
.screen--canvas { background: var(--paper); overflow: hidden; touch-action: none; }
#drawSurface { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.cursor-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

.canvas-topbar {
  position: absolute; top: 0; right: 0; left: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(20,16,31,.85), transparent);
}
.canvas-title { font-weight: 700; color: #221933; flex: 1; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: none;
  background: rgba(255,255,255,.85); color: #241d3d; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); transition: transform .15s, background .2s;
}
.icon-btn:hover { transform: translateY(-1px); background: #fff; }
.icon-btn--accent { background: var(--turquoise); color: #06211d; }
.icon-btn--small { width: 34px; height: 34px; border-radius: 10px; font-size: 1.1rem; }

.conn-status {
  display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.85);
  border-radius: 999px; padding: 6px 12px; font-size: .78rem; color: #241d3d; font-weight: 600;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--saffron); }
.conn-status.is-online .conn-dot { background: var(--turquoise); }
.conn-status.is-offline .conn-dot { background: var(--danger); }
.presence-chip {
  background: var(--ink-900); color: var(--text-hi); border-radius: 999px; padding: 6px 12px; font-size: .78rem; font-weight: 600;
}

/* نوار ابزار عمودی سمت راست (دسکتاپ) */
.toolbar {
  position: absolute; top: 50%; right: 16px; transform: translateY(-50%); z-index: 20;
  background: rgba(27, 21, 48, .92); backdrop-filter: blur(12px);
  border-radius: 20px; padding: 10px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow-deep);
}
.tool-group { display: flex; flex-direction: column; gap: 4px; }
.tool-divider { height: 1px; background: var(--ink-700); margin: 4px 2px; }
.tool-btn {
  width: 44px; height: 44px; border-radius: 12px; border: none; background: transparent; color: var(--text-hi);
  display: flex; align-items: center; justify-content: center; transition: background .2s, color .2s;
  position: relative;
}
.tool-btn:hover { background: var(--ink-700); }
.tool-btn.is-active { background: var(--turquoise); color: #06211d; }
.tool-btn svg { width: 20px; height: 20px; }

/* پنل پایین (رنگ / ضخامت / شفافیت) */
.bottom-panel {
  position: absolute; bottom: 0; right: 0; left: 0; z-index: 20;
  background: rgba(27, 21, 48, .95); backdrop-filter: blur(14px);
  border-top-left-radius: var(--radius-l); border-top-right-radius: var(--radius-l);
  box-shadow: 0 -12px 40px rgba(0,0,0,.35);
}
.bp-toggle {
  width: 100%; border: none; background: transparent; color: var(--text-hi);
  display: flex; align-items: center; gap: 10px; padding: 14px 20px; font-weight: 600;
}
.bp-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); background: #1f2937; }
.bp-chevron { margin-right: auto; transition: transform .25s var(--ease); }
.bottom-panel.is-open .bp-chevron { transform: rotate(180deg); }
.bp-body {
  max-height: 0; overflow: hidden; transition: max-height .3s var(--ease);
  padding: 0 20px;
}
.bottom-panel.is-open .bp-body { max-height: 320px; padding: 0 20px 20px; }
.bp-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; }
.bp-label { width: 78px; flex-shrink: 0; color: var(--text-lo); font-size: .86rem; }
.bp-value { width: 44px; text-align: left; font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--text-lo); }
.range {
  flex: 1; appearance: none; height: 6px; border-radius: 999px; background: var(--ink-700); outline: none;
}
.range::-webkit-slider-thumb {
  appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--turquoise);
  border: 3px solid var(--ink-900); cursor: pointer;
}
.color-controls { display: flex; align-items: center; gap: 10px; flex: 1; }
.color-wheel { width: 42px; height: 42px; border: none; border-radius: 12px; padding: 0; background: none; cursor: pointer; }
.hex-input { flex: 1; padding: 10px 12px; }
.recent-colors { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.swatch {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid rgba(255,255,255,.25); cursor: pointer;
}
.swatch.is-active { border-color: var(--turquoise); }

/* زوم */
.zoom-hud {
  position: absolute; bottom: 96px; left: 16px; z-index: 20;
  background: rgba(27,21,48,.92); border-radius: 14px; padding: 6px;
  display: flex; align-items: center; gap: 4px; box-shadow: var(--shadow-deep);
}
.zoom-value { min-width: 56px; background: transparent; border: none; color: var(--text-hi); font-weight: 600; font-size: .82rem; }

.canvas-loading {
  position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: var(--paper); color: #241d3d;
}

/* ===================== نوار اعلان‌ها ===================== */
.toast-host {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--ink-900); border: 1px solid var(--ink-700); color: var(--text-hi);
  padding: 12px 20px; border-radius: 999px; font-size: .88rem; box-shadow: var(--shadow-deep);
  animation: toastIn .25s var(--ease);
}
.toast.toast--error { border-color: var(--danger); }
.toast.toast--success { border-color: var(--turquoise); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ===================== واکنش‌گرا: موبایل ===================== */
@media (max-width: 720px) {
  .dash-actions { grid-template-columns: 1fr; padding: 18px; }
  .dash-hero { padding: 26px 18px 6px; }
  .dash-list-section { padding: 10px 18px 40px; }

  .toolbar {
    top: auto; bottom: 78px; right: 50%; transform: translateX(50%);
    flex-direction: row; border-radius: 18px; padding: 8px;
    max-width: calc(100vw - 24px); overflow-x: auto;
  }
  .tool-group { flex-direction: row; }
  .tool-divider { width: 1px; height: 28px; margin: 0 2px; }
  .canvas-topbar { padding: 10px 10px; gap: 6px; }
  .canvas-title { display: none; }
  .presence-chip { display: none; }
  .zoom-hud { bottom: 78px; left: 8px; }
  .bp-body { padding: 0 14px; }
  .bottom-panel.is-open .bp-body { padding: 0 14px 16px; }
  .bp-label { width: 60px; font-size: .78rem; }
  .auth-card { padding: 28px 20px; }
}

@media (max-width: 420px) {
  .action-title { font-size: 1.05rem; }
}

/* حالت کاهش حرکت */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* فوکوس قابل مشاهده برای دسترسی‌پذیری */
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--turquoise); outline-offset: 2px;
}

:fullscreen .screen--canvas, :-webkit-full-screen .screen--canvas { background: var(--paper); }
