:root {
  --paper: #f3eadc;
  --sheet: #fffaf3;
  --ink: #241c16;
  --muted: #6e6258;
  --line: #e3d4c2;
  --red: #8d2e2a;
  --red-soft: #f8e6e1;
  --green: #1d5c40;
  --green-soft: #e4f2ea;
  --amber: #8a5a12;
  --amber-soft: #f8edd8;
  --serif: Palatino, "Palatino Linotype", "Iowan Old Style", "Liberation Serif", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 255, 255, 0.8), transparent 32%),
    var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--red);
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 4rem);
  line-height: 1.05;
}

h1 span { color: var(--red); }

.lede, .hint, .colophon { color: var(--muted); }
.lede { max-width: 38rem; font-size: 1.05rem; }
.stats { margin: 0.4rem 0 0; font-size: 0.95rem; }

.lang-details { margin-top: 0.8rem; }
.lang-details summary { cursor: pointer; color: var(--muted); }
.lang-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
  margin-top: 0.8rem;
}
.lang-form label { width: 100%; font-size: 0.85rem; }
.lang-form input {
  flex: 1 1 12rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}
.lang-form .hint { width: 100%; margin: 0; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 1.6rem 0 1rem;
}
.tabs button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 0.7rem 1rem;
}
.tabs button[aria-selected="true"] {
  background: var(--ink);
  color: var(--sheet);
  border-color: var(--ink);
}

.field { margin-top: 1.15rem; }
.field label, fieldset legend, .groups-head h2, #query-label {
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

#query, #word, #significado {
  width: 100%;
  border: none;
  border-bottom: 2px solid var(--ink);
  background: transparent;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  padding: 0.35rem 0 0.45rem;
  border-radius: 0;
}
#significado { font-size: clamp(1.3rem, 3vw, 1.8rem); }
textarea {
  width: 100%;
  margin-top: 0.35rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  min-height: 7rem;
  resize: vertical;
}
.meaning { margin: 0.35rem 0 0; font-size: 1.15rem; }
.description {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}
#query:focus, #word:focus, #significado:focus, textarea:focus { outline: none; border-color: var(--red); }
#query:focus, #word:focus, #significado:focus { border-bottom-color: var(--red); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 0.4rem;
}
.segmented {
  display: flex;
  padding: 0.2rem;
  background: rgba(255, 250, 243, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
}
.segmented button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--sheet);
}

.group-editor, fieldset {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.card {
  padding: 1.15rem 0 1.05rem;
  border-bottom: 1px solid #c9b8a4;
}
.card:last-child { border-bottom: none; }
.card h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 500;
}
.card-top, .card-actions, .group-editor-head, .form-actions, .choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.card-top { justify-content: space-between; }
.meta { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.lang-tag { color: var(--muted); font-size: 0.92rem; }
.direction { margin: 0.35rem 0 0.7rem; color: var(--muted); }

.badge {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
}
.badge.used { background: var(--green-soft); color: var(--green); }
.badge.unused { background: var(--amber-soft); color: var(--amber); }

.concept-group { margin-top: 0.75rem; }
.concept-group h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: #f6ecdf;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
}
.chip.hit, .name-hit { background: var(--red-soft); }
.chip button {
  border: 0;
  background: transparent;
  padding: 0 0.15rem;
  line-height: 1;
}

.card-actions { margin-top: 0.9rem; }
.ghost, .primary, .lang-form button, .text-button {
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
}
.primary { background: var(--ink); color: var(--sheet); border: 1px solid var(--ink); }
.ghost, .lang-form button { background: transparent; border: 1px solid var(--line); }
.text-button { background: transparent; border: 0; padding-inline: 0.2rem; color: var(--muted); }
.text-button.danger { color: var(--red); }

.empty {
  margin-top: 1.2rem;
  padding: 1.2rem;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.55);
}

fieldset { border: 1px solid var(--line); margin: 1rem 0; padding: 0.8rem 1rem 1rem; }
.groups-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-top: 0.4rem;
}
.groups-head h2 { margin: 0; font-size: 1rem; letter-spacing: 0; text-transform: none; color: var(--ink); }
.group-editor { padding: 0.85rem; margin-top: 0.7rem; }
.group-editor-head input, .add-concept input {
  flex: 1 1 12rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}
.add-concept { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.form-actions { margin-top: 1rem; }

.usage-box { margin-top: 0.85rem; }
.kinds { margin: 1rem 0 0; padding: 0; border: none; background: transparent; }
.kinds .choices { margin-top: 0.45rem; gap: 0.45rem 0.85rem; }
.choice { position: relative; display: inline-flex; align-items: center; gap: 0.28rem; }
.info {
  width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.68rem;
  font-style: italic;
  line-height: 1;
  flex: 0 0 auto;
}
.info:hover, .info[aria-expanded="true"] { color: var(--ink); border-color: var(--ink); }
.tip {
  display: none;
  position: absolute;
  z-index: 4;
  top: calc(100% + 0.35rem);
  left: 0;
  width: max-content;
  max-width: 16rem;
  padding: 0.45rem 0.65rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.35;
  box-shadow: 0 8px 18px rgba(36, 28, 22, 0.08);
}
.info:hover + .tip,
.info:focus + .tip,
.info[aria-expanded="true"] + .tip { display: block; }
.usage-word {
  margin: 0.35rem 0 0.1rem;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 700;
}
.usage-kind, .card .kind {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.usage-line { margin: 0; font-size: 0.92rem; }
.usage-detail {
  margin: 0.15rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.banner {
  margin: 0.8rem 0 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: var(--red-soft);
}
.banner.success { background: var(--green-soft); color: var(--green); }
.colophon { margin-top: 2.5rem; font-size: 0.9rem; }

@media (max-width: 640px) {
  .groups-head, .card-top { align-items: stretch; flex-direction: column; }
}
