:root {
  --bg: #07090f;
  --surface: #101522;
  --surface-2: #161d2e;
  --ink: #f3f6fb;
  --muted: #93a0b8;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #3ee0b8;
  --accent-ink: #04241c;
  --warn: #f5c56b;
  --danger: #f0a3a3;
  --space: 8px;
  --radius: 12px;
  --max: 1120px;
  --tap: 44px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-s: max(16px, env(safe-area-inset-left, 0px));
  --safe-e: max(16px, env(safe-area-inset-right, 0px));
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "IBM Plex Sans Arabic", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.skip {
  position: absolute;
  inset-inline-start: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  z-index: 20;
}
.skip:focus { top: 12px; }

.mesh {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px),
    radial-gradient(900px 420px at 100% -10%, #16324a 0%, transparent 55%),
    radial-gradient(720px 380px at 0% 0%, #12362f 0%, transparent 50%),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto, auto;
}

.shell {
  width: min(var(--max), 100%);
  margin: 0 auto;
  padding: calc(24px + var(--safe-t)) var(--safe-e) calc(40px + var(--safe-b)) var(--safe-s);
}

.head { display: grid; gap: 12px; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--accent), #1aa888);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
  flex: 0 0 32px;
}
.kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.lede {
  margin: 0;
  max-width: 62ch;
  color: var(--muted);
  font-size: 15px;
}
.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.status-row .ghost {
  width: auto;
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.chip {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.chip.quiet { background: transparent; }
.chip.cloud-ok { color: var(--accent); border-color: rgba(62, 224, 184, 0.35); }
.chip.cloud-err { color: var(--danger); border-color: rgba(240, 163, 163, 0.35); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0 0 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.tab, button, .ghost, a.ghost {
  font: inherit;
  cursor: pointer;
}
.tab {
  min-height: var(--tap);
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.tab.on {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.panel { display: none; }
.panel.on { display: block; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-head { margin-bottom: 12px; }
.card-head h2, .rules h2, .result-bar h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}
.card-head p, .mini {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

label {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
textarea, input {
  width: 100%;
  min-height: var(--tap);
  background: #0b101c;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  outline: none;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.55; }
#jd { direction: ltr; text-align: left; }
#file-editor {
  min-height: min(52vh, 520px);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  direction: ltr;
  text-align: left;
  line-height: 1.55;
}
textarea:focus, input:focus, .tab:focus-visible, button:focus-visible, a:focus-visible {
  box-shadow: 0 0 0 3px rgba(62, 224, 184, 0.28);
  border-color: rgba(62, 224, 184, 0.55);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.actions.wrap { row-gap: 10px; }

.primary, .ghost {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
  border: 0;
}
.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.primary:disabled { opacity: 0.55; cursor: wait; }
.think {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-radius: var(--radius);
  font-weight: 700;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(62, 224, 184, 0.42);
}
.think.busy {
  background: rgba(62, 224, 184, 0.16);
  border-color: var(--accent);
  color: var(--ink);
}
.think:disabled { opacity: 0.55; cursor: wait; }
.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.hint { margin: 0; color: var(--muted); font-size: 13px; }

.rules ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}
.rules li {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
  counter-increment: step;
}
.rules li strong { color: var(--ink); font-weight: 650; }
.notes {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  background: #241c10;
  color: var(--warn);
  white-space: pre-wrap;
  font-size: 13px;
}
.hidden, [hidden] { display: none !important; }

.result {
  margin-top: 16px;
  padding: 0;
  overflow: hidden;
}
.result-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.danger {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: var(--radius);
  font-weight: 700;
  border: 1px solid rgba(240, 163, 163, 0.35);
  background: #2a1518;
  color: var(--danger);
}
.editor {
  padding: 16px 20px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.editor select {
  width: 100%;
  min-height: var(--tap);
  background: #0b101c;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  font: inherit;
}
.edit-label {
  margin: 16px 0 8px;
  font-size: 13px;
  color: var(--muted);
}
.edit-list {
  display: grid;
  gap: 10px;
}
.edit-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.edit-item textarea { min-height: 72px; }
.edit-item .locked {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.preview-frame {
  overflow: hidden;
  background: #cfd6e2;
  width: 100%;
  direction: ltr;
}
.preview-scale {
  width: 794px;
  height: 1123px;
  transform-origin: top left;
}
.preview-scale iframe {
  width: 794px;
  height: 1123px;
  min-width: 0;
  border: 0;
  background: #fff;
  display: block;
}

.file-tabs, .picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.file-tabs button, .picker button {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b101c;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
.file-tabs button.on, .picker button.on {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
}
.picker { grid-template-columns: repeat(3, 1fr); }

.form { display: grid; }
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(16px + var(--safe-b));
  max-width: 420px;
  margin-inline: auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: #121a14;
  color: var(--accent);
  border: 1px solid rgba(62, 224, 184, 0.3);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
  z-index: 30;
  text-align: center;
}
.toast.show { opacity: 1; transform: none; }

@media (max-width: 860px) {
  .layout, .pair { grid-template-columns: 1fr; }
  .file-tabs { grid-template-columns: 1fr 1fr; }
  .tab { font-size: 13px; padding: 0 6px; }
}

@media (max-width: 560px) {
  .shell { padding-top: calc(16px + var(--safe-t)); }
  .card { padding: 16px; }
  .primary, .ghost, .think { width: 100%; }
  .actions .hint { width: 100%; }
  .result-bar { flex-direction: column; align-items: stretch; }
  .result-actions .ghost, .result-actions .danger, .result-actions .primary { flex: 1 1 calc(50% - 8px); width: auto; }
}

.gate-body { min-height: 100dvh; }
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) var(--safe-e) calc(24px + var(--safe-b)) var(--safe-s);
}
.gate-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
}
.gate-card .lede { margin: 0; color: var(--muted); }
.gate-card input[type="password"] {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b101c;
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}
.gate-card .primary { width: 100%; }
.head-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

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