:root {
  color-scheme: light;
  --bg: #fff8fb;
  --panel: rgba(255, 255, 255, 0.86);
  --ink: #463845;
  --muted: #85727f;
  --line: #f4dce6;
  --pink: #ff9fc5;
  --pink-deep: #d9578b;
  --mint: #b8eadf;
  --butter: #fff0ad;
  --lavender: #d9ccff;
  --shadow: 0 18px 46px rgba(190, 118, 150, 0.18);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 8%, rgba(255, 213, 228, 0.9), transparent 28%),
    radial-gradient(circle at 84% 0%, rgba(184, 234, 223, 0.75), transparent 24%),
    linear-gradient(135deg, #fff8fb 0%, #fff3df 55%, #f8f0ff 100%);
}

button,
input,
select {
  font: inherit;
}

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

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 2px 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--pink-deep);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.65rem, 6vw, 3rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.18rem;
  line-height: 1.2;
}

.counter {
  min-width: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.78);
  text-align: center;
  box-shadow: 0 10px 24px rgba(217, 87, 139, 0.1);
}

.counter span {
  display: block;
  color: var(--pink-deep);
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.counter small,
.section-head p,
.word-meta,
.quiz-box small,
.flash-sub {
  color: var(--muted);
}

.panel {
  border: 1px solid rgba(244, 220, 230, 0.95);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.input-panel {
  padding: 14px;
}

.word-form {
  display: grid;
  grid-template-columns: 0.95fr 1.15fr 1.15fr 0.9fr 0.72fr auto;
  gap: 10px;
  align-items: end;
}

label,
.answer-label {
  display: grid;
  gap: 6px;
  color: #665560;
  font-size: 0.88rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  outline: none;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(255, 159, 197, 0.23);
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 850;
  white-space: nowrap;
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, #f578ab, #d9578b);
  box-shadow: 0 10px 22px rgba(217, 87, 139, 0.22);
}

.secondary-btn {
  color: #315d54;
  background: var(--mint);
}

.ghost-btn {
  color: var(--pink-deep);
  background: #fff0f6;
}

.dictionary-panel,
.study-controls,
.flashcard-panel,
.quiz-panel {
  margin-top: 14px;
  padding: 14px;
}

.study-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.study-controls label {
  width: min(280px, 100%);
}

.category-count {
  min-height: 44px;
  border: 1px solid #eadfff;
  border-radius: 8px;
  padding: 11px 14px;
  color: #5e4f69;
  background: rgba(217, 204, 255, 0.36);
  font-weight: 850;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head.compact {
  align-items: flex-start;
}

.search-box {
  margin-bottom: 12px;
}

.word-list {
  display: grid;
  gap: 8px;
  max-height: 310px;
  overflow: auto;
  padding-right: 2px;
}

.word-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #f5e1eb;
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.word-item.hidden-word {
  background: rgba(250, 245, 249, 0.72);
  opacity: 0.74;
}

.word-en,
.word-th,
.word-meta {
  display: block;
}

.word-en {
  font-size: 1.02rem;
}

.word-th {
  margin-top: 2px;
}

.word-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.word-actions button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff1b8;
  font-size: 0.84rem;
  font-weight: 800;
}

.word-actions .delete-btn {
  color: #a93f5e;
  background: #ffe1ec;
}

.word-actions .restore-btn {
  color: #315d54;
  background: #dff7f1;
}

.study-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.segmented button {
  min-height: 38px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.85rem;
  font-weight: 850;
}

.segmented button.active {
  color: #fff;
  background: var(--pink);
}

.flashcard {
  display: grid;
  place-items: center;
  gap: 8px;
  width: 100%;
  min-height: 224px;
  border: 1px dashed rgba(217, 87, 139, 0.5);
  border-radius: 8px;
  padding: 22px;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 240, 246, 0.86), rgba(255, 248, 213, 0.84)),
    #fff;
}

.flash-main {
  font-size: clamp(1.6rem, 5vw, 2.5rem);
  font-weight: 900;
  text-align: center;
  overflow-wrap: anywhere;
}

.flash-sub {
  text-align: center;
  font-weight: 700;
}

.quiz-box {
  display: grid;
  gap: 4px;
  min-height: 116px;
  border: 1px solid #eadfff;
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(135deg, rgba(217, 204, 255, 0.38), rgba(255, 255, 255, 0.84));
}

.quiz-label {
  color: var(--pink-deep);
  font-size: 0.78rem;
  font-weight: 900;
}

.quiz-box strong {
  align-self: center;
  font-size: clamp(1.35rem, 4.8vw, 2.1rem);
  overflow-wrap: anywhere;
}

.answer-label {
  margin-top: 12px;
}

.feedback {
  min-height: 28px;
  margin-top: 10px;
  font-weight: 850;
}

.feedback.good {
  color: #25806f;
}

.feedback.bad {
  color: #c44572;
}

.actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
  text-align: center;
}

@media (max-width: 860px) {
  .word-form,
  .study-grid {
    grid-template-columns: 1fr;
  }

  .study-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .counter {
    width: 100%;
  }

  .word-item {
    align-items: stretch;
    flex-direction: column;
  }

  .word-actions {
    justify-content: stretch;
  }

  .word-actions button,
  .actions-row button {
    flex: 1 1 auto;
  }
}
