/* ── Reset & Base ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Google Dark palette */
  --bg: #202124;
  --surface: #292a2d;
  --surface-2: #35363a;
  --border: #3c4043;
  --border-focus: #8ab4f8;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #8ab4f8;
  --accent-dim: #1a3a5c;
  --danger: #f28b82;
  --danger-dim: #4a1515;
  --success: #81c995;
  --success-dim: #1a3a25;
  --copy-flash: #fdd663;
  --copy-flash-dim: #3d3000;
  --highlight-dup: #f28b82;

  --radius: 6px;
  --font: 'JetBrains Mono', 'Fira Mono', 'Consolas', monospace;
  --font-ui: -apple-system, 'Segoe UI', sans-serif;
  --line-num-w: 3.2rem;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* ── Layout wrapper ── */
.input-block,
.list-block,
.footer-block {
  width: 100%;
  max-width: 750px;
}

/* ── Input Block ── */
.input-block {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 12px 0;
  border-bottom: 1px solid var(--border);
}

.input-row {
  display: flex;
  gap: 8px;
}

.word-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.word-input:focus {
  border-color: var(--border-focus);
}

.word-input::placeholder {
  color: var(--text-muted);
}

.save-btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.save-btn:hover {
  background: var(--accent);
  color: #202124;
}

.save-btn:active {
  opacity: 0.8;
}

/* ── Suggestions ── */
.suggestions {
  min-height: 34px;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow: hidden;
  align-items: center;
}

.suggestions:empty::before {
  content: '';
}

.suggestion-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

/* highlight duplicate chip */
.suggestion-chip.is-dup {
  border-color: var(--highlight-dup);
  color: var(--highlight-dup);
  animation: pulse-dup 0.6s ease;
}

@keyframes pulse-dup {
  0% {
    background: var(--danger-dim);
  }

  50% {
    background: #6a2020;
  }

  100% {
    background: var(--surface-2);
  }
}

/* ── Word List Block ── */
.list-block {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 8px;
  /* leave space for footer */
  padding-bottom: 44px;
}

.word-list {
  width: 100%;
}

/* ── Word Row ── */
.word-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid transparent;
  transition: background 0.1s;
}

.word-row:hover {
  background: var(--surface);
}

.line-num {
  width: var(--line-num-w);
  min-width: var(--line-num-w);
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
  padding: 6px 10px 6px 4px;
  user-select: none;
  flex-shrink: 0;
  line-height: 1.6;
  opacity: 0.6;
}

.word-cell {
  flex: 1;
  padding: 6px 8px;
  outline: none;
  word-break: break-all;
  line-height: 1.6;
  caret-color: var(--accent);
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}

.word-cell:focus {
  cursor: text;
  border-left-color: var(--border-focus);
  background: var(--surface);
}

/* Copy flash */
.word-cell.copied {
  background: var(--copy-flash-dim) !important;
  color: var(--copy-flash);
  border-left-color: var(--copy-flash);
  animation: flash-copy 0.9s ease forwards;
}

@keyframes flash-copy {
  0% {
    background: #5a4500;
    color: var(--copy-flash);
  }

  60% {
    background: var(--copy-flash-dim);
  }

  100% {
    background: transparent;
    color: var(--text);
  }
}

/* Duplicate highlight in list */
.word-cell.is-dup-list {
  background: var(--danger-dim) !important;
  color: var(--highlight-dup);
  border-left-color: var(--highlight-dup);
  animation: flash-dup 1.2s ease forwards;
}

@keyframes flash-dup {
  0% {
    background: #6a1010;
  }

  50% {
    background: var(--danger-dim);
  }

  100% {
    background: transparent;
    color: var(--text);
  }
}

/* Saving indicator */
.word-row.saving .word-cell {
  border-left-color: var(--text-muted);
}

.word-row.saved .word-cell {
  border-left-color: var(--success);
  animation: flash-saved 0.8s ease forwards;
}

@keyframes flash-saved {
  0% {
    border-left-color: var(--success);
  }

  100% {
    border-left-color: transparent;
  }
}

/* ── Footer ── */
.footer-block {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
}

.word-count-label {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-muted);
}

#wordCount {
  color: var(--accent);
  font-weight: 600;
}

/* ── Scrollbar ── */
.list-block::-webkit-scrollbar {
  width: 6px;
}

.list-block::-webkit-scrollbar-track {
  background: transparent;
}

.list-block::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.list-block::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Desktop ── */
@media (min-width: 600px) {
  .input-block {
    padding: 16px 16px 0;
  }

  .word-input {
    font-size: 15px;
    padding: 10px 14px;
  }

  .save-btn {
    font-size: 14px;
    padding: 10px 20px;
  }

  .word-cell,
  .line-num {
    font-size: 14px;
  }
}