/*!
 * O CHARLES QUER FALAR CONTIGO! — estilos
 * GRRR! LAB · mobile-first
 *
 * Tokens: petróleo escuro + amarelo eléctrico + branco-chuva.
 * Tipografia: Bricolage Grotesque (OFL), alojada localmente.
 */

@font-face {
  font-family: "Bricolage";
  src: url("assets/fonts/bricolage-grotesque.woff2") format("woff2");
  font-weight: 200 800;
  font-stretch: 75% 100%;
  font-display: swap;
}

:root {
  --petrol-950: #021419;
  --petrol-900: #031E24;
  --petrol-800: #052A31;
  --petrol-700: #0A3A43;
  --petrol-600: #135160;
  --petrol-500: #1F7C86;
  --yellow: #FFE600;
  --yellow-deep: #F5C800;
  --rain: #E9F4F1;
  --rain-dim: rgba(233, 244, 241, 0.72);
  --ink: #03181D;
  --alert: #FF5A5A;

  --font: "Bricolage", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  --r-bubble: 22px;
  --r-btn: 16px;
  --col: 480px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ease-out: cubic-bezier(.2, .9, .25, 1);
  --ease-pop: cubic-bezier(.3, 1.4, .5, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  color: var(--rain);
  background: var(--petrol-900);
  background-image:
    radial-gradient(120% 60% at 50% -10%, #0E4A55 0%, rgba(14, 74, 85, 0) 60%),
    repeating-linear-gradient(105deg, rgba(233, 244, 241, .028) 0 2px, transparent 2px 26px);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--yellow); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; border-radius: 6px; }
[hidden] { display: none !important; }

.app {
  position: relative;
  max-width: var(--col);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; overflow-x: clip; }
.screen.is-active { animation: screen-in .45s var(--ease-out) both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Barra superior ───────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-t)) 18px 0;
}
.brand {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 15px; letter-spacing: .02em; color: var(--yellow);
}
.brand-bolt { width: 11px; height: 18px; fill: var(--yellow); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 14px;
  border: 0; background: transparent; color: var(--rain-dim);
  transition: background .2s, color .2s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(233, 244, 241, .08); color: var(--rain); }
.icon-btn[aria-pressed="true"] { color: var(--yellow); background: rgba(255, 230, 0, .1); }
.js-sound .ico-on { display: none; }
.js-sound.is-on .ico-on { display: block; }
.js-sound.is-on .ico-off { display: none; }

/* ── Botões ───────────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; text-align: center;
  width: 100%; min-height: 54px; padding: 12px 20px;
  border-radius: var(--r-btn); border: 2px solid transparent;
  font-weight: 800; font-size: 16px; letter-spacing: .04em; text-decoration: none;
  transition: transform .15s var(--ease-out), background .2s, box-shadow .2s;
}
.btn:active { transform: translateY(2px) scale(.99); }
.btn--primary {
  background: var(--yellow); color: var(--ink);
  box-shadow: 0 5px 0 var(--ink), 0 10px 30px rgba(255, 230, 0, .18);
}
.btn--primary:active { box-shadow: 0 2px 0 var(--ink); }
.btn--secondary { background: var(--petrol-700); color: var(--rain); border-color: var(--petrol-600); }
.btn--secondary:hover { border-color: var(--yellow); }
.btn--ghost { background: transparent; color: var(--rain-dim); border-color: rgba(233, 244, 241, .18); }
.btn--ghost:hover { color: var(--rain); border-color: var(--rain-dim); }
.btn--big { min-height: 62px; font-size: 18px; }
.btn--pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 5px 0 var(--ink), 0 0 0 8px rgba(255, 230, 0, .14); } }

/* ════════════ ECRÃ INICIAL ════════════ */
.screen--intro { display: flex; flex-direction: column; }
.hero { flex: 1; padding: 10px 22px 8px; display: flex; flex-direction: column; }

.notif {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0 0; padding: 12px 14px;
  background: rgba(233, 244, 241, .96); color: var(--ink);
  border-radius: 20px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
  animation: notif-in .7s var(--ease-pop) .5s both, notif-nudge 6s ease-in-out 2.2s infinite;
  transform-origin: 50% 0;
}
@keyframes notif-in { from { opacity: 0; transform: translateY(-36px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes notif-nudge { 0%, 88%, 100% { transform: none; } 91% { transform: rotate(-1.4deg); } 94% { transform: rotate(1.4deg); } 97% { transform: rotate(-.6deg); } }
.notif-avatar { flex: none; width: 44px; height: 44px; border-radius: 13px; background: var(--petrol-800); padding: 4px; }
.notif-avatar svg { width: 100%; height: 100%; }
.notif-text { min-width: 0; }
.notif-who { margin: 0; display: flex; gap: 8px; align-items: baseline; font-size: 15px; }
.notif-who span { font-size: 13px; color: #4b6870; }
.notif-msg { margin: 1px 0 0; font-size: 15px; }
.notif-dot { position: absolute; top: 10px; right: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--alert); box-shadow: 0 0 0 3px rgba(233, 244, 241, .96); }

.hero-charles {
  width: min(62vw, 250px); margin: 14px auto 0;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .35));
}
.hero-charles svg { width: 100%; height: auto; display: block; }

.title {
  margin: 10px 0 0;
  font-weight: 800; font-stretch: 78%;
  font-size: clamp(3.1rem, 16.5vw, 5.4rem);
  line-height: .84; letter-spacing: -.015em;
  text-transform: uppercase; color: var(--yellow);
  text-shadow: 4px 4px 0 var(--ink);
}
.title-line { display: block; transform-origin: 0 100%; }
.title-line:nth-child(1) { transform: rotate(-2deg); }
.title-line:nth-child(2) { transform: rotate(-.5deg) translateX(.12em); color: var(--rain); }
.title-line:nth-child(3) { transform: rotate(-2.5deg); }
.is-struck .title { animation: struck .55s steps(1) both; }
@keyframes struck {
  0% { transform: translate(0, 0); }
  15% { transform: translate(-5px, 2px); }
  30% { transform: translate(4px, -3px); }
  45% { transform: translate(-3px, 1px); }
  60% { transform: translate(2px, 0); }
  80%, 100% { transform: none; }
}
.is-struck .flash { animation: flash .6s ease-out both; }

.subtitle { margin: 18px 0 22px; font-size: 18px; line-height: 1.4; color: var(--rain); max-width: 30ch; }
.warning { margin: 14px 0 0; font-size: 14px; color: var(--rain-dim); text-align: center; }

.foot { padding: 22px 22px calc(22px + var(--safe-b)); text-align: center; }
.foot-brand { margin: 0 0 6px; font-size: 14px; color: var(--rain-dim); }
.foot-brand strong { color: var(--yellow); }
.disclaimer { margin: 0 auto; max-width: 42ch; font-size: 12.5px; line-height: 1.45; color: rgba(233, 244, 241, .55); }

/* ════════════ CONVERSA ════════════ */
.screen--chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh; height: 100dvh;
  min-height: 0;
}
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 10px 10px 14px;
  background: rgba(3, 30, 36, .92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(233, 244, 241, .08);
  position: relative; z-index: 2;
}
.chat-avatar {
  flex: none; width: 50px; height: 50px; border-radius: 16px;
  background: var(--petrol-700); padding: 4px;
  box-shadow: inset 0 0 0 2px var(--yellow);
}
.chat-avatar svg { width: 100%; height: 100%; display: block; }
.chat-avatar.is-pop { animation: pop .38s var(--ease-pop); }
.chat-avatar.is-shock { animation: shock .5s steps(2) both; }
@keyframes pop { 0% { transform: scale(.82) rotate(-6deg); } 100% { transform: none; } }
@keyframes shock { 0%, 50% { background: var(--yellow); } 100% { background: var(--petrol-700); } }
.chat-id { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-id strong { font-size: 18px; line-height: 1.1; }
.chat-id span { font-size: 13px; color: var(--rain-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-log {
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 18px;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 0;
}
.log-note { align-self: center; margin: 0 0 10px; padding: 4px 12px; border-radius: 99px; font-size: 12px; color: var(--rain-dim); background: rgba(233, 244, 241, .06); }

.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.msg--first { margin-top: 10px; }
.msg--charles { padding-left: 42px; }
.msg--charles.msg--first, .msg--typing { padding-left: 0; }
.msg--user { justify-content: flex-end; }
.msg-avatar { flex: none; width: 34px; height: 34px; border-radius: 11px; background: var(--petrol-700); padding: 3px; align-self: flex-start; }
.msg-avatar svg { width: 100%; height: 100%; display: block; }

.bubble {
  margin: 0; padding: 10px 15px 11px;
  max-width: min(82%, 340px);
  font-size: 16.5px; line-height: 1.38;
  overflow-wrap: anywhere;
  animation: bubble-in .32s var(--ease-pop) both;
}
.bubble--charles {
  background: var(--rain); color: var(--ink);
  border-radius: 6px var(--r-bubble) var(--r-bubble) var(--r-bubble);
  transform-origin: 0 0;
}
.msg--charles:not(.msg--first) .bubble--charles { border-radius: var(--r-bubble); border-top-left-radius: 6px; }
.bubble--user {
  background: var(--yellow); color: var(--ink); font-weight: 600;
  border-radius: var(--r-bubble) 6px var(--r-bubble) var(--r-bubble);
  transform-origin: 100% 0;
}
.bubble--deleted {
  background: transparent; color: var(--rain-dim);
  border: 1.5px dashed rgba(233, 244, 241, .3); font-style: italic;
}
.bubble--deleted::before { content: "⌀ "; font-style: normal; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(8px) scale(.94); } to { opacity: 1; transform: none; } }

.typing {
  display: inline-flex; flex-direction: column; gap: 4px;
  animation: bubble-in .25s var(--ease-out) both;
}
.typing-dots {
  display: inline-flex; gap: 5px; padding: 14px 16px;
  background: var(--rain); border-radius: 6px var(--r-bubble) var(--r-bubble) var(--r-bubble);
  width: max-content;
}
.typing-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--petrol-600); animation: dot 1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }
.typing-label { font-size: 12.5px; color: var(--rain-dim); padding-left: 4px; }

/* Zona das respostas */
.composer {
  padding: 12px 14px calc(14px + var(--safe-b));
  background: linear-gradient(to top, var(--petrol-950) 60%, rgba(2, 20, 25, .85));
  border-top: 1px solid rgba(233, 244, 241, .08);
  transition: opacity .17s, transform .17s;
  min-height: 0;
}
.composer:empty { padding: 0 0 var(--safe-b); border-top-color: transparent; }
.composer.is-leaving { opacity: 0; transform: translateY(12px); }
.choices { display: grid; gap: 9px; }
.choice {
  width: 100%; min-height: 54px; padding: 12px 18px;
  border-radius: var(--r-btn);
  border: 2px solid var(--yellow);
  background: rgba(255, 230, 0, .04); color: var(--rain);
  font-size: 16.5px; font-weight: 600; text-align: left; line-height: 1.3;
  animation: choice-in .34s var(--ease-pop) both;
  animation-delay: calc(var(--i, 0) * 70ms);
  transition: background .15s, color .15s, transform .12s;
}
.choice:hover { background: rgba(255, 230, 0, .12); }
.choice:active, .choice.is-picked { background: var(--yellow); color: var(--ink); transform: scale(.98); }
@keyframes choice-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.name-form { display: grid; gap: 10px; animation: choice-in .3s var(--ease-pop) both; }
.name-label { font-size: 14px; color: var(--rain-dim); padding-left: 4px; }
.name-row { display: flex; gap: 8px; }
.name-input {
  flex: 1; min-width: 0; height: 54px; padding: 0 16px;
  border-radius: var(--r-btn); border: 2px solid var(--petrol-600);
  background: var(--petrol-800); color: var(--rain);
  font-size: 17px; /* ≥16px: evita o zoom automático no iPhone */
}
.name-input::placeholder { color: rgba(233, 244, 241, .4); }
.name-input:focus { outline: none; border-color: var(--yellow); }
.name-send {
  flex: none; width: 54px; height: 54px; border-radius: var(--r-btn); border: 0;
  background: var(--yellow); color: var(--ink); display: grid; place-items: center;
}
.name-send svg { width: 22px; height: 22px; }
.name-send:disabled { background: var(--petrol-700); color: rgba(233, 244, 241, .35); cursor: not-allowed; }

/* ════════════ RESULTADO ════════════ */
.result { padding: 4px 20px 8px; }
.result-head { text-align: center; }
.result-kicker { margin: 10px 0 0; font-size: 15px; color: var(--rain-dim); }
.result-ill { margin: 6px auto 0; max-width: 360px; animation: ill-in .8s var(--ease-pop) .1s both; }
.result-ill svg { width: 100%; height: auto; display: block; }
@keyframes ill-in { from { opacity: 0; transform: scale(.7) rotate(-6deg); } to { opacity: 1; transform: none; } }
.result-title {
  display: inline-block; margin: 6px 0 0; padding: 8px 18px 10px;
  background: var(--yellow); color: var(--ink);
  font-weight: 800; font-stretch: 80%; text-transform: uppercase;
  font-size: clamp(1.9rem, 9.5vw, 2.9rem); line-height: .95; letter-spacing: -.01em;
  border-radius: 14px; box-shadow: 6px 6px 0 var(--ink);
  transform: rotate(-2deg);
  animation: stamp .5s var(--ease-pop) .45s both;
}
@keyframes stamp { from { opacity: 0; transform: rotate(-6deg) scale(1.18); } to { opacity: 1; transform: rotate(-2deg); } }
.result-headline { margin: 22px auto 0; max-width: 30ch; font-size: 20px; line-height: 1.3; font-weight: 600; }
.result-body { margin-top: 18px; }
.result-text { margin: 0 auto; max-width: 38ch; font-size: 17px; line-height: 1.5; color: var(--rain-dim); text-align: center; }

.result-talk {
  position: relative; margin: 24px 0 0; padding-left: 46px;
  display: flex; flex-direction: column; gap: 5px; align-items: flex-start;
}
.result-talk .bubble { max-width: 100%; }
.result-talk .bubble--last { border-radius: var(--r-bubble); border-top-left-radius: 6px; }
.result-mini { position: absolute; left: 0; top: 0; width: 38px; height: 38px; border-radius: 12px; background: var(--petrol-700); padding: 3px; }
.result-mini svg { width: 100%; height: 100%; display: block; }

.card-preview { margin: 26px auto 0; max-width: 300px; text-align: center; }
.card-preview img {
  width: 100%; height: auto; aspect-ratio: 1080 / 1350; display: block;
  border-radius: 14px; background: var(--petrol-800);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .4), 0 0 0 1px rgba(233, 244, 241, .08);
  transform: rotate(1.5deg);
}
.card-preview figcaption { margin-top: 12px; font-size: 13px; color: var(--rain-dim); }

.actions { display: grid; gap: 10px; margin: 26px 0 0; }

/* ════════════ PARTILHA (folha) ════════════ */
.sheet {
  width: min(100%, var(--col)); max-width: 100%; max-height: 92dvh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--petrol-800); color: var(--rain);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
}
.sheet[open] { animation: sheet-in .35s var(--ease-out) both; }
.sheet::backdrop { background: rgba(2, 20, 25, .72); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner { position: relative; padding: 22px 20px calc(22px + var(--safe-b)); overflow-y: auto; max-height: 92dvh; }
.sheet-close { position: absolute; top: 10px; right: 10px; }
.sheet h3 { margin: 4px 50px 14px 0; font-size: 22px; font-stretch: 85%; }
.sheet-card { display: block; width: 62%; max-width: 240px; margin: 0 auto 12px; border-radius: 12px; }
.sheet-msg { margin: 0 0 16px; padding: 14px 16px; border-radius: 16px; background: var(--petrol-700); font-size: 15.5px; user-select: all; -webkit-user-select: all; }
.sheet-hint { margin: 0 0 14px; font-size: 13.5px; color: var(--rain-dim); text-align: center; }
.sheet-actions { display: grid; gap: 9px; margin-bottom: 8px; }

/* ════════════ EFEITOS ════════════ */
.flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: radial-gradient(circle at 60% 20%, rgba(255, 246, 170, .9), rgba(255, 230, 0, .25) 45%, transparent 75%);
  opacity: 0;
}
.flash.is-on { animation: flash .6s ease-out both; }
@keyframes flash { 0% { opacity: 0; } 8% { opacity: 1; } 18% { opacity: .15; } 26% { opacity: .8; } 100% { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); z-index: 60;
  width: max-content; max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 14px;
  background: var(--rain); color: var(--ink); font-size: 15px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s var(--ease-out);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* Animações do Charles (só no ecrã; o cartão PNG é estático) */
.charles .ch-body, .charles .ch-face { animation: float 4.2s ease-in-out infinite; }
.charles .ch-eyes { transform-box: fill-box; transform-origin: center; animation: blink 5.5s infinite; }
.charles .ch-bolt { animation: bolt 3.6s infinite; }
.charles .ch-bolt-b { animation-delay: 1.3s; }
.charles .ch-brows { transform-box: fill-box; transform-origin: center; animation: brows .5s var(--ease-pop); }
@keyframes float { 50% { transform: translateY(-4px); } }
@keyframes blink { 0%, 93%, 100% { transform: none; } 95% { transform: scaleY(.1); } }
@keyframes bolt { 0%, 100% { opacity: 0; } 4%, 10% { opacity: 1; } 7% { opacity: .2; } 14% { opacity: 0; } }
@keyframes brows { from { transform: translateY(-6px); } to { transform: none; } }
.hero-charles .ch-bolt { animation-duration: 2.8s; }

.noscript { margin: 40px 20px; padding: 16px; border-radius: 12px; background: var(--rain); color: var(--ink); }

/* Ecrãs maiores: a mesma coluna, com mais ar */
@media (min-width: 600px) {
  body { font-size: 18px; }
  .hero { padding-top: 24px; }
  .screen--chat { height: min(100dvh, 920px); margin: 0 auto; }
  .app::before {
    content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
    background: radial-gradient(60% 50% at 50% 50%, rgba(255, 230, 0, .05), transparent 70%);
  }
}

/* Ecrãs muito baixos (telemóveis pequenos na horizontal ou com teclado aberto) */
@media (max-height: 640px) {
  .hero-charles { width: min(42vw, 170px); margin-top: 6px; }
  .title { font-size: clamp(2.6rem, 13vw, 4.2rem); }
  .subtitle { margin: 12px 0 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
  }
  .charles .ch-bolt { opacity: 1; }
  .flash { display: none; }
}
