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

:root {
  color-scheme: dark;
  --ink: #eef1f8;
  --muted: #98a1b8;
  --line: #28304a;
  --accent: #8a6cff;
  --radius: 16px;
  font-family: "Vazirmatn", "IRANSans", "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Sans", system-ui, -apple-system, sans-serif;
}

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

body {
  padding: 22px clamp(14px, 3vw, 36px) 40px;
  color: var(--ink);
  font-size: 15px;
  background:
    radial-gradient(1100px 520px at 88% -12%, #2a2258 0%, transparent 62%),
    radial-gradient(900px 480px at -8% 108%, #103642 0%, transparent 58%),
    #0a0c12;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

body.fs-mode {
  overflow: hidden;
}

.app {
  max-width: 1320px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(138, 108, 255, 0.18), 0 0 18px var(--accent);
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- panel ---------- */

.panel {
  position: sticky;
  top: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(26, 32, 48, 0.94), rgba(18, 22, 33, 0.94));
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

@media (max-width: 900px) {
  .panel {
    position: static;
  }
}

.panel[hidden] {
  display: none;
}

.layout.is-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(40, 48, 74, 0.7);
}

.panel-title {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0e121b;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-btn:hover {
  background: #1d2536;
  color: var(--ink);
  border-color: #354063;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.field-head.sub {
  margin-top: 4px;
}

label,
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: #cfd6e8;
}

output {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.field-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.7;
  color: #7b849c;
}

textarea {
  width: 100%;
  min-height: 76px;
  padding: 11px 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e121b;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.7;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(138, 108, 255, 0.18);
}

/* ---------- direction ---------- */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e121b;
}

.segmented.seg-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.seg-3 .seg {
  padding-inline: 4px;
  font-size: 12.5px;
  gap: 4px;
}

.seg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.seg:hover {
  color: var(--ink);
}

.seg.is-active {
  color: #fff;
  background: linear-gradient(180deg, #7559ec, #5a41cf);
  box-shadow: 0 6px 16px rgba(98, 72, 220, 0.35);
}

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

/* ---------- select ---------- */

select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e121b;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:hover {
  border-color: #354063;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(138, 108, 255, 0.18);
}

select option {
  background: #0e121b;
  color: var(--ink);
  font-size: 14px;
}

/* ---------- ranges ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 99px;
  background: #232a3d;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5.5px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 99px;
  background: #232a3d;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: #fff;
}

/* ---------- colors ---------- */

.colors {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
}

.color-chip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.color-chip input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0e121b;
  cursor: pointer;
}

.color-chip input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 3px;
}

.color-chip input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 7px;
}

.color-chip input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 7px;
}

.swap {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0e121b;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.2s;
}

.swap:hover {
  color: var(--ink);
  border-color: var(--accent);
  transform: rotate(180deg);
}

/* ---------- switch ---------- */

.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #cfd6e8;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}

.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  border-radius: 99px;
  background: #232a3d;
  transition: background 0.18s;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(-18px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- buttons ---------- */

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #161c29;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.btn:hover {
  background: #1d2536;
  border-color: #354063;
}

.btn:active {
  transform: translateY(1px);
}

.btn.is-active {
  border-color: var(--accent);
  color: #cfc3ff;
}

.btn-primary {
  border-color: transparent;
  background: linear-gradient(180deg, #7c5cff, #5f42e0);
  color: #fff;
  box-shadow: 0 10px 24px rgba(102, 74, 235, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #8a6cff, #6a4cec);
  border-color: transparent;
}

:where(button, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hints {
  margin: 0;
  padding-top: 2px;
  font-size: 11.5px;
  line-height: 1.9;
  color: #7b849c;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #10151f;
  font-family: inherit;
  font-size: 10.5px;
  color: #b9c2d8;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  height: min(64vh, max(clamp(200px, 36vh, 330px), calc(var(--fs, 96px) * 1.7)));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg, #0f1117);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.5), 0 26px 60px rgba(0, 0, 0, 0.4);
  isolation: isolate;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.26), transparent 12%, transparent 88%, rgba(0, 0, 0, 0.26));
}

.stage-badge {
  position: absolute;
  top: 12px;
  inset-inline-start: 14px;
  z-index: 3;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  backdrop-filter: blur(6px);
}

.marquee {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
  direction: ltr;
}

/* Static mode: the board is centred and never slides. */
.marquee.is-static {
  justify-content: center;
}

.marquee.is-static .track {
  width: 100%;
  transform-origin: center center;
  will-change: auto;
}

/* A still board wraps instead of clipping, and each repeat gets its own block. */
.marquee.is-static .chunk {
  width: 100%;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: center;
  padding-right: 0;
  text-align: center;
}

.marquee.is-static .item {
  flex: 1 1 100%;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.track {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  width: max-content;
  transform: translateX(0);
  will-change: transform;
}

.chunk {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.7em;
  padding-right: 0.7em;
  white-space: nowrap;
  color: var(--fg, #ffe66d);
  font-family: var(--font, "Vazirmatn"), system-ui, sans-serif;
  font-size: var(--fs, 96px);
  font-weight: 800;
  line-height: 1.25;
  text-shadow: 0 0 32px color-mix(in srgb, var(--fg, #ffe66d) 32%, transparent);
}

.item {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* The flash phase is toggled from JS so it stays in sync with pause/resume. */
.marquee.is-flashing.flash-off .chunk {
  opacity: 0;
}

/* Auto sizing owns the height, so the font it chooses cannot feed back into it. */
.stage.auto-size {
  height: clamp(230px, 40vh, 460px);
}

/* ---------- fullscreen ---------- */

.fs-only {
  display: none !important;
}

.stage.is-fs {
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.stage.is-fs .chunk {
  font-size: max(var(--fs, 96px), 11vh);
}

.stage.is-fs .stage-badge {
  display: none;
}

/* In fullscreen the board is a display, not a document: no drag-selecting the text. */
.stage.is-fs .marquee,
.stage.is-fs .marquee * {
  -webkit-user-select: none;
  user-select: none;
}

.stage.is-fs .fs-only {
  display: inline-flex !important;
}

.stage.is-fs .fs-hint {
  display: block !important;
  animation: hint-fade 4s ease forwards;
}

.btn-exit {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  inset-inline-end: max(16px, env(safe-area-inset-left));
  z-index: 4;
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 99px;
  background: rgba(10, 12, 18, 0.55);
  color: rgba(255, 255, 255, 0.82);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, color 0.15s;
}

.btn-exit:hover {
  background: rgba(10, 12, 18, 0.85);
  color: #fff;
}

.fs-hint {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  background: rgba(10, 12, 18, 0.5);
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  direction: rtl;
  pointer-events: none;
  opacity: 0;
}

@keyframes hint-fade {
  0%,
  65% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage::after {
    backdrop-filter: none;
  }

  .track {
    will-change: auto;
  }
}
