:root {
  --paper: #f6f1e7;
  --paper-deep: #ece4d3;
  --ink: #1f1b16;
  --ink-soft: #6b6156;
  --ink-faint: #a69b8c;
  --rule: #d8ccb6;
  --accent: #9b2c1f;
  --correct: #2f6b3b;
  --correct-bg: #dcebd5;
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, rgba(255, 255, 255, 0.55), transparent 60%), var(--paper);
}

button, input { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- masthead ---------- */

.masthead {
  border-bottom: 3px double var(--ink);
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 10px;
}
.masthead-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}
nav { display: flex; gap: 6px; }
.edition {
  margin: 2px 0 0;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

/* ---------- buttons ---------- */

.chip, .primary, .link {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.chip { border: 1px solid var(--rule); background: transparent; padding: 5px 14px; }
.chip:hover { background: var(--paper-deep); }
.chip.icon { width: 32px; padding: 5px 0; font-weight: 600; }
.primary {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 22px;
  font-weight: 600;
}
.primary:hover { background: #3a3229; }
.primary:active, .chip:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.6; cursor: progress; }
.link {
  border: none;
  background: none;
  padding: 0;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 13px;
}
.link:hover { color: var(--accent); }
.link.armed { color: var(--accent); font-weight: 600; }

/* ---------- entry ---------- */

.headline { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.headword {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(44px, 9vw, 64px);
  line-height: 1.05;
  margin: 0;
  letter-spacing: -0.01em;
}
.headword.done { color: var(--accent); }
.pos { font-family: var(--display); font-style: italic; font-size: 22px; color: var(--ink-soft); }

.definition {
  font-size: clamp(20px, 3.4vw, 25px);
  line-height: 1.4;
  margin: 22px 0 0;
}
.sense { font-weight: 600; margin-right: 2px; }
.filler { color: var(--ink-soft); }

.prompt {
  margin: 10px 0 0;
  font-size: 19px;
  color: var(--ink-soft);
}

.rank {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.78em;
  font-weight: 600;
  padding: 0 7px;
  border-radius: 999px;
  background: hsl(var(--h) 80% 90%);
  color: hsl(var(--h) 55% 30%);
  vertical-align: 0.08em;
}

/* ---------- feedback ---------- */

.feedback {
  margin-top: 18px;
  padding: 16px 20px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.5);
  animation: rise 0.3s ease-out;
}
.feedback p { margin: 0; }
.verdict { font-size: 20px; }
.verdict .word {
  font-family: var(--display);
  font-size: 1.25em;
  color: var(--accent);
}
.sense { margin-top: 6px !important; color: var(--ink-soft); font-size: 16px; }
.standing { margin-top: 12px !important; font-size: 16px; }
.nearby {
  margin-top: 4px !important;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-faint);
}

/* ---------- guess input ---------- */

.guess-form {
  margin-top: 26px;
  display: flex;
  gap: 10px;
}
.guess-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--serif);
  font-size: 19px;
  padding: 10px 16px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.guess-form input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(31, 27, 22, 0.08);
}
.guess-form input::placeholder { color: var(--ink-faint); font-style: italic; }

/* ---------- result ---------- */

.result {
  margin-top: 20px;
  padding: 18px 20px;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  background: rgba(255, 255, 255, 0.45);
  animation: rise 0.4s ease-out;
}
.result-kicker { margin: 0; font-family: var(--display); font-size: 24px; font-weight: 700; }
.official { margin: 8px 0 0; font-size: 19px; }
.official em { color: var(--ink-soft); }
.result-stats { margin: 6px 0 14px; color: var(--ink-soft); font-size: 16px; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- history ---------- */

.history { margin-top: 30px; }
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
  margin-bottom: 4px;
}
.history h2 {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 0;
}
.history-list { margin: 0; padding-left: 2.2em; font-size: 17px; line-height: 1.7; }
.history-list li { padding: 6px 0; border-bottom: 1px dotted var(--rule); }
.history-list li::marker { font-family: var(--sans); font-size: 12px; color: var(--ink-faint); }
.guess-text { font-style: italic; }
.arrow { color: var(--ink-faint); margin: 0 8px; }
.match { font-weight: 600; margin-right: 8px; }
.match.correct { color: var(--correct); }

/* ---------- dialog / toast ---------- */

dialog {
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  max-width: 540px;
  padding: 24px 28px;
  box-shadow: 0 20px 60px rgba(31, 27, 22, 0.25);
}
dialog::backdrop { background: rgba(31, 27, 22, 0.35); }
dialog h2 { font-family: var(--display); margin-top: 0; }
dialog p, dialog li { font-size: 16px; }
.example { background: var(--paper-deep); padding: 4px 14px; border-radius: 6px; }
.example p { margin: 8px 0; font-size: 15px; }
.example .pos { font-size: 15px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  padding: 8px 18px;
  border-radius: 999px;
  animation: rise 0.25s ease-out;
}

@keyframes pop {
  0% { transform: scale(0.85); opacity: 0.2; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes rise {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.shake { animation: shake 0.35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 520px) {
  body { font-size: 16px; }
  .wordmark { font-size: 28px; }
  .guess-form { flex-direction: column; }
}
