:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface2: #f0ede8;
  --border: rgba(0, 0, 0, 0.1);
  --border2: rgba(0, 0, 0, 0.18);
  --text: #1a1917;
  --muted: #7a7774;
  --accent: #1a1917;
  --accent-fg: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: "Courier New", Courier, monospace;
  --serif: Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18171a;
    --surface: #232228;
    --surface2: #2c2b31;
    --border: rgba(255, 255, 255, 0.1);
    --border2: rgba(255, 255, 255, 0.2);
    --text: #f0ede8;
    --muted: #8a8790;
    --accent: #f0ede8;
    --accent-fg: #18171a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem 4rem;
}

header {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2.5rem;
}
.logo {
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-family: var(--mono);
  color: var(--muted);
}
.settings-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}
.settings-toggle:hover {
  color: var(--text);
}
.settings-toggle svg {
  width: 14px;
  height: 14px;
}

.main {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Settings panel ── */
.settings-panel {
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: none;
  flex-direction: column;
  gap: 1rem;
}
.settings-panel.open {
  display: flex;
}

.settings-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.field select,
.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.field select:focus,
.field input:focus {
  border-color: var(--text);
}

.field select option {
  background: var(--surface);
}

.engine-note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--border2);
}
.engine-note a {
  color: var(--text);
}

.divider {
  height: 0.5px;
  background: var(--border);
  margin: 0.25rem 0;
}

/* ── Setup panel ── */
.setup-panel {
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.section-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

textarea {
  width: 100%;
  height: 130px;
  resize: vertical;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.9;
  padding: 10px 12px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
textarea:focus {
  border-color: var(--text);
}
textarea::placeholder {
  color: var(--muted);
  font-style: italic;
}

.start-btn {
  align-self: flex-start;
  padding: 10px 26px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s;
}
.start-btn:hover {
  opacity: 0.78;
}

/* ── Game panel ── */
.game-panel {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.round-badge {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  white-space: nowrap;
}
.bar-bg {
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--text);
  border-radius: 99px;
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
.count-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  min-width: 40px;
  text-align: right;
}

.card-wrap {
  position: relative;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.word-card {
  width: 100%;
  height: 190px;
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 8vw, 56px);
  font-weight: bold;
  font-family: var(--serif);
  color: var(--text);
  letter-spacing: 0.02em;
  transition:
    opacity 0.2s,
    transform 0.2s;
  cursor: default;
  position: relative;
  overflow: hidden;
}
.word-card.hidden {
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
}
.word-text {
  transition:
    opacity 0.25s,
    filter 0.25s;
}
.word-text.concealed {
  opacity: 0;
  filter: blur(8px);
  user-select: none;
}
.hint-label {
  position: absolute;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  transition: opacity 0.25s;
}
.hint-label.hidden {
  opacity: 0;
}

.answer-reveal {
  margin-top: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 0.2s,
    transform 0.2s;
  pointer-events: none;
}
.answer-reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.speaking-dot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf82;
  opacity: 0;
  transition: opacity 0.2s;
}
.speaking-dot.active {
  opacity: 1;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.5);
    opacity: 0.5;
  }
}

.btn-row {
  display: flex;
  gap: 10px;
}
.btn {
  flex: 1;
  padding: 14px 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background 0.15s,
    opacity 0.15s,
    transform 0.1s;
  border: 0.5px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover {
  background: var(--surface2);
}
.btn:active {
  transform: scale(0.98);
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn.primary:hover {
  opacity: 0.82;
  background: var(--accent);
}

.btn-icon {
  font-size: 15px;
}

/* ── Done screen ── */
.done-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
  padding: 3.5rem 1rem;
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
}
.done-check {
  font-size: 36px;
  margin-bottom: 0.25rem;
}
.done-title {
  font-size: 22px;
  font-weight: bold;
  color: var(--text);
}
.done-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.reset-btn {
  margin-top: 0.5rem;
  padding: 9px 22px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  background: none;
  color: var(--muted);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    color 0.15s,
    border-color 0.15s;
}
.reset-btn:hover {
  color: var(--text);
  border-color: var(--text);
}

.error-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #b94040;
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  white-space: nowrap;
  z-index: 999;
}
.error-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
