:root {
  color-scheme: light;
  --canvas: oklch(97% 0.012 100);
  --surface: oklch(99% 0.006 100);
  --soft: oklch(94% 0.018 190);
  --ink: oklch(29% 0.025 245);
  --muted: oklch(51% 0.025 245);
  --line: oklch(88% 0.018 220);
  --accent: oklch(59% 0.105 195);
  --accent-strong: oklch(48% 0.105 195);
  --error: oklch(53% 0.17 28);
  --focus: oklch(55% 0.13 220);
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --font: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: oklch(18% 0.018 245);
  --surface: oklch(22% 0.02 245);
  --soft: oklch(27% 0.025 225);
  --ink: oklch(92% 0.014 220);
  --muted: oklch(70% 0.025 220);
  --line: oklch(34% 0.025 230);
  --accent: oklch(74% 0.09 190);
  --accent-strong: oklch(82% 0.075 190);
  --error: oklch(72% 0.13 28);
  --focus: oklch(76% 0.11 210);
}

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

html {
  min-height: 100%;
  background: var(--canvas);
  font-family: var(--font);
  font-size: 100%;
  font-kerning: normal;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  color: var(--ink);
  background: var(--canvas);
}

button,
input {
  font: inherit;
}

button,
input[type="search"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus,
input:focus {
  outline: none;
}

button:focus-visible,
input:focus-visible,
.skip-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: var(--space-sm);
  left: var(--space-sm);
  z-index: 20;
  padding: 0.75rem 1rem;
  color: var(--surface);
  background: var(--ink);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.shell {
  width: min(100%, 40rem);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-lg);
  padding: var(--space-xl) 1.25rem var(--space-lg);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: var(--space-xs);
  font-size: clamp(1.85rem, 8vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.word-count {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.add-section,
.dictionary,
.fatal-state {
  padding-right: 1.25rem;
  padding-left: 1.25rem;
}

.add-section {
  padding-bottom: var(--space-xl);
}

.add-section > label,
.search-row span {
  display: block;
  margin-bottom: var(--space-sm);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

#add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-sm);
  padding: var(--space-xs);
  background: var(--soft);
  border: 1px solid transparent;
  border-radius: 1rem;
}

#add-form:focus-within {
  border-color: var(--accent);
}

#term {
  width: 100%;
  min-height: 3rem;
  padding: 0.65rem 0.75rem;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-size: 1rem;
}

#term::placeholder {
  color: var(--muted);
  opacity: 1;
}

#add-button {
  min-width: 4.25rem;
  min-height: 3rem;
  padding: 0 1rem;
  color: var(--surface);
  background: var(--accent-strong);
  border: 0;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

#add-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.field-note {
  min-height: 1.25rem;
  margin: var(--space-sm) 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.field-note:empty {
  display: none;
}

.field-note.is-error {
  color: var(--error);
}

.dictionary {
  min-height: 17rem;
  padding-bottom: 4rem;
  border-top: 1px solid var(--line);
}

.search-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-md);
  min-height: 3.5rem;
  border-bottom: 1px solid var(--line);
}

.search-row span {
  margin: 0;
}

#search {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-size: 0.9rem;
}

.word-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.word-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-md);
  min-height: 3.75rem;
  border-bottom: 1px solid var(--line);
}

.word-term {
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.35;
}

.delete-button {
  min-width: 3.75rem;
  min-height: 2.75rem;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 0.78rem;
  cursor: pointer;
}

.loading-list {
  display: grid;
}

.loading-list span {
  display: block;
  height: 3.75rem;
  border-bottom: 1px solid var(--line);
}

.empty-state {
  margin: 0;
  padding: 3rem 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.fatal-state {
  min-height: 18rem;
  padding-top: 4rem;
}

.fatal-state h2 {
  margin-bottom: var(--space-sm);
  font-size: 1.5rem;
  font-weight: 500;
}

.fatal-state p {
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: max(var(--space-md), env(safe-area-inset-right));
  bottom: max(var(--space-md), env(safe-area-inset-bottom));
  left: max(var(--space-md), env(safe-area-inset-left));
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  width: min(calc(100% - 2rem), 28rem);
  min-height: 3.5rem;
  margin-left: auto;
  padding: 0.7rem 0.75rem 0.7rem 1rem;
  color: var(--surface);
  background: var(--ink);
  border-radius: 0.875rem;
  font-size: 0.875rem;
}

.toast[hidden],
[hidden] {
  display: none !important;
}

#toast-action {
  min-width: 3.75rem;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  color: var(--accent-strong);
  background: var(--surface);
  border: 0;
  border-radius: 0.625rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
  .delete-button:hover {
    color: var(--accent-strong);
  }

  #add-button:hover {
    background: var(--accent);
  }
}

@media (min-width: 44rem) {
  body {
    padding: max(var(--space-xl), env(safe-area-inset-top)) var(--space-md);
  }

  .shell {
    min-height: calc(100dvh - 4rem);
    border: 1px solid var(--line);
    border-radius: 1.5rem;
  }

  .topbar {
    padding: 2.5rem 2.5rem var(--space-xl);
  }

  .add-section,
  .dictionary,
  .fatal-state {
    padding-right: 2.5rem;
    padding-left: 2.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
