:root {
  --bg: #0f1419;
  --bg-elevated: #1a2332;
  --bg-soft: #243044;
  --border: #2d3a4f;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --primary: #3d9cf0;
  --primary-hover: #5aadf5;
  --secondary: #2a9d8f;
  --secondary-hover: #34b3a3;
  --danger: #e76f51;
  --success: #52b788;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "Vazirmatn", "Tahoma", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
}

@font-face {
  font-family: "Vazirmatn";
  src: local("Vazirmatn"), local("Vazir");
  font-display: swap;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 156, 240, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(42, 157, 143, 0.14), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3rem;
}

.hero {
  text-align: center;
  margin-bottom: 2rem;
}

.brand {
  display: inline-block;
  margin-bottom: 0.75rem;
  line-height: 0;
}

.logo-img {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: block;
  margin: 0 auto;
}

.logo-img-sm {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin-bottom: 0.75rem;
}

.brand-mini {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}

.brand-mini img {
  width: 36px;
  height: 36px;
  display: block;
  border-radius: 10px;
}

.logo-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.75rem;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: var(--shadow);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.howto {
  margin-top: 1rem;
}

.howto h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.howto-sub {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
  color: var(--text);
}

.howto-list {
  margin: 0;
  padding-inline-start: 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.howto-list li {
  margin-bottom: 0.35rem;
}

.howto-list strong {
  color: var(--text);
}

.howto-plain {
  list-style: disc;
}

.footer-meta {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.footer-meta .dot {
  opacity: 0.5;
}

.hero h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--muted);
  margin: 0.5rem 0 0;
}

.cards {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .cards {
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.muted {
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: 0.92rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #041018;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  color: #041018;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.btn-ghost:hover {
  background: var(--bg-soft);
}

.join-form {
  display: grid;
  gap: 0.75rem;
}

.code-input {
  width: 100%;
  text-align: center;
  font-family: var(--mono);
  font-size: 1.6rem;
  letter-spacing: 0.35em;
  padding: 0.75rem 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  direction: ltr;
}

.code-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(61, 156, 240, 0.2);
}

.error {
  color: var(--danger);
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2rem;
}

.center-card {
  max-width: 420px;
  margin: 4rem auto;
  text-align: center;
}

/* Room */
.room-body {
  height: 100vh;
  overflow: hidden;
}

.room-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.room-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: color-mix(in srgb, var(--bg-elevated) 95%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.back-link {
  color: var(--muted);
  font-size: 1.2rem;
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
}

.back-link:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.room-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.room-meta .label {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

.room-code {
  font-family: var(--mono);
  font-size: 1.15rem;
  letter-spacing: 0.12em;
}

.room-actions {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dir-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
}

.dir-panel-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
}

.dir-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
}

.dir-toggle .dir-btn {
  border: none;
  border-radius: 0;
  border-inline-end: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  min-width: 4.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  line-height: 1.15;
  height: auto;
}

.dir-toggle .dir-btn:last-child {
  border-inline-end: none;
}

.dir-btn-title {
  font-weight: 700;
  font-size: 0.78rem;
}

.dir-btn-desc {
  font-weight: 500;
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
}

.dir-toggle .dir-btn.is-active {
  background: var(--bg-soft);
  color: var(--primary);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 35%, transparent);
}

.dir-toggle .dir-btn.is-active .dir-btn-desc {
  color: color-mix(in srgb, var(--primary) 80%, var(--muted));
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.status.saving { color: var(--primary); }
.status.saved { color: var(--success); }
.status.error { color: var(--danger); }
.status.sync { color: var(--secondary); }

.editor-wrap {
  min-height: 0;
  padding: 0.75rem;
}

.editor {
  width: 100%;
  height: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.75;
  padding: 1rem 1.1rem;
  outline: none;
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

/* Manual / auto direction */
.editor[dir="rtl"] {
  direction: rtl;
  text-align: right;
  unicode-bidi: embed;
}

.editor[dir="ltr"] {
  direction: ltr;
  text-align: left;
  unicode-bidi: embed;
}

.editor[dir="auto"] {
  direction: auto;
  text-align: start;
  unicode-bidi: plaintext;
}

.editor:focus {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
  box-shadow: 0 0 0 3px rgba(61, 156, 240, 0.12);
}

@media (max-width: 640px) {
  .room-bar {
    flex-wrap: wrap;
  }

  .room-actions {
    width: 100%;
    margin-inline-start: 0;
    justify-content: space-between;
  }

  .status {
    display: none;
  }
}

.room-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem 0.7rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 90%, transparent);
}

.room-footer .dot {
  opacity: 0.5;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 18, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.modal-actions {
  display: grid;
  gap: 0.6rem;
  margin-top: 1rem;
}

@media (min-width: 480px) {
  .modal-actions {
    grid-template-columns: 1fr 1fr;
  }
}
