@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
}

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-subtle: #ebedf0;
  --border: #dfe3ea;
  --border-strong: #c7cdd8;
  --text: #111827;
  --text-muted: #5b6472;
  --text-light: #8a93a2;
  --accent: #111827;
  --accent-text: #ffffff;
  --accent-hover: #374151;
  --focus-ring: rgba(17, 24, 39, 0.08);
  --badge-bg: rgba(255, 255, 255, 0.85);
  --backdrop: rgba(17, 24, 39, 0.4);
  --error: #dc2626;
  --info: #2563eb;

  --tier-win: #16a34a;
  --tier-win-bg: rgba(34, 197, 94, 0.18);
  --tier-close: #15803d;
  --tier-close-bar: #86efac;
  --tier-mid: #b45309;
  --tier-mid-bar: #fcd34d;
  --tier-far: #b91c1c;
  --tier-far-bar: #fca5a5;
  --latest-border: #94a3b8;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #171a22;
  --surface-subtle: #202430;
  --border: #262b38;
  --border-strong: #343b4d;
  --text: #e6e8ee;
  --text-muted: #9aa3b2;
  --text-light: #6b7485;
  --accent: #e6e8ee;
  --accent-text: #0f1117;
  --accent-hover: #ffffff;
  --focus-ring: rgba(230, 232, 238, 0.12);
  --badge-bg: rgba(15, 17, 23, 0.65);
  --backdrop: rgba(0, 0, 0, 0.65);
  --error: #f87171;
  --info: #60a5fa;

  --tier-win: #22c55e;
  --tier-win-bg: rgba(34, 197, 94, 0.16);
  --tier-close: #4ade80;
  --tier-close-bar: rgba(34, 197, 94, 0.30);
  --tier-mid: #fbbf24;
  --tier-mid-bar: rgba(245, 158, 11, 0.28);
  --tier-far: #f87171;
  --tier-far-bar: rgba(239, 68, 68, 0.26);
  --latest-border: #4b5568;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.game-pill {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn-icon {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
}

.btn-icon:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-primary {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  padding: 0 18px;
  height: 46px;
  border-radius: var(--radius);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

/* Stats bar */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 2px 18px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.stats-bar strong {
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
}

/* Guess Input */
.guess-form {
  display: flex;
  gap: 8px;
}

.guess-form input {
  flex: 1;
  height: 46px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.guess-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.guess-form input:disabled {
  background: var(--surface-subtle);
  color: var(--text-muted);
}

/* Feedback message */
.feedback {
  min-height: 24px;
  margin: 8px 2px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.feedback.error {
  color: var(--error);
}

.feedback.info {
  color: var(--info);
}

/* Win / Give-up Banner */
.win-banner {
  background: var(--surface);
  border: 1.5px solid var(--tier-win);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.win-banner.gave-up {
  border-color: var(--border-strong);
}

.win-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.win-header p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.top-words-wrap {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.top-words-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.top-words-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 0.8rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip .chip-rank {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.win-actions {
  margin-top: 16px;
}

.win-actions .btn-primary {
  height: 38px;
  font-size: 0.85rem;
  padding: 0 16px;
}

/* Sections */
.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.vocab-note {
  font-size: 0.75rem;
  color: var(--text-light);
}

.latest-section {
  margin-bottom: 22px;
}

.latest-section .section-label {
  display: block;
  margin-bottom: 8px;
}

/* Guess Row */
.guess-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.guess-row {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.guess-row.is-latest {
  border-color: var(--latest-border);
}

.guess-row.is-win {
  border-color: var(--tier-win);
  background: var(--tier-win-bg);
}

.guess-row.pulse {
  animation: pulse-highlight 0.55s ease;
}

@keyframes pulse-highlight {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(17, 24, 39, 0.25); }
  50% { transform: scale(1.015); box-shadow: 0 0 0 5px rgba(17, 24, 39, 0.08); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(17, 24, 39, 0); }
}

.guess-bar {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  transition: width 0.3s ease;
}

.guess-word-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.guess-word {
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.hint-badge {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--badge-bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
}

.guess-meta {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tier-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.guess-rank {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.92rem;
  font-weight: 600;
  min-width: 58px;
  text-align: right;
}

/* 3 clean closeness tiers: close (green), mid (amber), far (red) */
.tier-close .guess-bar { background: var(--tier-close-bar); }
.tier-close .guess-rank { color: var(--tier-close); }

.tier-mid .guess-bar { background: var(--tier-mid-bar); }
.tier-mid .guess-rank { color: var(--tier-mid); }

.tier-far .guess-bar { background: var(--tier-far-bar); }
.tier-far .guess-rank { color: var(--tier-far); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.92rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.empty-state strong {
  color: var(--text);
}

.empty-sub {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--text-light);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow-md);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-body {
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-body h3 {
  font-size: 0.9rem;
  color: var(--text);
  margin-top: 4px;
}

.modal-body ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-body strong {
  color: var(--text);
}

.picker-actions {
  margin-bottom: 14px;
}

.picker-actions .btn-primary {
  width: 100%;
  height: 40px;
  font-size: 0.86rem;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.game-tile {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 10px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: center;
}

.game-tile:hover {
  border-color: var(--accent);
}

.game-tile.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.game-tile.solved {
  background: var(--tier-win-bg);
  border-color: var(--tier-win);
  color: var(--tier-close);
}

.game-tile.active.solved {
  background: var(--tier-win);
  color: #ffffff;
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  .app { padding: 18px 14px 48px; }
  .topbar { flex-wrap: wrap; }
  .game-grid { grid-template-columns: repeat(4, 1fr); }
}
