:root {
  /* Beige page + Nebelung greys for surfaces; emerald accents */
  --slate: #2d3945;
  --silver: #696470;
  --emerald: #3b7a57;
  --bg1: #faf6f0;
  --bg2: #f3ebe0;
  --ink: var(--slate);
  --muted: var(--silver);
  /* Cards / fields match left panel beige */
  --card: #faf6f0;
  --field: #faf6f0;
  --accent: var(--emerald);
  --accent-dark: #2f6246;
  --accent-soft: rgba(59, 122, 87, 0.12);
  --warn: #9a3412;
  --warn-bg: #ffedd5;
  --line: rgba(45, 57, 69, 0.14);
  --shadow: 0 10px 30px rgba(45, 57, 69, 0.1);
  --radius: 18px;
  --tap: 48px;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

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

body {
  background: var(--bg1);
  min-height: 100dvh;
}

/* Viewport-fixed wash so My words filter height cannot remap the gradient */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 0%, rgba(59, 122, 87, 0.1) 0%, transparent 44%),
    radial-gradient(circle at 92% 8%, rgba(243, 217, 176, 0.55) 0%, transparent 42%),
    linear-gradient(165deg, var(--bg1), var(--bg2));
}

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

.app {
  display: flex;
  align-items: stretch;
  max-width: 780px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 1.25rem 1.1rem 2.5rem;
}

.top {
  margin-bottom: 1.75rem;
}

.top h1 {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  margin: 0.2rem 0 0.2rem;
  letter-spacing: -0.02em;
}

.app[data-view="history"] .top,
.app[data-view="settings"] .top {
  display: none;
}

.tagline,
.hint,
.empty {
  color: var(--muted);
  margin: 0;
}

.tabs {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 52px;
  min-height: 100dvh;
  margin: 0;
  padding: 0.85rem 0.3rem;
  background: rgba(250, 246, 240, 0.72);
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  flex-shrink: 0;
}

.tab {
  min-height: 42px;
  min-width: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
}

.tab-icon {
  width: 1.55rem;
  height: 1.55rem;
  display: block;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  box-shadow: none;
}

.tab:hover:not(.active) {
  color: var(--ink);
}

.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.lookup-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

.search-field {
  position: relative;
  min-width: 0;
}

#word-input,
select {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 1.15rem;
  background: var(--field);
}

#word-input {
  width: 100%;
  padding-right: 2.75rem;
}

#provider-select {
  display: inline-block;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
  /* Extra room between label text, custom arrow, and right edge */
  padding: 0.75rem 2.85rem 0.75rem 1rem;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--field);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23696470' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1.05rem center;
  background-size: 1rem;
  cursor: pointer;
}

.clear-btn {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.clear-btn:hover {
  background: rgba(45, 57, 69, 0.08);
  color: var(--ink);
}

.clear-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 1.1rem;
  font: inherit;
  font-weight: 800;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status,
.suggestions,
.word-list,
.field {
  margin-top: 1rem;
}

.status {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
}

.status.warn,
.adult-banner {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: rgba(154, 52, 18, 0.2);
}


.lookup-result-wrap {
  margin-top: 1rem;
}

.lookup-result-wrap > .adult-banner {
  margin-bottom: 0.75rem;
}

.lookup-result-wrap > .history-item {
  margin-bottom: 0;
}

.word-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.word-row h2 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 2rem;
  margin: 0;
}

.history-word {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35em;
  row-gap: 0.15em;
}

.history-phonetic {
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 0.55em;
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}

.word-ending {
  color: var(--accent-dark);
  text-decoration: underline;
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.12em;
}

.form-note {
  margin: 0.15rem 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-dark);
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0.2em;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}

.speak-btn svg {
  width: 1em;
  height: 1em;
  display: block;
}

.speak-btn:hover {
  color: var(--accent);
}

.speak-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


.phonetic {
  color: var(--muted);
  margin: 0.35rem 0 0.8rem;
  font-size: 1.05rem;
}

.sense {
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
}

.sense:first-of-type {
  border-top: 0;
}

.history-senses {
  margin-top: 0.35rem;
}

.history-senses .sense:first-child {
  border-top: 1px solid var(--line);
}

.sense-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  gap: 0.55rem;
  align-items: start;
}

.sense-body {
  min-width: 0;
}

.star-btn {
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.1rem;
  padding: 0;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: #b8a990;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.star-btn.active {
  color: #d4a017;
}

.star-btn:not(.active):hover {
  color: #d4a017;
}

.star-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 40px;
  margin-top: 0.35rem;
  padding: 0.2rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
}

.expand-btn svg {
  width: 1.5rem;
  height: 1.5rem;
  display: block;
}

.expand-btn:hover {
  background: var(--accent-soft);
}

.expand-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pos {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-dark);
  margin-bottom: 0.25rem;
}

.examples {
  margin: 0.45rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
}


.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  min-height: 42px;
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.history-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 0.9rem;
  margin-bottom: 0.85rem;
  font: inherit;
  box-shadow: var(--shadow);
}

.history-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.history-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.4rem 0.75rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.95rem;
}

.footer-meta-start {
  justify-self: start;
}

.footer-meta-end {
  justify-self: end;
  text-align: right;
}

.delete-btn {
  min-height: 42px;
  min-width: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: 10px;
  flex-shrink: 0;
}

.delete-btn:hover {
  background: rgba(154, 52, 18, 0.08);
  color: var(--warn);
}

.field {
  display: grid;
  gap: 0.4rem;
  font-weight: 700;
}

.settings-delete {
  margin-top: 1.5rem;
}

.settings-delete .history-filter-chips {
  margin: 0.15rem 0 0.35rem;
}

#delete-range-btn {
  justify-self: start;
}

#delete-range-status {
  margin-top: 0.65rem;
}

.settings-backup {
  margin-top: 1.75rem;
}

.settings-backup .hint {
  margin: 0.15rem 0 0.6rem;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.undo-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.85rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.undo-btn {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font: inherit;
  font-weight: 700;
  padding: 0.28rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 34px;
}

.undo-btn:hover {
  background: var(--accent);
  color: #fff;
}

.undo-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

#delete-range-status.undo-bar {
  margin-top: 0.65rem;
}

.mirror-state {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
}

#backup-status {
  margin-top: 0.65rem;
}

.view-head {
  margin-bottom: 0.75rem;
}

.view-head h2 {
  margin: 0 0 0.2rem;
  font-family: "Fraunces", Georgia, serif;
}

#view-history .view-head,
#view-settings .view-head {
  margin-bottom: 1.25rem;
}

#view-history .view-head h2,
#view-settings .view-head h2 {
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0.2rem 0 0.35rem;
}

#view-history .view-head .hint {
  font-size: 0.95rem;
  font-weight: 500;
}

.history-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin: 0 0 1rem;
}

.history-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.filter-chip {
  min-height: 42px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
}

.filter-count {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
  margin-left: 0.2em;
}

.filter-chip.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.filter-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.word-index,
.word-index-spacer {
  justify-self: center;
  margin: 0;
  padding: 0 0.35rem;
  min-width: 1.5rem;
  height: auto;
  border-radius: 0;
  background: transparent;
  text-align: center;
  line-height: 1;
}

.word-index {
  color: var(--muted);
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: oldstyle-nums;
  letter-spacing: 0.03em;
  opacity: 0.72;
}

.word-index-spacer {
  visibility: hidden;
}

.empty {
  text-align: center;
  padding: 2rem 1rem;
}

@media (max-width: 480px) {
  .lookup-form {
    grid-template-columns: 1fr;
  }

  .history-footer {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0.35rem;
  }

  .footer-meta-start,
  .footer-meta-end {
    justify-self: center;
    text-align: center;
  }

  .word-index {
    order: -1;
  }
}
