 :root {
    --ink: #1c2321;
    --ink-soft: #cfc7b6;
    --parchment: #f4ede0;
    --parchment-dim: #e8dfcd;
    --gold: #c79a3d;
    --gold-dim: #9c7a2f;
    --correct: #4f7857;
    --incorrect: #b54b3a;
    --line: #d8cdb4;
}
 
* { box-sizing: border-box; }
 
body {
    margin: 0;
    min-height: 100vh;
    background: var(--ink);
    background-image:
      radial-gradient(circle at 20% 20%, rgba(199,154,61,0.05), transparent 40%),
      radial-gradient(circle at 80% 80%, rgba(199,154,61,0.04), transparent 40%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    font-family: 'Inter', sans-serif;
}
 
.card {
    width: 100%;
    max-width: 480px;
    background: var(--parchment);
    border-radius: 4px;
    box-shadow: 0 30px 60px -20px rgba(0,0,0,0.6), 0 0 0 1px rgba(199,154,61,0.15);
    padding: 40px 36px 32px;
    position: relative;
    overflow: hidden;
}
 
.card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--gold-dim), var(--gold), var(--gold-dim));
}

.sound-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  color: var(--ink);
  opacity: 0.45;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.sound-toggle:hover { opacity: 0.8; background: rgba(28,35,33,0.06); }
.sound-toggle svg { width: 100%; height: 100%; }
 
.eyebrow {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--gold-dim);
    margin: 0 0 6px;
}
 
h1 {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 32px;
    color: var(--ink);
    margin: 0 0 28px;
    letter-spacing: -0.01em;
}
 
.play-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}
 
.play-btn {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    background: var(--ink);
    color: var(--parchment);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, background 0.15s ease;
}
 
.play-btn:hover { background: #2c3531; transform: scale(1.04); }
.play-btn:active { transform: scale(0.97); }

.play-btn svg { width: 22px; height: 22px; }
 
.wave {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    flex: 1;
}
 
.wave span {
    display: block;
    width: 4px;
    border-radius: 2px;
    background: var(--gold-dim);
    height: 8px;
    transition: background 0.2s ease;
}
 
.wave.playing span {
    background: var(--gold);
    animation: bounce 0.9s ease-in-out infinite;
}
 
.wave span:nth-child(1) { animation-delay: 0s; }
.wave span:nth-child(2) { animation-delay: 0.1s; }
.wave span:nth-child(3) { animation-delay: 0.2s; }
.wave span:nth-child(4) { animation-delay: 0.3s; }
.wave span:nth-child(5) { animation-delay: 0.4s; }
.wave span:nth-child(6) { animation-delay: 0.3s; }
.wave span:nth-child(7) { animation-delay: 0.2s; }
.wave span:nth-child(8) { animation-delay: 0.1s; }
 
@keyframes bounce {
    0%, 100% { height: 8px; }
    50% { height: 28px; }
}
 
@media (prefers-reduced-motion: reduce) {
    .wave.playing span { animation: none; height: 18px; }
}
 
form { margin-bottom: 8px; }
 
label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.55;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  gap: 8px;
}

.tries {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--gold-dim);
  white-space: nowrap;
}
 
.input-row {
    display: flex;
    gap: 10px;
}
 
#word-input {
    flex: 1;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 20px;
    letter-spacing: 0.06em;
    padding: 14px 16px;
    border: 2px solid var(--line);
    border-radius: 3px;
    background: #fffdf8;
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s ease;
}
 
#word-input:focus { border-color: var(--gold); }
 
#word-input.correct { border-color: var(--correct); }
#word-input.incorrect { border-color: var(--incorrect); animation: shake 0.3s ease; }
 
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}
 
#submit-btn {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 14px;
    padding: 0 24px;
    border: none;
    border-radius: 3px;
    background: var(--gold);
    color: var(--ink);
    cursor: pointer;
    transition: background 0.15s ease;
}
 
#submit-btn:hover { background: #d8ab4c; }
#submit-btn:active { background: var(--gold-dim); }
 
.feedback {
    min-height: 22px;
    margin-top: 14px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
}
 
.feedback.correct { color: var(--correct); }
.feedback.incorrect { color: var(--incorrect); }

.keyboard {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
 
.kb-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}
 
.kb-row-offset { padding: 0 16px; }
 
.key {
    flex: 1;
    min-width: 0;
    padding: 0;
    height: 44px;
    border: none;
    border-radius: 4px;
    background: #fffdf8;
    border: 1px solid var(--line);
    color: var(--ink);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 15px;
    text-transform: lowercase;
    cursor: pointer;
    transition: background 0.1s ease, transform 0.1s ease;
}
 
.key:hover { background: var(--parchment-dim); }
.key:active { background: var(--gold); transform: scale(0.94); }
 
.key-wide {
    flex: 1.6;
    min-width: 0;
    font-size: 16px;
    background: var(--ink);
    color: var(--parchment);
    border-color: var(--ink);
}
 
.key-wide:hover { background: #2c3531; }
.key-wide:active { background: #101513; transform: scale(0.96); }
 
.key-enter { background: var(--gold-dim); border-color: var(--gold-dim); }
.key-enter:hover { background: var(--gold); }
.key-enter:active { background: var(--gold-dim); }

.ledger {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
}
 
.stat {
    text-align: center;
    flex: 1;
}
 
.stat-value {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 24px;
    color: var(--ink);
    display: block;
}
 
.stat-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink);
    opacity: 0.5;
}

.reset-btn {
  display: block;
  margin: 16px auto 0;
  background: none;
  border: none;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink);
  opacity: 0.4;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px 8px;
  transition: opacity 0.15s ease;
}

.reset-btn:hover { opacity: 0.75; }

.footer-actions {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
}

.footer-actions .reset-btn { margin-top: 0; }

.footer-actions .reset-btn:not(:last-child)::after {
  content: "·";
  margin-left: 12px;
  opacity: 0.5;
}

.modal-history { max-width: 400px; }

.history-list {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.history-date {
  color: var(--ink);
  opacity: 0.6;
}

.history-figures {
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.history-pct {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--correct);
}

.history-raw {
  color: var(--ink);
  opacity: 0.5;
  font-size: 11px;
}

.history-item-delete {
  background: none;
  border: none;
  color: var(--ink);
  opacity: 0.35;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  margin-left: 4px;
  border-radius: 3px;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.history-item-delete:hover {
  opacity: 1;
  color: var(--incorrect);
}

.clear-all-row {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.clear-all-btn {
  background: none;
  border: none;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--incorrect);
  opacity: 0.6;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px 8px;
  transition: opacity 0.15s ease;
}

.clear-all-btn:hover { opacity: 1; }

.clear-confirm-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(181, 75, 58, 0.08);
  border: 1px solid rgba(181, 75, 58, 0.25);
  border-radius: 3px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.clear-confirm-row.visible { display: flex; }

.clear-confirm-text {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--ink);
}

.clear-confirm-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.clear-confirm-actions .modal-btn {
  padding: 6px 12px;
  font-size: 12px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 35, 33, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 100;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--parchment);
  border-radius: 4px;
  max-width: 360px;
  width: 100%;
  padding: 28px 26px 22px;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.6);
  transform: translateY(8px);
  transition: transform 0.15s ease;
}

.modal-overlay.visible .modal { transform: translateY(0); }

.modal-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--ink);
  margin: 0 0 10px;
}

.modal-body {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  opacity: 0.75;
  margin: 0 0 22px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 3px;
  cursor: pointer;
  border: none;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.modal-btn-cancel {
  background: transparent;
  color: var(--ink);
  opacity: 0.6;
}

.modal-btn-cancel:hover { opacity: 1; }

.modal-btn-confirm {
  background: var(--incorrect);
  color: var(--parchment);
}

.modal-btn-confirm:hover { background: #9c3d30; }

@media (max-width: 420px) {
    body { padding: 20px 12px; }
 
    .card { padding: 28px 20px 24px; }
 
    h1 { font-size: 26px; margin-bottom: 22px; }
 
    .play-btn { width: 54px; height: 54px; }
 
    .input-row { flex-wrap: wrap; }
 
    #word-input {
      font-size: 18px;
      padding: 12px 14px;
      min-width: 0;
      flex-basis: 100%;
    }
 
    #submit-btn {
      flex: 1;
      padding: 14px 0;
    }
 
    .ledger { flex-wrap: wrap; gap: 12px 0; }
 
    .stat-value { font-size: 20px; }

    .kb-row { gap: 4px; }
    .kb-row-offset { padding: 0 8px; }
    .key { font-size: 13px; }
    .key-wide { font-size: 14px; }
}