/* ==========================================================================
   N-gram Text Generator — DotCode
   Purple = the word(s) we look at, green = the word picked next,
   yellow = the dice rolling across a list.
   ========================================================================== */

:root {
  /* DotCode brand */
  --primary: #5C48E7;
  --primary-light: #8C6DF5;
  --lavender: #BEC7EC;

  --bg: #080F1A;
  --bg-soft: #0E1628;
  --code-bg: #050A14;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(140, 109, 245, 0.24);
  --line: rgba(255, 255, 255, 0.08);
  --text: #F1F2FA;
  --muted: #A3AAC8;

  --key: #C792EA;
  --next: #C3E88D;
  --dice: #FFC857;

  --radius: 20px;
  --font: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 24px 48px;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(900px 600px at 90% -10%, rgba(92, 72, 231, 0.3), transparent 70%),
    radial-gradient(700px 500px at 0% 110%, rgba(140, 109, 245, 0.12), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

.grad {
  background: linear-gradient(90deg, var(--primary-light), #C9B8FF 55%, #7FD6FF);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---- Header -------------------------------------------------------------- */

.top {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 0 24px;
  display: flex;
  align-items: center;
  gap: 18px;
}

/* The logo SVG has lots of empty space around it */
.logo { height: 170px; margin: -40px -26px -40px -40px; flex-shrink: 0; }

.top h1 {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.top p { color: var(--muted); margin-top: 6px; }

/* ---- Layout -------------------------------------------------------------- */

.layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 24px;
}

.card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 { margin: 0; }

.num {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ---- 1. Text ------------------------------------------------------------- */

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.chip-btn {
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(140, 109, 245, 0.14);
  border: 1px solid rgba(140, 109, 245, 0.4);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.chip-btn:hover { background: rgba(140, 109, 245, 0.32); }
.chip-btn--ghost { background: transparent; border-color: var(--line); }

textarea {
  display: block;
  width: 100%;
  min-height: 180px;
  padding: 16px 18px;
  font-size: 16px;
  line-height: 1.6;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  resize: vertical;
}

textarea:focus,
select:focus,
input[type="search"]:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 1px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
}

.stats b { color: var(--text); font-weight: 700; }

/* ---- 2. Settings --------------------------------------------------------- */

.setting { margin-bottom: 18px; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.segmented button {
  padding: 10px 8px;
  font-weight: 600;
  line-height: 1.3;
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.segmented button small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.segmented button:hover { background: rgba(140, 109, 245, 0.14); }
.segmented button[aria-checked="true"] { background: var(--primary); }
.segmented button[aria-checked="true"] small { color: var(--lavender); }

.segmented--small { border-radius: 10px; }
.segmented--small button { padding: 6px 12px; font-size: 13px; border-radius: 7px; }

.checks {
  display: grid;
  gap: 10px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--primary-light);
  flex-shrink: 0;
}

.check small {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

/* ---- 3. Generate --------------------------------------------------------- */

.gen-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 24px;
  margin-bottom: 18px;
}

.field { display: block; }
.field output { color: var(--text); }

select,
input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

select option { background: var(--bg-soft); }

input[type="range"] {
  width: 100%;
  margin: 10px 0 0;
  accent-color: var(--primary-light);
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  padding: 11px 20px;
  font-weight: 600;
  background: rgba(140, 109, 245, 0.18);
  border: 1px solid rgba(140, 109, 245, 0.5);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.btn:hover { background: rgba(140, 109, 245, 0.34); }
.btn--primary { background: var(--primary); border-color: var(--primary); }
.btn--primary:hover { background: var(--primary-light); }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--small { padding: 7px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .chip-btn:focus-visible, .segmented button:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

.output {
  margin-top: 20px;
  padding: 22px 24px;
  min-height: 140px;
  font-size: 22px;
  line-height: 1.7;
  background: linear-gradient(160deg, rgba(92, 72, 231, 0.35), rgba(140, 109, 245, 0.08));
  border-left: 6px solid #7FD6FF;
  border-radius: 0 16px 16px 0;
}

.output.is-empty { color: var(--muted); font-style: italic; }

.w {
  display: inline-block;
  padding: 0 0.12em;
  margin: 0 -0.12em;
  border-radius: 6px;
}

.w.is-key {
  background: rgba(199, 146, 234, 0.28);
  box-shadow: 0 0 0 2px var(--key);
}

.w.is-new {
  color: var(--next);
  background: rgba(22, 35, 15, 0.85);
  box-shadow: 0 0 0 2px var(--next);
}

.w.is-waiting { visibility: hidden; }

.explain {
  margin-top: 14px;
  min-height: 1.5em;
  color: var(--muted);
}

.explain b { color: var(--text); }
.explain .ck, .dict .k { color: var(--key); }
.explain .cn { color: var(--next); }

.how summary {
  font-weight: 700;
  cursor: pointer;
}

.how ol { margin: 14px 0; padding-left: 22px; }
.how li { margin-bottom: 8px; color: var(--muted); }
.how li strong, .how p strong { color: var(--text); }
.how p { color: var(--muted); }

/* ---- Dictionary ---------------------------------------------------------- */

.dict-card {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
  min-width: 0;
}

@media (max-width: 960px) {
  .dict-card { position: static; max-height: 80vh; }
}

.count {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.dict-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  margin-bottom: 12px;
}

.dict-tools select { width: auto; }

@media (max-width: 560px) {
  .dict-tools { grid-template-columns: 1fr 1fr; }
  .dict-tools input { grid-column: 1 / -1; }
}

.dict {
  position: relative;
  flex: 1;
  min-height: 200px;
  overflow: auto;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.8;
  color: #D6DBF5;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.row {
  display: grid;
  grid-template-columns: auto 1fr; /* long lists wrap under their first word */
  padding: 0 6px;
  margin: 0 -6px;
  border-radius: 8px;
  transition: background 0.2s;
}

.row.is-active { background: rgba(199, 146, 234, 0.14); }
.row-key { white-space: pre; }
.row.is-active .k { text-decoration: underline; text-underline-offset: 4px; }

.chip {
  display: inline-block;
  padding: 0 0.15em;
  margin: 0 -0.15em;
  color: var(--next);
  border-radius: 5px;
  transition: background 0.1s, box-shadow 0.1s;
}

.chip .pct { color: var(--muted); font-size: 0.85em; }

.chip.is-spin {
  background: rgba(255, 200, 87, 0.25);
  box-shadow: 0 0 0 2px var(--dice);
}

.chip.is-new {
  background: rgba(195, 232, 141, 0.2);
  box-shadow: 0 0 0 2px var(--next);
}

.dict-empty {
  font-family: var(--font);
  color: var(--muted);
}

.show-all { margin-top: 12px; font-family: var(--font); }

/* The copy of a word that flies from the dictionary into the text */
.ghost {
  position: fixed;
  z-index: 50;
  padding: 0 0.2em;
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--next);
  background: #16230F;
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--next), 0 12px 28px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.pop { animation: pop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }

@keyframes pop {
  from { transform: scale(1.4); }
  to   { transform: none; }
}

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

@media (max-width: 560px) {
  body { padding: 0 16px 32px; }
  .card { padding: 18px; }
  .output { font-size: 19px; }
  .logo { height: 120px; margin: -28px -18px -28px -28px; }
}
