:root {
  --fondo: #f7f6f3;
  --carta: #ffffff;
  --inchiostro: #17171a;
  --grigio: #6f6f76;
  --grigio-chiaro: #a3a3aa;
  --bordo: rgba(23, 23, 26, 0.08);
  --barra: #18181b;
  --barra-alta: #2a2a2f;
  --barra-testo: #f4f4f5;
  --accento: #5b5bd6;
  --selezione: color-mix(in srgb, var(--accento) 17%, transparent);
  --commento: rgba(234, 179, 8, 0.22);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--fondo);
  color: var(--inchiostro);
  font-family: "Mona Sans Variable", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: min(5vh, 32px) 16px;
}

.doc {
  position: relative;
  width: min(600px, 100%);
  background: var(--carta);
  border: 1px solid var(--bordo);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(23, 23, 26, 0.04), 0 18px 48px -18px rgba(23, 23, 26, 0.16);
}

.doc__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--bordo);
  font-size: 13px;
  font-weight: 500;
}
.doc__logo { width: 16px; height: 16px; fill: none; stroke: var(--accento); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.doc__sep { color: var(--grigio-chiaro); }
.doc__path { color: var(--grigio); }
.doc__state { margin-left: auto; color: var(--grigio-chiaro); font-weight: 450; font-size: 12px; font-variant-numeric: tabular-nums; }

.doc__body {
  position: relative;
  padding: clamp(18px, 4vh, 30px) clamp(20px, 5vw, 40px) clamp(18px, 4vh, 28px);
}
.doc__title {
  font-size: clamp(20px, min(4.6vw, 5vh), 28px);
  font-weight: 640;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: clamp(10px, 2vh, 16px);
}
.doc__p {
  position: relative;
  z-index: 1;
  font-size: clamp(14px, min(2.9vw, 3.6vh), 17px);
  line-height: 1.6;
  color: #2b2b30;
  margin-bottom: 10px;
}
.doc__p--soft { color: var(--grigio); }
.doc__p::selection, .doc__p *::selection, .doc__title::selection { background: transparent; }
.doc__meta { font-size: 12px; color: var(--grigio-chiaro); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* every word is its own box: GSAP gives it weight and slant, the highlight measures it */
.w { display: inline-block; font-weight: 420; transform-origin: 50% 80%; }
.w.is-link { color: var(--accento); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: rgba(91, 91, 214, 0.45); }
.w.is-noted { background: linear-gradient(transparent 58%, var(--commento) 58%); }

.marks { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.mark {
  position: absolute;
  background: var(--selezione);
  border-radius: 4px;
  transform-origin: 0 50%;
}
.doc__chip {
  display: none;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px 0 6px;
  border-radius: 11px;
  background: #fff7d6;
  border: 1px solid rgba(234, 179, 8, 0.35);
  color: #8a6a00;
  font-size: 11px;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}
.doc__chip svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.doc__chip.is-on + .doc__state { margin-left: 8px; }
.doc__chip.is-on { display: inline-flex; margin-left: auto; }

/* ---- the toolbar ---- */
.bar {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  visibility: hidden;
  will-change: transform;
}
.bar__shell {
  position: relative;
  height: 40px;
  border-radius: 20px;
  background: var(--barra);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 10px 28px -8px rgba(10, 10, 12, 0.45), 0 2px 6px rgba(10, 10, 12, 0.18);
  overflow: hidden;
}
.bar__tools, .bar__link {
  position: absolute;
  inset: 0 auto 0 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
  white-space: nowrap;
}
.bar__link { visibility: hidden; opacity: 0; gap: 6px; padding: 0 4px 0 12px; }
.tool {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  min-width: 32px;
  justify-content: center;
  padding: 0 7px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--barra-testo);
  font: inherit;
  font-size: 13px;
  font-weight: 560;
  cursor: pointer;
  transition: background-color 0.18s;
}
.tool svg, .bar__link svg, .menu__item svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tool[data-act="bold"] svg { stroke-width: 2; }
.tool.is-hover, .tool:focus-visible { background: var(--barra-alta); outline: none; }
.tool:focus-visible { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35); }
.tool[aria-pressed="true"] { background: rgba(255, 255, 255, 0.14); }
@media (hover: hover) { .tool:hover { background: var(--barra-alta); } }
.bar__div { width: 1px; height: 18px; background: rgba(255, 255, 255, 0.14); margin: 0 3px; }
.tool--ai {
  padding: 0 11px 0 9px;
  background-image: linear-gradient(100deg, transparent 30%, rgba(170, 170, 255, 0.28) 48%, rgba(255, 255, 255, 0.18) 52%, transparent 70%);
  background-size: 260% 100%;
  background-position: 120% 0;
  background-repeat: no-repeat;
  animation: luce 3.2s cubic-bezier(0.5, 0, 0.3, 1) infinite;
}
.tool--ai svg { color: #b9b9ff; stroke-width: 1.4; }
.tool--ai[aria-expanded="true"] { background-color: rgba(255, 255, 255, 0.14); }
@keyframes luce { 0% { background-position: 120% 0; } 55%, 100% { background-position: -40% 0; } }

.bar__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.bar__link > svg { color: var(--grigio-chiaro); }
.bar__field {
  width: 168px;
  border: 0;
  background: transparent;
  color: var(--barra-testo);
  font: inherit;
  font-size: 13px;
  font-weight: 450;
  outline: none;
}
.bar__field::placeholder { color: #85858c; }
.bar__ok {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 15px; border: 0;
  background: var(--accento); color: #fff; cursor: pointer;
}
.bar__ok svg { width: 15px; height: 15px; stroke-width: 2; }
.bar__nib {
  position: absolute;
  top: 36px;
  left: 0;
  width: 10px;
  height: 10px;
  background: var(--barra);
  border-radius: 0 0 3px 0;
  transform: translateX(-50%) rotate(45deg);
  z-index: -1;
}
.bar.is-below .bar__nib { top: -5px; border-radius: 3px 0 0 0; }

/* ---- the Ask AI menu ---- */
.menu {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  width: 204px;
  padding: 5px;
  border-radius: 14px;
  background: var(--barra);
  box-shadow: 0 14px 34px -10px rgba(10, 10, 12, 0.5), 0 2px 6px rgba(10, 10, 12, 0.2);
  visibility: hidden;
  transform-origin: 24px 0;
}
.menu__item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--barra-testo);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.menu__item svg { color: #b9b9ff; }
.menu__item.is-hover, .menu__item:focus-visible { background: var(--barra-alta); outline: none; }
@media (hover: hover) { .menu__item:hover { background: var(--barra-alta); } }

.ghost, .caret {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
}
.ghost { width: 22px; height: 22px; fill: var(--inchiostro); stroke: #fff; stroke-width: 1.4; stroke-linejoin: round; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2)); }
.caret { width: 12px; height: 22px; fill: none; stroke: var(--inchiostro); stroke-width: 1.6; stroke-linecap: round; }

@media (max-width: 440px) {
  .doc__bar { padding: 11px 14px; }
  .doc__path { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar__field { width: 132px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool--ai { animation: none; }
}
