/* ==========================================================================
   Tinta · Contador de palabras
   Concepto: tinta azul sobre papel frío, con un subrayador amarillo como
   único acento (enlaces del menú).
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --paper: #f2f4f8;
  --surface: #ffffff;
  --ink: #121c3a;
  --ink-soft: #4b5578;
  --line: #dde2ee;
  --accent: #ffd43b;
  --accent-ink: #121c3a;
  --blue: #2f4bd8;
  --ok: #1f9d6a;
  --warn: #e08a00;
  --bad: #d63a4a;
  --paper-glass: #f2f4f8e0;
  --focus-ring: #2f4bd840;
  --shadow: 0 1px 2px #121c3a0f, 0 8px 24px #121c3a0f;

  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;

  --radius: 14px;
  --radius-sm: 8px;
  --max: 1160px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #121212;
  --surface: #1c1c1f;
  --ink: #f4f4f5;
  --ink-soft: #a1a1aa;
  --line: #303036;
  --accent: #ffd43b;
  --accent-ink: #121212;
  --blue: #8ea2ff;
  --paper-glass: #121212e0;
  --focus-ring: #8ea2ff40;
  --shadow: 0 1px 2px #0000004d, 0 8px 24px #00000040;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.65 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.15;
  letter-spacing: -.02em;
  margin: 0;
}

a { color: inherit; }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem clamp(1rem, 4vw, 2.5rem);
  background: var(--paper-glass);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 2rem; height: 2rem;
  background: var(--ink); color: var(--paper);
  border-radius: 8px;
  font: 800 18px var(--font-display);
}
.brand-name { font: 800 20px var(--font-display); letter-spacing: -.02em; }

.topnav { display: flex; gap: 1.25rem; margin-left: auto; }
.topnav a {
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  text-decoration: none; color: var(--ink-soft);
  font-size: 15px; font-weight: 500;
  transition: background .15s, color .15s;
}
.topnav a:hover,
.topnav a:focus-visible { background: var(--accent); color: var(--accent-ink); }

.icon-btn {
  display: grid; place-items: center;
  width: 2.4rem; height: 2.4rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 50%; cursor: pointer;
}
.icon-btn:hover { border-color: var(--blue); }

/* ---------- Hero ---------- */
.hero {
  max-width: var(--max); margin: 0 auto;
  padding: .75rem clamp(1rem, 4vw, 2.5rem) 1.5rem;
}
.hero h1 { font-size: clamp(34px, 5.5vw, 61px); font-weight: 800; max-width: 16ch; }
.hero p { max-width: 58ch; margin: 1rem 0 0; color: var(--ink-soft); font-size: 17px; }

/* ---------- Espacio de trabajo ---------- */
.workspace {
  max-width: var(--max); margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2.5rem) 4rem;
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
  grid-template-areas:
    "editor  stats"
    "howto   keywords";
  gap: 1.5rem; align-items: start;
}

.editor { grid-area: editor; padding: 1rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.toolbar button {
  padding: .4rem .75rem;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.toolbar button:hover { border-color: var(--blue); background: var(--surface); }
.toolbar button.danger:hover { border-color: var(--bad); color: var(--bad); }
.toolbar-spacer { flex: 1; }
.toolbar-format { margin: 1rem 0 0; }

textarea {
  width: 100%; min-height: 380px; resize: vertical;
  padding: 1rem;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 17px; line-height: 1.7;
}
textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--focus-ring); }
textarea::placeholder { color: var(--ink-soft); opacity: .7; }

/* ---------- Límite ---------- */
.limit { margin-top: .9rem; }
.limit-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.limit-head label { font-weight: 600; font-size: 14px; }
.limit select, .limit input {
  padding: .35rem .6rem;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 14px;
}
.limit input { width: 6.5rem; }

.meter { height: 8px; margin-top: .7rem; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter-bar { height: 100%; width: 0; background: var(--ok); border-radius: 99px; transition: width .2s, background .2s; }
.meter-bar.warn { background: var(--warn); }
.meter-bar.over { background: var(--bad); }
.limit-text { margin: .4rem 0 0; min-height: 1.4em; font-size: 14px; color: var(--ink-soft); }
.limit-text.over { color: var(--bad); font-weight: 600; }

/* ---------- Estadísticas ---------- */
.stats { grid-area: stats; display: grid; gap: 1rem; }

.primary-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stat {
  padding: .8rem .9rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stat strong { display: block; font: 700 26px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: 16px; line-height: 1.3; color: var(--ink-soft); }

.details, .keywords { padding: 1rem 1.1rem; }
.keywords { grid-area: keywords; }
.details h2, .keywords h2 { font-size: 17px; margin-bottom: .6rem; }

dl { margin: 0; }
dl > div { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-top: 1px solid var(--line); font-size: 14px; }
dl > div:first-child { border-top: 0; }
dt { color: var(--ink-soft); }
dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.keyword-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.keyword-list li { display: grid; grid-template-columns: 7rem 1fr auto; align-items: center; gap: .6rem; font-size: 14px; }
.keyword-list .word { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.keyword-list .bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.keyword-list .bar i { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.keyword-list .count { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.keyword-list .empty { display: block; color: var(--ink-soft); }

/* ---------- Cómo funciona (bajo el editor) ---------- */
.howto { grid-area: howto; padding-top: 1.5rem; }
.howto h2 { font-size: 28px; font-weight: 700; margin-bottom: 1rem; }

/* ---------- Secciones informativas ---------- */
.info { padding: clamp(2.5rem, 6vw, 4.5rem) clamp(1rem, 4vw, 2.5rem); }
.info.alt { background: var(--surface); border-block: 1px solid var(--line); }
.info > h2, .info > .prose, .info > .use-grid, .info > .faq { max-width: var(--max); margin-inline: auto; }
.info > h2 { font-size: clamp(26px, 3.5vw, 37px); font-weight: 700; margin-bottom: 1.5rem; }

.prose { max-width: 70ch; }
.prose p { margin: 0 0 1.1rem; color: var(--ink-soft); }
.prose strong { color: var(--ink); }
.prose.two-col { max-width: var(--max); display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 2.5rem; }

.use-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 2rem 2.5rem; }
.use-grid h3 { font-size: 18px; margin-bottom: .4rem; }
.use-grid p { margin: 0; color: var(--ink-soft); }

.faq { display: grid; gap: .6rem; }
.faq details { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .85rem 1.1rem; max-width: 80ch; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: .6rem 0 0; color: var(--ink-soft); }

kbd {
  padding: .1rem .4rem;
  background: var(--paper); border: 1px solid var(--line); border-radius: 5px;
  font: 500 14px var(--font-body);
}

/* ---------- Pie y aviso ---------- */
.footer { padding: 2rem; text-align: center; color: var(--ink-soft); font-size: 14px; }
.footer p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; z-index: 20;
  transform: translate(-50%, 1rem);
  padding: .6rem 1.1rem;
  background: var(--ink); color: var(--paper);
  border-radius: 99px; font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas: "editor" "stats" "keywords" "howto";
  }
  .topnav { display: none; }
  .icon-btn { margin-left: auto; }
}

@media (max-width: 480px) {
  .stat { padding: .7rem .6rem; }
  .stat strong { font-size: 22px; }
  .stat span { font-size: 14px; }
  .keyword-list li { grid-template-columns: 5.5rem 1fr auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
