:root {
  --paper: #f3f5fa;
  --panel: #e4e8f1;
  --field: #ffffff;
  --ink: #111827;
  --ink-soft: #4b5567;
  --rule: #cdd3e2;
  --cobalt: #2542d6;
  --scrim: rgba(17, 24, 39, 0.58);
  --mark: #ffd84d;
  --good: #0b7a4b;
  --bad: #b4281a;
  --display: 'Archivo Black', 'Arial Black', Arial, sans-serif;
  --body: Arial, Helvetica, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1424;
    --panel: #171d33;
    --field: #0b0f1d;
    --ink: #eef1fa;
    --ink-soft: #a5aec4;
    --rule: #2a3350;
    --cobalt: #8ea2ff;
    --scrim: rgba(0, 0, 0, 0.68);
    --good: #4fd18b;
    --bad: #ff8b7a;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 var(--body);
}

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

/* Layout: play area on the left, words and wins in a bar on the right */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(18rem, 26vw, 25rem);
  min-height: 100vh;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
}

.stage-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
}

.wordmark { margin: 0; font: 400 1.125rem/1.2 var(--display); }

.status { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1.25rem; color: var(--ink-soft); font-size: 0.9375rem; }
.status #score { font-weight: 700; color: var(--ink); }

.play {
  width: 100%;
  max-width: 46rem;
  margin: auto 0;
  align-self: center;
  padding: 2rem 0;
}

.prompt { margin: 0; color: var(--ink-soft); font-size: 1.0625rem; }

/* The words themselves are the page's loudest element */
.target-words {
  display: flex;
  flex-wrap: wrap;
  gap: 0.05em 0.4em;
  margin: 0.25rem 0 1.75rem;
  font: 400 clamp(2.5rem, 9vw, 6rem)/1.05 var(--display);
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.target-words.n2 { font-size: clamp(2.25rem, 7vw, 4.5rem); }
.target-words.n3 { font-size: clamp(2rem, 5.5vw, 3.5rem); }

/* Highlighter underline that fills in once the word appears in the sentence */
.tw {
  background-image: linear-gradient(var(--mark), var(--mark));
  background-repeat: no-repeat;
  background-position: 0 94%;
  background-size: 0% 0.22em;
  transition: background-size 0.25s ease;
}
.tw.used { background-size: 100% 0.22em; }

textarea {
  display: block;
  width: 100%;
  min-height: 8.5rem;
  padding: 1rem 1.125rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: 1.375rem/1.45 var(--body);
  resize: vertical;
}
textarea::placeholder { color: var(--ink-soft); opacity: 0.8; }
textarea:disabled { opacity: 0.6; }

textarea:focus-visible, button:focus-visible {
  outline: 3px solid var(--cobalt);
  outline-offset: 2px;
}

.entry-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  margin-top: 0.75rem;
}
.entry-bar p { margin: 0; color: var(--ink-soft); font-size: 0.9375rem; }
.entry-bar .tries { margin-right: auto; }

button {
  font: 400 1rem/1 var(--display);
  cursor: pointer;
}

#check, .btn {
  padding: 0.85rem 1.5rem;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
}
#check:hover:not(:disabled), .btn:hover { background: var(--cobalt); color: #fff; }
#check:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--ink);
}
.btn.secondary:hover { background: var(--ink); color: var(--paper); }

/* Feedback after a check */
.feedback { margin-top: 1.5rem; }
.fb-head { margin: 0 0 0.25rem; font: 400 1.75rem/1.15 var(--display); }
.fb-head.win { color: var(--good); }
.fb-head.close { color: var(--cobalt); }
.fb-head.miss { color: var(--bad); }
.fb-sub { margin: 0 0 1rem; color: var(--ink-soft); }

.verdicts { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.5rem; }
.verdicts li { padding: 0.5rem 0.75rem; border-left: 4px solid var(--rule); background: color-mix(in srgb, var(--field) 70%, transparent); }
.verdicts li.ok { border-left-color: var(--good); }
.verdicts li.no { border-left-color: var(--bad); }
.verdicts .v-word { font-weight: 700; }
.verdicts .v-tag { margin-left: 0.5rem; font-size: 0.875rem; }
.verdicts li.ok .v-tag { color: var(--good); }
.verdicts li.no .v-tag { color: var(--bad); }
.verdicts .v-reason { display: block; color: var(--ink-soft); font-size: 0.9375rem; }

.problems { margin: 0 0 1rem; padding-left: 1.25rem; }
.problems li { margin: 0.25rem 0; }

.fb-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* Judge status (shown in the footer and in the instructions panel) */
#footer-judge { padding-top: 1rem; }
.judge-status {
  display: grid;
  gap: 0.4rem;
  justify-items: start;
  max-width: 30rem;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}
.judge-status p { margin: 0; }
.judge-status .js-label { color: var(--ink); font-weight: 700; }
.judge-status progress { width: 100%; }

progress {
  height: 1rem;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background-color: var(--field);
  overflow: hidden;
  accent-color: var(--cobalt);
}
progress::-webkit-progress-bar { background: var(--field); }
progress::-webkit-progress-value { background: var(--cobalt); transition: width 0.2s ease; }
progress::-moz-progress-bar { background: var(--cobalt); }
progress:indeterminate {
  background-image: linear-gradient(90deg, var(--cobalt) 0 35%, transparent 35%);
  background-size: 45% 100%;
  background-repeat: no-repeat;
  animation: slide 1.1s linear infinite;
}
@keyframes slide { from { background-position: -50% 0; } to { background-position: 150% 0; } }

.link-btn {
  padding: 0.4rem 0.75rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 0.875rem;
}
.link-btn:hover { background: var(--ink); color: var(--paper); }

/* Right-hand bar */
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 1.25rem 2rem;
  background: var(--panel);
}
.side h2 { margin: 0 0 0.5rem; font: 400 1.25rem/1.2 var(--display); }
.side .wins-title { margin-top: 2rem; }

.side-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.5rem; }
.side-head h2 { margin: 0; }
.toggle-btn {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font: 400 0.8125rem/1.2 var(--body);
}
.toggle-btn:hover { color: var(--ink); border-color: var(--ink); }
.toggle-btn:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; }

.word { margin-bottom: 0.6rem; padding: 0.75rem 0.9rem; background: var(--field); border: 1px solid var(--rule); border-radius: 10px; }
.word h3 { margin: 0; font: 400 1.5rem/1.2 var(--display); letter-spacing: -0.01em; }
.word .meta { display: flex; flex-wrap: wrap; gap: 0 0.75rem; margin: 0.15rem 0 0.35rem; color: var(--ink-soft); font-size: 0.875rem; }
.word .def { margin: 0; }

.win { margin-bottom: 0.6rem; padding: 0.7rem 0.9rem; background: var(--field); border: 1px solid var(--rule); border-radius: 10px; }
.win .win-head { display: flex; justify-content: space-between; gap: 0.75rem; }
.win .win-words { font-weight: 700; overflow-wrap: anywhere; }
.win .win-pts { font: 400 1rem/1.5 var(--display); color: var(--good); white-space: nowrap; }
.win p { margin: 0.25rem 0 0; color: var(--ink-soft); font-size: 0.875rem; font-style: italic; }
.empty { margin: 0; color: var(--ink-soft); font-size: 0.9375rem; }

.help-btn {
  padding: 0.3rem 0.7rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: 400 0.8125rem/1.2 var(--display);
}
.help-btn:hover { background: var(--ink); color: var(--paper); }
.help-btn:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; }

/* Instructions: the page behind is dimmed and the panel floats above it */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: var(--scrim);
}
.panel {
  position: relative;
  width: min(100%, 30rem);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1.5rem 1.5rem 1.25rem;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
.panel h2 { margin: 0 3rem 0.75rem 0; font: 400 1.5rem/1.2 var(--display); }
.panel h3 { margin: 1.25rem 0 0.5rem; font: 400 1.0625rem/1.2 var(--display); }
.rules { display: grid; gap: 0.5rem; margin: 0; padding-left: 1.25rem; }
.close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
}
.close:hover { background: var(--ink); color: var(--paper); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .play { padding: 1.5rem 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tw { transition: none; }
  progress:indeterminate { animation: none; background-image: none; }
  progress::-webkit-progress-value { transition: none; }
}
