/*
 * Chat simulator page (/simulador/, docs/plans/plan-043-chat-simulator.md).
 *
 * .sim-*  the page around the phone (IARA brand).
 * .ws-*   the simulated phone screen: a recreation of the current iOS chat
 *         app design (light mode), sized in iOS points (1 CSS px = 1 pt).
 * .kb-*   the fake iOS keyboard inside the screen (pointer devices only).
 */

@font-face {
  font-family: "Funnel Display";
  src: url("../fonts/FunnelDisplay-VariableFont_wght.ttf") format("truetype");
  font-weight: 300 800;
  font-display: swap;
}

:root {
  --sim-bg: #002e10;
  --sim-bg-glow: #0e5228;
  --sim-text: #eef3ea;
  --sim-muted: rgba(238, 243, 234, 0.72);
  --sim-accent: #d4ff00;
  --sim-font: "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --sim-display: "Funnel Display", var(--sim-font);
}

/* Global rules stay on the /simulador/ page: this stylesheet also loads on
   the home, for its embedded simulator. */
.sim-page *,
.sim-page *::before,
.sim-page *::after,
.sim-embed *,
.sim-embed *::before,
.sim-embed *::after {
  box-sizing: border-box;
}

body.sim-page {
  margin: 0;
  color-scheme: dark;
  min-height: 100vh;
  /* The 3D layers reach past the column; never a sideways scrollbar. */
  overflow-x: clip;
  background:
    radial-gradient(900px 700px at 72% 45%, var(--sim-bg-glow) 0%, rgba(14, 82, 40, 0) 70%),
    radial-gradient(1200px 900px at 10% 0%, #053d18 0%, rgba(5, 61, 24, 0) 60%),
    var(--sim-bg);
  color: var(--sim-text);
  font-family: var(--sim-font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Page ---------- */

.sim-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 32px;
}

.sim-home {
  display: inline-flex;
  border-radius: 8px;
}

.sim-home img {
  display: block;
  height: 26px;
  width: auto;
}

.sim-home:focus-visible {
  outline: 2px solid var(--sim-accent);
  outline-offset: 4px;
}

/* Eyebrow: the landing's section eyebrow (Funnel Display, small caps). */
.sim-eyebrow {
  color: rgba(238, 243, 234, 0.7);
  font-family: var(--sim-display);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

/* "Simulação interativa": a quiet glass chip with a live dot. */
.sim-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: rgba(238, 243, 234, 0.9);
  font-family: var(--sim-display);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
}

.sim-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sim-accent);
  box-shadow: 0 0 0 3px rgba(212, 255, 0, 0.16);
  animation: sim-live 2.4s ease-in-out infinite;
}

@keyframes sim-live {
  50% {
    box-shadow: 0 0 0 5px rgba(212, 255, 0, 0.04);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sim-chip-dot {
    animation: none;
  }
}

.sim-main {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(440px, 1.15fr);
  align-items: center;
  gap: 40px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 32px 24px;
}

.sim-copy {
  max-width: 470px;
}

.sim-eyebrow {
  margin: 0 0 18px;
}

.sim-copy h1 {
  margin: 0 0 18px;
  font-family: var(--sim-display);
  font-size: clamp(2.4rem, 1.4rem + 2.6vw, 3.9rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1;
}

.sim-lead {
  margin: 0 0 18px;
  color: var(--sim-muted);
  font-size: clamp(1.05rem, 0.95rem + 0.35vw, 1.25rem);
  line-height: 1.5;
}

.sim-disclaimer {
  margin: 0;
  color: rgba(238, 243, 234, 0.55);
  font-size: 0.875rem;
  line-height: 1.45;
}

.sim-noscript {
  max-width: 600px;
  margin: 24px auto;
  padding: 0 32px;
}

/* The phone's area and its caption below: the caption has its own row, so
   the phone (fitted to the stage) never runs into it. */
/* Sized from the vertical space: the phone is about the stage's height. */
.sim-device {
  display: flex;
  flex-direction: column;
  height: min(calc(100svh - 66px), 1024px);
  min-height: 560px;
}

.sim-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  user-select: none;
  -webkit-user-select: none;
}

html.sim-dragging,
html.sim-dragging * {
  -webkit-user-select: none !important;
  user-select: none !important;
  cursor: grabbing !important;
}

/* The home's embed on phones: vertical swipes scroll the page (phone3d.ts
   turns the phone on horizontal drags only). */
.sim-embed .sim-stage.is-3d {
  touch-action: pan-y;
}

/* Over the phone where it overflows the stage (phone3d.ts). */
html.sim-grab-hover,
html.sim-grab-hover * {
  cursor: grab !important;
}

.sim-stage.is-3d {
  cursor: grab;
  /* Drags that start on the stage turn the phone; inside the screen they
     scroll the chat as usual. */
  touch-action: none;
}

.sim-stage.is-3d .ws-host {
  touch-action: auto;
}

.sim-stage.is-dragging {
  cursor: grabbing;
}

/* The floor shadow under the phone (sized by phone3d.ts): a wide soft
   penumbra (::before) and a dense contact core near the phone's lowest
   point (::after), both centered --shadow-y above the stage's bottom. */
.sim-stage {
  --shadow-color: 0, 0, 0;
  --shadow-strength: 0.5;
  --shadow-core: 0.55;
}

/* Placed with transforms from a fixed corner (the stage's bottom left):
   following the phone never counts as a layout shift. */
.sim-stage::before,
.sim-stage::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  width: var(--shadow-width, 300px);
  height: var(--shadow-depth, 40px);
  transform: translate(calc(var(--shadow-x, 50%) - 50%), calc(-1 * var(--shadow-y, 26px) - 50%));
  border-radius: 50%;
  opacity: var(--shadow-opacity, 1);
  pointer-events: none;
}

.sim-stage::before {
  background: radial-gradient(closest-side, rgba(var(--shadow-color), var(--shadow-strength)) 20%, rgba(var(--shadow-color), 0));
  filter: blur(var(--shadow-blur, 8px));
}

.sim-stage::after {
  width: calc(var(--shadow-width, 300px) * 0.7);
  height: calc(var(--shadow-depth, 40px) * 0.4);
  transform: translate(calc(var(--shadow-x, 50%) - 50%), calc(-1 * var(--shadow-y, 26px) + var(--shadow-depth, 40px) * 0.3 - 50%));
  background: radial-gradient(closest-side, rgba(var(--shadow-color), var(--shadow-core)), rgba(var(--shadow-color), 0));
  filter: blur(calc(var(--shadow-blur, 8px) * 0.4));
}

/* The 3D layers: larger than the stage (centered on it), so a turning phone
   is never cut off; they ignore the pointer except on the screen itself, so
   the page around stays usable. */
.sim-render {
  position: absolute;
  inset: -18% -45%;
  z-index: 2;
  pointer-events: none;
}

.sim-css3d,
.sim-canvas {
  position: absolute;
  inset: 0;
}

/* Sized and placed by phone3d.ts (centered on the stage). */
.sim-css3d {
  right: auto;
  bottom: auto;
}

.sim-css3d {
  z-index: 1;
  pointer-events: none;
}

/* The CSS3D object: a plain box the size of the screen (see phone3d.ts). */
.sim-screen-3d {
  width: 402px;
  height: 874px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.sim-css3d .sim-screen-3d,
.sim-css3d .ws-host {
  pointer-events: auto;
}

.sim-canvas {
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sim-flat {
  position: absolute;
  inset: 0;
}

.is-loading-3d .sim-flat {
  visibility: hidden;
}

.is-3d .sim-flat {
  display: none;
}

.sim-flat-frame {
  padding: 12px;
  border-radius: 67px;
  background: linear-gradient(160deg, #2b2b2d, #0c0c0d);
  box-shadow:
    0 0 0 2px #b9b4ab,
    0 0 0 4px #77736b,
    0 40px 90px rgba(0, 0, 0, 0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(var(--flat-scale, 1));
  transform-origin: center;
}

/* Under the phone: the chips side by side, the drag hint on its own line
   below (smaller, muted; it fades out for good after the first turn). */
.sim-caption {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  box-sizing: border-box;
  height: 80px;
  margin: 0;
  /* Some air between the phone and the chips. */
  padding-top: 16px;
}

.sim-caption-chips {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.sim-drag-hint {
  visibility: hidden;
  color: rgba(238, 243, 234, 0.5);
  font-size: 0.75rem;
  transition: opacity 0.4s ease;
}

.sim-stage.is-3d ~ .sim-caption .sim-drag-hint {
  visibility: visible;
}

.sim-stage.has-turned ~ .sim-caption .sim-drag-hint {
  opacity: 0;
}

@media (max-width: 1000px) {
  .sim-main {
    grid-template-columns: 1fr;
  }

  .sim-copy {
    max-width: 640px;
    margin: 12px auto 0;
    text-align: center;
  }
}

/* Phones: the chat itself, full screen, under a slim bar. */
html.sim-full,
html.sim-full body.sim-page {
  height: 100%;
  overflow: hidden;
  /* No pull-to-refresh: pulling down to drop the keyboard would reload. */
  overscroll-behavior: none;
}

/* Under the fixed page (around the keyboard and Safari's toolbar): the
   composer bar's color, not the page's dark green. */
html.sim-full {
  background: #f3f1ec;
}

html.sim-full body.sim-page {
  /* Safari 26 tints its bars from the fixed element at each edge (here the
     body), not from theme-color: the composer bar's color, so the area
     around the keyboard and the bottom toolbar continues the composer. */
  background: #f3f1ec;
  position: fixed;
  inset: var(--sim-vtop, 0) 0 auto;
  height: var(--sim-vh, 100dvh);
  /* The page's 100vh minimum is iOS's large viewport (toolbar hidden): it
     would push the composer under Safari's toolbar and the keyboard. */
  min-height: 0;
  display: flex;
  flex-direction: column;
}

html.sim-full .sim-header {
  width: 100%;
  /* Its own green: the full-screen body is the composer's color (below).
     Sticky, so Safari takes the top bar's tint from it. */
  position: sticky;
  top: 0;
  z-index: 1;
  background:
    radial-gradient(1200px 900px at 10% 0%, #053d18 0%, rgba(5, 61, 24, 0) 60%),
    var(--sim-bg);
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
}

html.sim-full .sim-home img {
  height: 20px;
}

html.sim-full .sim-main {
  display: block;
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 0;
}

html.sim-full .sim-copy {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

html.sim-full .sim-device {
  height: 100%;
  min-height: 0;
}

html.sim-full .sim-stage::before,
html.sim-full .sim-stage::after,
html.sim-full .sim-caption {
  display: none;
}

html.sim-full .sim-flat {
  inset: 0;
  display: block;
}

html.sim-full .sim-flat-frame,
html.sim-full .sim-screen-slot {
  position: static;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  transform: none;
}

.sim-finger {
  position: fixed;
  top: -12px;
  left: -12px;
  z-index: 2147483600;
  width: 24px;
  height: 24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.sim-finger::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(110, 110, 118, 0.3);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition:
    transform 0.18s cubic-bezier(0.32, 0.72, 0, 1),
    background 0.18s,
    box-shadow 0.18s;
}

.sim-finger.is-shown {
  opacity: 1;
}

.sim-finger.is-hover::before {
  transform: scale(1.3);
  background: rgba(69, 166, 99, 0.22);
  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.3),
    0 0 14px rgba(69, 166, 99, 0.45),
    0 1px 4px rgba(0, 0, 0, 0.18);
}

.sim-finger.is-down::before {
  transform: scale(0.72);
  background: rgba(60, 60, 68, 0.45);
}

/* The header chip only shows on phones, where the page copy is hidden. */
.sim-header-chip {
  display: none;
}

html.sim-full .sim-header-chip {
  display: inline-flex;
}

/* Spam check modal (page level, never transformed; see challenge-modal.ts). */
.sim-challenge-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 20, 8, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.sim-challenge-backdrop[hidden] {
  display: none;
}

.sim-challenge {
  width: 360px;
  max-width: 100%;
  padding: 22px 22px 20px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  background: rgba(10, 52, 26, 0.82);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 30px 80px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  color: var(--sim-text);
  font-family: var(--sim-font);
  outline: none;
}

.sim-challenge-title {
  margin: 0 0 6px;
  font-family: var(--sim-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sim-challenge-text {
  margin: 0 0 16px;
  color: var(--sim-muted);
  font-size: 0.9375rem;
  line-height: 1.45;
}

.sim-challenge-slot {
  width: 316px;
  max-width: 100%;
  height: 81px;
  margin: 0 auto;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}

/* Switching layouts (main.ts animates the move, FLIP-style). */
.sim-render,
.sim-flat {
  transform-origin: 0 0;
}

.sim-render[hidden] {
  display: none;
}

/* "Recomeçar conversa" (outside the phone) and its confirmation. */
.sim-caption {
  position: relative;
}

.sim-page button.sim-chip,
.sim-embed button.sim-chip {
  cursor: pointer;
  font: inherit;
  font-family: var(--sim-display);
  font-size: 0.8125rem;
  font-weight: 600;
}

.sim-reset[hidden] {
  display: none;
}

.sim-reset:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sim-reset-icon {
  width: 14px;
  height: 14px;
}

.sim-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  z-index: 20;
  width: 280px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  background: rgba(10, 52, 26, 0.86);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 20px 50px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  color: var(--sim-text);
  font-family: var(--sim-font);
}

.sim-popover[hidden] {
  display: none;
}

.sim-popover p {
  margin: 0 0 12px;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.sim-popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.sim-popover button {
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--sim-text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.sim-popover .sim-popover-confirm {
  border-color: transparent;
  background: var(--sim-accent);
  color: #002e10;
}

html.sim-kiosk .sim-home {
  pointer-events: none;
}

/* Light theme (the home's embed, on its off-white section): dark text,
   subtle glass on light, a softer warm floor shadow. */
.sim-embed[data-theme="light"] {
  --sim-text: #102a1a;
  --sim-muted: rgba(16, 42, 26, 0.7);
}

.sim-embed[data-theme="light"] .sim-chip {
  border-color: rgba(0, 46, 16, 0.12);
  background: rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 2px rgba(0, 0, 0, 0.05);
  color: #183a26;
}

.sim-embed[data-theme="light"] .sim-chip-dot {
  background: #3fae5f;
  box-shadow: 0 0 0 3px rgba(63, 174, 95, 0.18);
}

.sim-embed[data-theme="light"] .sim-reset:hover {
  background: rgba(255, 255, 255, 0.85);
}

.sim-embed[data-theme="light"] .sim-drag-hint {
  color: rgba(16, 42, 26, 0.55);
}

.sim-embed[data-theme="light"] .sim-stage {
  --shadow-color: 84, 72, 56;
  --shadow-strength: 0.26;
  --shadow-core: 0.42;
}

.sim-embed[data-theme="light"] .sim-popover {
  border-color: rgba(0, 46, 16, 0.12);
  background: rgba(252, 252, 250, 0.92);
  box-shadow:
    inset 0 1px 0 #fff,
    0 18px 40px rgba(0, 0, 0, 0.14);
  color: #102a1a;
}

.sim-embed[data-theme="light"] .sim-popover button {
  border-color: rgba(0, 46, 16, 0.16);
  background: rgba(0, 46, 16, 0.04);
  color: #102a1a;
}

.sim-embed[data-theme="light"] .sim-popover .sim-popover-confirm {
  background: #002e10;
  color: #fff;
}

/* The phone screen's host (its UI lives in a shadow root, styled by
   chat-simulator-screen.css): the screen's size, or the full layout. */
.ws-host {
  display: block;
  width: 402px;
  height: 874px;
}

html.sim-full .ws-host {
  width: 100%;
  height: 100%;
}

/* The retro grid backdrop (backdrop.ts): the viewport's width, behind the
   copy and the phone, centered on the page; never takes the pointer. */
.sim-backdrop {
  position: absolute;
  top: -18%;
  bottom: -18%;
  left: calc(50% - 50vw);
  width: 100vw;
  z-index: 0;
  pointer-events: none;
}

.sim-backdrop-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sim-main {
  position: relative;
}

.sim-main > :not(.sim-backdrop) {
  position: relative;
  z-index: 1;
}

html.sim-full .sim-backdrop {
  display: none;
}
