@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-Black.ttf") format("truetype");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

/* Handmade Cafe Paper & Espresso Ink Tokens (No pure black) */
:root {
  --bg-canvas: #160e09;
  --paper-center: #f7f1e6;
  --paper-edge: #ece1ce;
  --paper-surface: rgba(255, 251, 244, 0.56);
  --paper-surface-strong: rgba(255, 251, 244, 0.82);
  --border-hairline: rgba(107, 86, 69, 0.16);
  --border-subtle: rgba(107, 86, 69, 0.24);
  --border-strong: rgba(107, 86, 69, 0.48);
  --ink-primary: #2a1c14;
  --ink-sepia: #6b5645;
  --ink-placeholder: #7c6553;
  --accent: #85381f;
  --accent-deep: #652a17;
  --accent-tint: rgba(133, 56, 31, 0.09);
  --ink-on-accent: #fcf7ee;
  --error-bg: rgba(168, 58, 40, 0.08);
  --error-border: #9e3d28;
  --font-literary: "Vazirmatn", system-ui, -apple-system, sans-serif;
  --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.6;
  overflow: hidden;
}

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(--accent);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

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

/* Handmade Paper Panel (3-layer texture + hairline frame) */
.panel-wrap {
  order: 1;
  position: relative;
  /* Layer 1: Soft warm gradient from milky cream center to slightly aged edge */
  background: radial-gradient(
    ellipse at 50% 35%,
    var(--paper-center) 0%,
    #f2e9d8 58%,
    var(--paper-edge) 100%
  );
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  z-index: 10;
}

/* Layer 2 + 3: SVG feTurbulence + feDiffuseLighting paper tooth & recycled fiber flecks */
.panel-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.25;
  mix-blend-mode: multiply;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='280' height='280'%3E%3Ccircle cx='34' cy='52' r='0.75' fill='rgb(107,86,69)' fill-opacity='0.28'/%3E%3Ccircle cx='178' cy='94' r='0.6' fill='rgb(92,68,48)' fill-opacity='0.22'/%3E%3Ccircle cx='242' cy='208' r='0.8' fill='rgb(107,86,69)' fill-opacity='0.24'/%3E%3Ccircle cx='96' cy='226' r='0.55' fill='rgb(122,94,68)' fill-opacity='0.25'/%3E%3Cpath d='M62 142 q4 -2 9 1' stroke='rgb(107,86,69)' stroke-width='0.6' stroke-opacity='0.22' fill='none'/%3E%3Cpath d='M210 38 q-3 4 2 7' stroke='rgb(107,86,69)' stroke-width='0.55' stroke-opacity='0.2' fill='none'/%3E%3Cpath d='M132 252 q5 1 8 -2' stroke='rgb(92,68,48)' stroke-width='0.55' stroke-opacity='0.2' fill='none'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='paper' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.036 0.044' numOctaves='4' seed='11' result='noise'/%3E%3CfeDiffuseLighting in='noise' lighting-color='rgb(255,248,236)' surfaceScale='1.15' diffuseConstant='1.05'%3E%3CfeDistantLight azimuth='48' elevation='58'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paper)'/%3E%3C/svg%3E");
  background-repeat: repeat, repeat;
  background-size: 280px 280px, 320px 320px;
}

/* Inner hairline frame like a printed cafe menu card */
.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(107, 86, 69, 0.25) transparent;
}

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

/* Pre-pour Intro (De-bureaucratized Journal Style) */
.ritual-intro {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.ritual-head h1 {
  font-family: var(--font-literary);
  font-size: 22px;
  font-weight: 800;
  color: var(--ink-primary);
  margin-bottom: 4px;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

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

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

.intention-input {
  width: 100%;
  background: rgba(255, 251, 244, 0.34);
  border: none;
  border-bottom: 1.5px solid rgba(107, 86, 69, 0.38);
  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(--accent);
  background: rgba(255, 251, 244, 0.68);
}

/* Delicate Paper Tags with Ink-Stamp Selected State */
.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-sepia);
  background: rgba(255, 251, 244, 0.42);
  border: 1px solid rgba(107, 86, 69, 0.24);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
  line-height: 1.3;
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.chip-btn:hover {
  border-color: rgba(107, 86, 69, 0.45);
  background: rgba(255, 251, 244, 0.72);
  color: var(--ink-primary);
}

.chip-btn.selected {
  border: 1.5px solid rgba(133, 56, 31, 0.72);
  background: var(--accent-tint);
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(133, 56, 31, 0.14);
}

/* Tactile Terracotta-Espresso Gradient CTA */
.primary-cta {
  width: 100%;
  padding: 12px 18px;
  min-height: 48px;
  border: 1px solid var(--accent-deep);
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, #98462a 0%, #7f361e 55%, #652a17 100%);
  color: var(--ink-on-accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  box-shadow:
    0 6px 16px rgba(68, 30, 16, 0.28),
    inset 0 1px 0 rgba(255, 242, 228, 0.2);
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.primary-cta:hover {
  filter: brightness(1.05);
  box-shadow:
    0 8px 18px rgba(68, 30, 16, 0.32),
    inset 0 1px 0 rgba(255, 242, 228, 0.24);
}

.primary-cta:active {
  transform: translateY(1.5px) scale(0.992);
  box-shadow: 0 2px 7px rgba(68, 30, 16, 0.26);
}

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

.secondary-cta {
  width: 100%;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--paper-surface);
  color: var(--accent);
  font-family: inherit;
  font-size: 13px;
  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(--accent);
}

.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-radius: var(--radius-sm);
  border: 1px solid rgba(133, 56, 31, 0.42);
  background: linear-gradient(135deg, rgba(184, 118, 62, 0.14), rgba(133, 56, 31, 0.08));
  color: var(--accent);
  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(--accent);
  background: linear-gradient(135deg, rgba(184, 118, 62, 0.24), rgba(133, 56, 31, 0.14));
}

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

/* Pouring Progress & Error States */
.pouring-banner {
  background: var(--paper-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

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

.pouring-banner h2 {
  font-family: var(--font-literary);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink-primary);
}

.pouring-banner p {
  font-size: 13px;
  color: var(--ink-sepia);
}

.progress-track {
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: rgba(107, 86, 69, 0.16);
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #98462a, #652a17);
  transition: width 0.08s linear;
}

.error-banner {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

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

/* Post-Pour Reading Result (Printed Literary Ink on Paper) */
.reading-result {
  display: flex;
  flex-direction: column;
  gap: 13px;
  animation: fadeSlideUp 0.28s ease;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-hairline);
}

.result-kicker {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--accent);
}

.ghost-mini-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-primary);
  background: var(--paper-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

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

.intent-quote {
  background: var(--paper-surface);
  border-right: 2.5px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-literary);
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-primary);
}

.intent-label {
  font-family: "Vazirmatn", sans-serif;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 800;
  margin-left: 5px;
}

.intent-hook {
  margin-top: 4px;
  color: var(--ink-sepia);
  font-size: 13.5px;
}

.symbol-hero {
  background: var(--paper-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 15px;
}

.symbol-meta {
  margin-bottom: 2px;
}

.card-loc {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-sepia);
}

.symbol-title {
  font-family: var(--font-literary);
  font-size: 21px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
  line-height: 1.35;
}

.symbol-body {
  font-family: var(--font-literary);
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ink-primary);
}

.symbol-secondary {
  border-top: 1px solid var(--border-hairline);
  border-bottom: 1px solid var(--border-hairline);
  padding: 11px 2px;
}

.symbol-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.symbol-tag {
  font-family: var(--font-literary);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink-primary);
}

.cup-mood-note {
  padding: 2px 2px 0;
}

.mood-title {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 3px;
}

.cup-mood-note p {
  font-family: var(--font-literary);
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-sepia);
}

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

/* Centered, Underline-Free Sepia Footer Link */
.panel-footer {
  margin-top: 4px;
  padding-top: 2px;
  display: flex;
  justify-content: center;
}

.panel-subtle-link {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-sepia);
  background: transparent;
  border: none;
  padding: 6px 12px;
  text-decoration: none;
  transition: color 0.15s ease;
}

.panel-subtle-link:hover {
  color: var(--accent);
}

/* Symbols Reference Pane */
.lab-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-hairline);
}

.lab-title {
  font-family: var(--font-literary);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink-primary);
}

.lab-sub {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-sepia);
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.sym-test-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-primary);
  background: var(--paper-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.sym-test-btn:hover {
  border-color: var(--border-strong);
  background: var(--paper-surface-strong);
}

.sym-test-btn.active {
  border-color: var(--accent-deep);
  background: linear-gradient(145deg, #98462a 0%, #652a17 100%);
  color: var(--ink-on-accent);
  font-weight: 800;
}

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

/* Soft top/bottom vignette for cinematic lighting on cup */
.stage-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    to bottom,
    rgba(16, 9, 5, 0.36) 0%,
    rgba(16, 9, 5, 0) 20%,
    rgba(16, 9, 5, 0) 76%,
    rgba(16, 9, 5, 0.46) 100%
  );
}

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

#coffee-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;
}

/* Circular Dark Espresso Glassmorphism Buttons */
.hud-icon-btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #f4ebd9;
  background: rgba(28, 17, 11, 0.52);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(247, 241, 230, 0.22);
  border-radius: 999px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  min-width: 42px;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(14, 8, 4, 0.28);
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
}

.hud-icon-btn:hover {
  background: rgba(42, 25, 16, 0.72);
  border-color: rgba(247, 241, 230, 0.42);
}

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

.hud-icon-btn[aria-pressed="true"] {
  background: rgba(46, 26, 16, 0.72);
  border-color: rgba(247, 236, 214, 0.5);
  color: #f9efdd;
}

.hud-icon-btn[aria-pressed="false"] {
  color: rgba(244, 235, 217, 0.68);
}

.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: #f4ebd9;
  background: rgba(28, 17, 11, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(247, 241, 230, 0.2);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(14, 8, 4, 0.26);
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.stage-btn:hover {
  background: rgba(44, 27, 17, 0.78);
  border-color: rgba(247, 241, 230, 0.42);
}

.stage-btn.accent {
  border-color: rgba(244, 224, 196, 0.42);
  color: #f7e9d2;
}

.stage-btn.accent.active {
  background: linear-gradient(145deg, #98462a 0%, #652a17 100%);
  border-color: rgba(247, 232, 212, 0.45);
  color: var(--ink-on-accent);
  font-weight: 800;
}

.orbit-hint {
  font-size: 11.5px;
  font-weight: 500;
  color: rgba(247, 241, 230, 0.9);
  background: rgba(24, 15, 9, 0.56);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid rgba(247, 241, 230, 0.16);
  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) {
  .reading-result,
  .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: 352px 1fr;
  }
}

/* Mobile Responsive: Overlapping Thick Paper Card Over Wooden Table */
@media (max-width: 820px) {
  html,
  body {
    overflow: auto;
    background: var(--paper-center);
  }

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

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

  .panel-wrap {
    order: 2;
    height: auto;
    margin-top: -24px;
    border-left: none;
    border-top: 1px solid rgba(255, 250, 242, 0.65);
    border-radius: 28px 28px 0 0;
    box-shadow:
      0 -12px 32px rgba(24, 14, 7, 0.38),
      0 -2px 10px rgba(24, 14, 7, 0.18);
  }

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

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

  .tab-pane.active {
    gap: 12px;
  }

  .ritual-intro {
    gap: 12px;
  }

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

  .ritual-head p {
    font-size: 12.5px;
  }

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

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

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

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

  /* Raised above the -24px overlapping paper card */
  .stage-hud-bottom {
    bottom: 34px;
    left: 12px;
    right: 12px;
    gap: 6px;
  }

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

  .orbit-hint {
    font-size: 11px;
    padding: 4px 11px;
  }
}
