:root {
  color-scheme: light dark;
  --background: #f5f7f4;
  --foreground: #18343d;
  --card: #ffffff;
  --muted: #e8efeb;
  --muted-text: #617277;
  --border: #d9e3df;
  --accent: #c6ea4b;
  --accent-text: #18343d;
  --secondary: #eef5d9;
  --danger: #bd2d32;
  --danger-soft: #fff0f0;
  --shadow: 0 24px 70px rgb(20 48 56 / 9%);
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0d171a;
    --foreground: #edf4ef;
    --card: #142429;
    --muted: #23353a;
    --muted-text: #a8bab5;
    --border: #31454a;
    --accent: #b8dc42;
    --accent-text: #102126;
    --secondary: #263b32;
    --danger: #ff8f91;
    --danger-soft: #3b2427;
    --shadow: 0 24px 70px rgb(0 0 0 / 24%);
  }
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--background);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  overscroll-behavior-y: none;
}

button,
input,
select { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent);
  outline-offset: 2px;
}

svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden { display: none !important; }

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

.app-shell {
  min-height: 100svh;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  background:
    radial-gradient(circle at 15% 0%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 34rem),
    var(--background);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 64rem);
  margin: 0 auto;
  padding: 1rem;
}

.brand { display: flex; align-items: center; gap: .7rem; }

.brand-mark {
  display: grid;
  width: 2.3rem;
  height: 2.3rem;
  place-items: center;
  border-radius: .8rem;
  background: var(--foreground);
  color: var(--card);
}

.brand strong {
  display: block;
  font-size: .88rem;
  letter-spacing: .16em;
}

.brand small {
  display: block;
  margin-top: .1rem;
  color: var(--muted-text);
  font-size: .75rem;
}

.icon-button {
  display: grid;
  min-width: 3rem;
  min-height: 3rem;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
}

.icon-button:hover { background: var(--muted); }

.message {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  width: min(calc(100% - 2rem), 44rem);
  margin: 0 auto .75rem;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: var(--card);
  box-shadow: 0 4px 20px rgb(20 48 56 / 6%);
  font-size: .88rem;
}

.message-close {
  min-width: 2rem;
  min-height: 2rem;
  border: 0;
  border-radius: .5rem;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.center-view {
  display: grid;
  min-height: calc(100svh - 5rem);
  place-items: center;
  width: 100%;
  padding: 1.25rem 1.25rem 5rem;
  text-align: center;
}

.loading-label { color: var(--muted-text); }

.welcome-card {
  width: min(100%, 34rem);
  padding: 2rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 2rem;
  background: var(--card);
  box-shadow: var(--shadow);
}

.welcome-icon,
.success-icon {
  display: grid;
  width: 4rem;
  height: 4rem;
  place-items: center;
  margin: 0 auto 1.5rem;
  border-radius: 1.1rem;
  background: var(--accent);
  color: var(--accent-text);
}

.welcome-icon svg { width: 1.8rem; height: 1.8rem; }

.welcome-card h1,
.word-content h1 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: -.045em;
  text-wrap: balance;
}

.welcome-card h1 { font-size: clamp(2.5rem, 10vw, 3.4rem); }

.welcome-card > p {
  max-width: 25rem;
  margin: 1rem auto 0;
  color: var(--muted-text);
  font-size: 1rem;
  line-height: 1.75;
}

.welcome-card > small {
  display: block;
  margin-top: .9rem;
  color: var(--muted-text);
}

.primary-button,
.secondary-button,
.know-button,
.danger-button {
  min-height: 3rem;
  padding: .75rem 1rem;
  border: 1px solid transparent;
  border-radius: .8rem;
  cursor: pointer;
  font-weight: 700;
}

.primary-button,
.know-button {
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button:hover,
.know-button:hover { filter: brightness(.95); }

.secondary-button {
  border-color: var(--border);
  background: var(--card);
  color: var(--foreground);
}

.secondary-button:hover { background: var(--muted); }

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
}

button:disabled {
  cursor: default;
  opacity: .42;
}

.import-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin-top: 1.75rem;
  font-size: 1rem;
}

.study-view {
  width: min(100%, 48rem);
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.toolbar { display: grid; gap: .75rem; margin-bottom: 1rem; }

.search-form { position: relative; }

.search-form > svg {
  position: absolute;
  top: 50%;
  left: .9rem;
  color: var(--muted-text);
  transform: translateY(-50%);
  pointer-events: none;
}

.search-form input {
  width: 100%;
  min-height: 3rem;
  padding: .7rem 3rem .7rem 2.65rem;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: var(--card);
  color: var(--foreground);
  font-size: 1rem;
  box-shadow: 0 2px 10px rgb(20 48 56 / 4%);
}

.search-form button {
  position: absolute;
  top: 50%;
  right: .35rem;
  display: grid;
  width: 2.3rem;
  height: 2.3rem;
  place-items: center;
  border: 0;
  border-radius: .6rem;
  background: transparent;
  color: var(--muted-text);
  transform: translateY(-50%);
  cursor: pointer;
  font-size: 1.2rem;
}

.filters {
  display: flex;
  width: 100%;
  min-height: 3rem;
  padding: .25rem;
  gap: .1rem;
  overflow-x: auto;
  border-radius: .8rem;
  background: var(--muted);
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }

.filters button {
  flex: 1 0 auto;
  min-height: 2.5rem;
  padding: .45rem .75rem;
  border: 0;
  border-radius: .6rem;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  font-size: .88rem;
  font-weight: 700;
}

.filters button[aria-selected="true"] {
  background: var(--card);
  color: var(--foreground);
  box-shadow: 0 2px 8px rgb(20 48 56 / 7%);
}

.progress-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .4rem .8rem;
  margin: 0 .2rem .75rem;
  color: var(--muted-text);
  font-size: .82rem;
}

.progress-line p { margin: 0; }
.progress-line strong { color: var(--foreground); font-size: .92rem; }
.progress-line small { margin-left: .5rem; color: var(--muted-text); }

.study-card {
  display: flex;
  min-height: 29rem;
  flex-direction: column;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 1.75rem;
  background: var(--card);
  box-shadow: var(--shadow);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  color: var(--muted-text);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.status-pill {
  padding: .42rem .7rem;
  border-radius: 999px;
  background: var(--muted);
  letter-spacing: .06em;
}

.status-pill.known { background: var(--accent); color: var(--accent-text); }
.status-pill.learning { background: var(--secondary); color: var(--foreground); }

.word-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
  text-align: center;
}

.word-content h1 {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(3.25rem, 14vw, 6.5rem);
  font-weight: 600;
  line-height: .95;
}

.pronunciation {
  min-height: 2rem;
  margin: 1.15rem 0 0;
  color: var(--muted-text);
  font-size: clamp(1.2rem, 5vw, 1.5rem);
  line-height: 1.5;
}

.divider {
  width: 3.5rem;
  height: 1px;
  margin: 2rem 0;
  background: var(--accent);
}

.definition {
  max-width: 38rem;
  margin: 0;
  font-size: clamp(1.08rem, 4vw, 1.28rem);
  line-height: 1.75;
}

.example {
  max-width: 38rem;
  margin: 1.1rem 0 0;
  color: var(--muted-text);
  font-size: clamp(1rem, 3.6vw, 1.13rem);
  font-style: italic;
  line-height: 1.7;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.navigation { margin-top: 1rem; }
.learning-actions { margin-top: .75rem; }
.learning-actions button { min-height: 3.5rem; font-size: 1rem; }
.learning-actions .active { box-shadow: inset 0 0 0 2px var(--foreground); }

.gesture-hint {
  margin: .9rem 0 0;
  color: var(--muted-text);
  font-size: .75rem;
  text-align: center;
}

.empty-filter {
  display: grid;
  min-height: 24rem;
  place-items: center;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 1.75rem;
  background: var(--card);
  text-align: center;
}

.empty-filter h2 { margin: 0; }
.empty-filter p { margin: .5rem 0 1.25rem; color: var(--muted-text); }

.modal {
  width: min(calc(100% - 2rem), 28rem);
  max-height: min(90svh, 48rem);
  padding: 1.25rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 1.2rem;
  background: var(--card);
  color: var(--foreground);
  box-shadow: 0 28px 90px rgb(0 0 0 / 22%);
}

.modal::backdrop {
  background: rgb(5 15 18 / 48%);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.modal h2 { margin: 0; font-size: 1.3rem; }
.modal-header p,
.confirm-modal > p { margin: .45rem 0 0; color: var(--muted-text); line-height: 1.55; }
.modal-header .icon-button { min-width: 2.5rem; min-height: 2.5rem; font-size: 1.5rem; }

.settings-list { display: grid; gap: .7rem; margin-top: 1.2rem; }
.settings-list > button { margin: 0; text-align: left; }

.count-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: color-mix(in srgb, var(--muted) 55%, transparent);
}

.count-row span,
.privacy-note { color: var(--muted-text); }
.privacy-note { margin: 1rem 0 0; font-size: .75rem; line-height: 1.5; }
.mapping-modal { width: min(calc(100% - 2rem), 34rem); }
.mapping-form { display: grid; gap: .85rem; margin-top: 1.2rem; }

.mapping-form label {
  display: grid;
  gap: .35rem;
  font-size: .86rem;
  font-weight: 700;
}

.mapping-form label > span { color: var(--danger); }

.mapping-form select {
  width: 100%;
  min-height: 2.8rem;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: .7rem;
  background: var(--background);
  color: var(--foreground);
  font-size: 1rem;
}

.mapping-form .primary-button { margin-top: .4rem; }

.success-modal { text-align: center; }
.success-icon { width: 3.5rem; height: 3.5rem; border-radius: 999px; font-size: 1.6rem; }
.success-modal p { color: var(--muted-text); line-height: 1.6; }
.success-modal .primary-button { width: 100%; margin-top: .5rem; }
.confirm-modal > .button-grid { margin-top: 1.3rem; }

@media (min-width: 640px) {
  .app-header { padding: 1.5rem 2rem; }
  .welcome-card { padding: 2.6rem; }
  .study-view { padding-right: 2rem; padding-left: 2rem; }
  .toolbar { grid-template-columns: minmax(15rem, 1fr) auto; align-items: center; }
  .filters { width: auto; }
  .study-card { min-height: 31rem; padding: 2.5rem; }
  .word-content { padding: 2.5rem 0; }
  .divider { margin: 2.4rem 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
