@font-face {
  font-family: "Vazirmatn";
  src: url("/shared/fonts/Vazirmatn-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/shared/fonts/Vazirmatn-Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/shared/fonts/Vazirmatn-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/shared/fonts/Vazirmatn-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/shared/fonts/Vazirmatn-Black.ttf") format("truetype");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Amiri";
  src: url("/shared/fonts/Amiri-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Amiri";
  src: url("/shared/fonts/Amiri-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IranNastaliq";
  src: url("/shared/fonts/IranNastaliq.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Deep Lapis Navy, Illuminated Gold & Vermilion Ink Palette */
:root {
  --stage-bg: #0b1426;
  --paper-center: #162c50;
  --paper-edge: #0c1930;
  --paper-surface: rgba(11, 23, 44, 0.56);
  --paper-surface-strong: rgba(9, 19, 38, 0.78);
  --border-hairline: rgba(216, 180, 104, 0.22);
  --border-subtle: rgba(182, 204, 236, 0.22);
  --border-strong: rgba(216, 180, 104, 0.48);
  --ink-primary: #f7f0e0;
  --ink-sepia: #d4c7af;
  --ink-placeholder: #9cb0ce;
  --lapis: #f0d38c;
  --lapis-deep: #f5dfb0;
  --lapis-tint: rgba(216, 180, 104, 0.14);
  --accent: #c94e33;
  --accent-deep: #f7b89c;
  --accent-tint: rgba(196, 74, 48, 0.22);
  --ink-on-accent: #fcf8ef;
  --gold-trim: #d8b468;
  --error-bg: rgba(185, 60, 42, 0.2);
  --error-border: #e06a52;
  --radius-sm: 8px;
  --radius-md: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  background: var(--paper-center);
  color: var(--ink-primary);
  font-family: "Vazirmatn", system-ui, -apple-system, sans-serif;
  line-height: 1.65;
  overflow: hidden;
}

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

button,
a[href],
select,
summary,
label[for],
[role="button"] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid var(--lapis);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 404px 1fr;
  height: 100dvh;
  width: 100%;
  direction: rtl;
  background: var(--paper-center);
}

/* Deep Lapis Navy Panel */
.panel-wrap {
  order: 1;
  position: relative;
  background: radial-gradient(
    ellipse at 50% 24%,
    #1b3560 0%,
    #132647 58%,
    var(--paper-edge) 100%
  );
  border-left: 1px solid rgba(216, 180, 104, 0.25);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  z-index: 10;
}

.panel-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.14;
  mix-blend-mode: soft-light;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Ccircle cx='42' cy='58' r='0.75' fill='rgb(245,223,176)' fill-opacity='0.35'/%3E%3Ccircle cx='172' cy='96' r='0.6' fill='rgb(245,223,176)' fill-opacity='0.28'/%3E%3Ccircle cx='222' cy='214' r='0.75' fill='rgb(245,223,176)' fill-opacity='0.3'/%3E%3Cpath d='M68 148 q4 -2 8 1' stroke='rgb(245,223,176)' stroke-width='0.55' stroke-opacity='0.24' fill='none'/%3E%3Cpath d='M196 42 q-3 4 2 7' stroke='rgb(245,223,176)' stroke-width='0.55' stroke-opacity='0.24' fill='none'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='p' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.035 0.045' numOctaves='4' seed='7' result='n'/%3E%3CfeDiffuseLighting in='n' lighting-color='rgb(190,210,245)' surfaceScale='1.0' diffuseConstant='0.9'%3E%3CfeDistantLight azimuth='52' elevation='60'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
  background-repeat: repeat, repeat;
  background-size: 260px 260px, 300px 300px;
}

/* Fine Illuminated Gold Margin Frame */
.panel-wrap::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  pointer-events: none;
  z-index: 1;
}

.tab-pane {
  display: none;
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  padding: 26px 24px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(216, 180, 104, 0.3) transparent;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Pre-Open Intro */
.ritual-intro {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ritual-head {
  text-align: right;
  padding-bottom: 2px;
}

.ritual-head h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--lapis-deep);
  margin-bottom: 5px;
  line-height: 1.35;
}

.ritual-head p {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-sepia);
}

.field-group {
  display: flex;
  flex-direction: column;
}

.intention-input {
  width: 100%;
  background: rgba(9, 19, 38, 0.55);
  border: none;
  border-bottom: 1.5px solid rgba(216, 180, 104, 0.45);
  border-radius: 6px 6px 0 0;
  color: var(--ink-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 10px 9px;
  min-height: 44px;
  text-align: right;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.intention-input::placeholder {
  color: var(--ink-placeholder);
}

.intention-input:focus-visible {
  outline: none;
  border-bottom-color: var(--gold-trim);
  background: rgba(9, 19, 38, 0.85);
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip-btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-sepia);
  background: rgba(10, 22, 43, 0.52);
  border: 1px solid rgba(182, 204, 236, 0.24);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  min-height: 38px;
  line-height: 1.3;
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.chip-btn:hover {
  border-color: var(--border-strong);
  background: var(--paper-surface-strong);
  color: var(--ink-primary);
}

.chip-btn.selected {
  border: 1.5px solid var(--gold-trim);
  background: rgba(216, 180, 104, 0.18);
  color: var(--lapis-deep);
  font-weight: 700;
}

/* Primary Deliberate Accent CTA (Vermilion-Cinnabar with Gold Edge) */
.primary-cta {
  width: 100%;
  padding: 12px 18px;
  min-height: 48px;
  border: 1px solid rgba(240, 211, 140, 0.42);
  border-radius: var(--radius-md);
  background: linear-gradient(155deg, #c2492f 0%, #a63a24 55%, #822917 100%);
  color: var(--ink-on-accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 5px 14px rgba(5, 11, 22, 0.45);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.primary-cta:hover {
  filter: brightness(1.06);
}

.primary-cta:active {
  transform: translateY(1px) scale(0.992);
}

.primary-cta.compact {
  padding: 10px 14px;
  font-size: 13.5px;
  min-height: 44px;
}

.secondary-cta {
  width: 100%;
  padding: 10px 14px;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--paper-surface);
  color: var(--lapis-deep);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.secondary-cta:hover {
  background: var(--paper-surface-strong);
  border-color: var(--lapis);
}

.secondary-cta:active {
  transform: scale(0.99);
}

.share-cta {
  width: 100%;
  margin-top: 8px;
  padding: 10px 14px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(184, 138, 68, 0.55);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(184, 138, 68, 0.16), rgba(29, 60, 106, 0.1));
  color: var(--lapis-deep);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.share-cta:hover {
  border-color: var(--lapis);
  background: linear-gradient(135deg, rgba(184, 138, 68, 0.25), rgba(29, 60, 106, 0.16));
}

.share-cta:active {
  transform: scale(0.99);
}

/* Opening Progress State */
.opening-banner,
.error-banner {
  background: var(--paper-surface-strong);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.open-meter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--lapis);
}

.opening-banner h2,
.error-banner h2 {
  font-size: 17px;
  font-weight: 800;
  color: var(--ink-primary);
}

.opening-banner p,
.error-banner p {
  font-size: 13.5px;
  color: var(--ink-sepia);
}

.error-banner {
  background: var(--error-bg);
  border-color: var(--error-border);
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 6px;
  background: rgba(247, 240, 224, 0.14);
  overflow: hidden;
  margin-top: 4px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--lapis), var(--accent));
  transition: width 0.14s linear;
}

/* Revealed Reading Result */
.reading-result {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.result-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-kicker {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--lapis);
}

.ghost-mini-btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-sepia);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  min-height: 36px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ghost-mini-btn:hover {
  background: var(--paper-surface-strong);
  color: var(--ink-primary);
}

.intent-quote {
  border-right: 3px solid var(--accent);
  background: var(--accent-tint);
  border-radius: 8px 0 0 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.intent-line {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-primary);
}

.intent-label {
  color: var(--accent-deep);
  margin-left: 4px;
}

.intent-hook {
  font-size: 13px;
  color: var(--ink-sepia);
}

/* Hero Ghazal Card */
.ghazal-hero {
  background: var(--paper-surface-strong);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 15px 15px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ghazal-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ghazal-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--lapis-deep);
}

.ghazal-tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--lapis-deep);
  background: var(--lapis-tint);
  border: 1px solid rgba(216, 180, 104, 0.34);
  border-radius: 6px;
  padding: 3px 9px;
  white-space: nowrap;
}

.matla-box {
  background: rgba(7, 15, 31, 0.72);
  border: 1px solid rgba(216, 180, 104, 0.36);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.matla-line {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-primary);
  line-height: 1.75;
}

.matla-line.second {
  text-align: left;
  color: var(--lapis);
}

.full-poem-wrap {
  border-top: 1px dashed var(--border-subtle);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 230px;
  overflow-y: auto;
}

.couplet-item {
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--ink-primary);
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(182, 204, 236, 0.12);
}

.couplet-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.poem-expand-btn {
  align-self: flex-start;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--lapis);
  background: transparent;
  border: none;
  padding: 4px 2px;
  min-height: 32px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.poem-expand-btn:hover {
  color: var(--accent);
}

.ghazal-interp {
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink-primary);
}

/* Facets Editorial List (Varied Rhythm, No Bento Clone) */
.facets-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.facet-row {
  border-right: 2.5px solid var(--lapis);
  padding: 5px 11px 5px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.facet-row.advice {
  border-right-color: var(--gold-trim);
  background: rgba(216, 180, 104, 0.12);
  border-radius: 8px 0 0 8px;
  padding: 8px 11px;
}

.facet-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--lapis-deep);
}

.facet-row.advice .facet-label {
  color: #f3d285;
}

.facet-text {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-sepia);
}

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

.panel-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(216, 180, 104, 0.18);
  display: flex;
  justify-content: center;
}

.panel-subtle-link {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--lapis);
  background: transparent;
  border: none;
  padding: 8px 12px;
  min-height: 40px;
}

.panel-subtle-link:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Secondary Pane: Ghazal Catalog */
.catalog-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.catalog-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--lapis-deep);
}

.catalog-state {
  background: var(--paper-surface-strong);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 13.5px;
  color: var(--ink-sepia);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.catalog-state.error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--ink-primary);
}

.catalog-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-bottom: 12px;
}

.catalog-item-btn {
  width: 100%;
  text-align: right;
  font-family: inherit;
  background: var(--paper-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.catalog-item-btn:hover {
  background: var(--paper-surface-strong);
  border-color: var(--lapis);
}

.catalog-item-btn.active {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.catalog-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.catalog-item-title {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--lapis-deep);
}

.catalog-item-tag {
  font-size: 11.5px;
  color: var(--ink-sepia);
}

.catalog-item-matla {
  font-size: 12.5px;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 3D Viewport Stage */
.stage-wrap {
  order: 2;
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--stage-bg);
  overflow: hidden;
}

#hafez-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#hafez-canvas:active {
  cursor: grabbing;
}

.stage-hud-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  pointer-events: none;
}

.hud-actions-top {
  display: flex;
  gap: 9px;
  pointer-events: auto;
}

/* Glass HUD accent strictly capped to floating viewport pill buttons */
.hud-icon-btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-primary);
  background: rgba(16, 33, 62, 0.8);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(247, 240, 224, 0.28);
  border-radius: 999px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(24, 18, 12, 0.22);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.hud-icon-btn:hover {
  background: rgba(20, 42, 77, 0.88);
  border-color: rgba(248, 242, 228, 0.5);
}

.hud-icon-btn:active {
  transform: scale(0.96);
}

.hud-icon-btn[aria-pressed="false"] {
  color: rgba(247, 240, 224, 0.65);
}

.stage-hud-bottom {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.reveal-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  pointer-events: auto;
}

.stage-btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-primary);
  background: rgba(16, 33, 62, 0.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(247, 240, 224, 0.28);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 10px rgba(24, 18, 12, 0.2);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.stage-btn:hover {
  background: rgba(20, 42, 77, 0.9);
  border-color: rgba(248, 242, 228, 0.45);
}

.stage-btn.accent {
  background: rgba(166, 58, 36, 0.88);
  border-color: rgba(248, 242, 228, 0.38);
}

.orbit-hint {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-primary);
  background: rgba(16, 33, 62, 0.78);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(216, 180, 104, 0.3);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.orbit-hint.is-dismissed {
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill,
  .chip-btn,
  .primary-cta,
  .secondary-cta,
  .stage-btn,
  .orbit-hint {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 356px 1fr;
  }
}

@media (max-width: 820px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--paper-center);
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(340px, 52dvh) auto;
    height: auto;
    min-height: 100dvh;
  }

  .stage-wrap {
    order: 1;
    height: 52dvh;
    min-height: 340px;
  }

  .panel-wrap {
    order: 2;
    height: auto;
    margin-top: -24px;
    border-left: none;
    border-top: 1px solid rgba(216, 180, 104, 0.38);
    border-radius: 26px 26px 0 0;
    box-shadow: 0 -10px 28px rgba(7, 14, 28, 0.42);
  }

  .panel-wrap::after {
    inset: 9px;
    border-radius: 18px 18px 6px 6px;
  }

  .tab-pane {
    overflow-y: visible;
    padding: 20px 18px 20px;
  }

  .ritual-head h1 {
    font-size: 20px;
  }

  .btn-mini-label {
    display: none;
  }

  .hud-icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
  }

  .stage-hud-top {
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }

  .stage-hud-bottom {
    bottom: 34px;
    left: 12px;
    right: 12px;
    gap: 6px;
  }

  .stage-btn {
    font-size: 11.5px;
    padding: 7px 12px;
    min-height: 40px;
  }
}
