:root {
  --blue: #4f8fd8;
  --purple: #7461cf;
  --green: #57b88b;
  --yellow: #f4c95d;
  --red: #ec6f6f;
  --ink: #263241;
  --muted: #6d7785;
  --line: #dde5ef;
  --paper: #ffffff;
  --soft: #f4f7fb;
  --shadow: 0 12px 30px rgba(42, 54, 74, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  background: linear-gradient(120deg, var(--blue), var(--purple));
  color: #fff;
  padding: 18px clamp(18px, 5vw, 68px) 0;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
}

.rolebar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
}

.studentbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 0 14px;
  color: #fff;
}

.studentbar strong,
.version-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
}

.studentbar input {
  width: 160px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
}

.studentbar button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-weight: 700;
}

#roleBadge {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.rolebar button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-weight: 700;
}

.login-form {
  display: flex;
  gap: 8px;
}

.login-form input {
  width: 150px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

body:not(.teacher-mode) .teacher-only {
  display: none !important;
}

.teacher-mode .teacher-only {
  display: inline-flex !important;
}

.teacher-mode .tab.teacher-only {
  display: block !important;
}

.teacher-mode .word-check.teacher-only {
  display: grid !important;
}

.teacher-mode .word-actions.teacher-only {
  display: flex !important;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-weight: 900;
  box-shadow: inset -9px -9px 0 #dff0ff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3.2vw, 34px);
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.84);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 0;
}

.tab {
  min-width: 112px;
  padding: 14px 20px;
  border-radius: 8px 8px 0 0;
  color: #eef5ff;
  background: rgba(255, 255, 255, 0.14);
}

.tab.active {
  color: var(--blue);
  background: var(--soft);
  font-weight: 700;
}

main {
  width: min(980px, calc(100% - 28px));
  margin: 16px auto 40px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#studyView.active {
  min-height: calc(100vh - 132px);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stats article,
.study-card,
.panel {
  background: var(--paper);
  border: 1px solid rgba(221, 229, 239, 0.85);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats article {
  min-height: 72px;
  display: grid;
  place-items: center;
  padding: 10px;
}

.stats strong {
  color: var(--blue);
  font-size: 24px;
}

.stats span {
  font-size: 13px;
}

.stats span,
.section-title p,
.hint,
.phonetic,
.preview,
.word-card small {
  color: var(--muted);
}

.modebar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.study-scope {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.study-scope strong {
  color: var(--ink);
}

.study-scope select {
  width: min(240px, 100%);
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.mode,
.actions button,
.manual-form button,
#scanBtn,
.import-actions button,
.library-tools button,
.category-row select,
.category-row input,
.manual-form select,
.library-tools select,
.word-card.editing input,
.spell-box button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.mode {
  min-height: 112px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
}

.mode strong {
  font-size: 24px;
}

.mode span {
  color: var(--muted);
  font-size: 14px;
}

.mode.active,
#scanBtn,
.manual-form button,
.actions button:last-child,
.spell-box button {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.mode.active span {
  color: rgba(255, 255, 255, 0.88);
}

.study-card {
  min-height: min(620px, calc(100vh - 290px));
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  padding: clamp(18px, 3vw, 28px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#tagText {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  color: #386d54;
  background: #e7f6ef;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
}

.word {
  text-align: center;
  font-size: clamp(40px, 7vw, 68px);
  font-weight: 900;
  line-height: 1.12;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.word u {
  text-decoration-thickness: 4px;
  text-underline-offset: 8px;
  text-decoration-color: var(--yellow);
}

.study-card.sentence-mode .word {
  font-size: clamp(28px, 4.5vw, 46px);
  line-height: 1.22;
  max-width: 820px;
  margin: 0 auto;
}

.phonetic,
.hint,
.progress-text,
.feedback {
  text-align: center;
}

.phonetic {
  margin-top: 6px;
  font-size: 18px;
}

.hint {
  margin: 10px 0 16px;
}

.progress-text {
  min-height: 24px;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 800;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.answer {
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 20px;
}

.answer.correct {
  border-color: var(--green);
  background: #e9f7f0;
}

.answer.wrong {
  border-color: var(--red);
  background: #fff0f0;
}

.spell-box {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.spell-box input,
.manual-form input,
.manual-form select,
.library-tools input,
.library-tools select,
.category-row input,
.category-row select,
.word-card.editing input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.spell-box input,
.manual-form input,
.manual-form select,
.library-tools input {
  min-height: 46px;
  padding: 0 14px;
}

.hidden {
  display: none !important;
}

.feedback {
  min-height: 30px;
  margin-top: 12px;
  font-weight: 700;
}

.feedback.good {
  color: var(--green);
}

.feedback.bad {
  color: var(--red);
}

.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.panel {
  padding: clamp(18px, 3vw, 28px);
  margin-bottom: 18px;
}

.compact {
  box-shadow: none;
}

.section-title {
  margin-bottom: 18px;
}

.section-title h2 {
  font-size: 24px;
  margin-bottom: 6px;
}

.upload-row,
.category-row,
.category-manager,
.import-actions,
.library-head,
.library-tools {
  display: flex;
  gap: 12px;
}

.upload-row {
  align-items: stretch;
  flex-wrap: wrap;
}

.category-row {
  align-items: end;
  flex-wrap: wrap;
  margin-top: 12px;
}

.category-manager {
  flex-wrap: wrap;
}

.category-manager input,
.category-manager select {
  min-width: 220px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.category-manager button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

#addLibraryBtn {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.category-row label {
  display: grid;
  gap: 6px;
  min-width: 180px;
  color: var(--muted);
}

.category-row input {
  flex: 1;
  min-width: 220px;
}

#fileInput {
  display: none;
}

.upload-box {
  flex: 1;
  min-width: 260px;
  display: grid;
  gap: 4px;
  min-height: 76px;
  padding: 14px 16px;
  border: 1px dashed var(--blue);
  border-radius: 8px;
  background: #f4f9ff;
  cursor: pointer;
}

.upload-box span {
  color: var(--blue);
  font-weight: 800;
}

.upload-box small {
  color: var(--muted);
}

textarea {
  min-height: 180px;
  padding: 14px;
  margin-top: 12px;
  resize: vertical;
  line-height: 1.7;
}

.import-actions {
  margin: 12px 0;
}

.preview {
  min-height: 42px;
  line-height: 1.7;
}

.manual-form {
  display: grid;
  grid-template-columns: 1fr 1.2fr 120px 1fr 160px auto;
  gap: 12px;
}

.library-head {
  align-items: flex-start;
  justify-content: space-between;
}

.library-tools {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.manual-form > *,
.library-tools > *,
.spell-box > *,
.upload-row > *,
.category-row > *,
.category-manager > * {
  min-width: 0;
}

.bulk-status {
  margin: -6px 0 14px;
  color: var(--muted);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

#scanBtn {
  flex: 0 0 auto;
  min-width: 132px;
}

.word-list {
  display: grid;
  gap: 14px;
}

.library-group {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.library-group-head {
  display: grid;
  grid-template-columns: 40px minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #f7fbff;
  border-bottom: 1px solid var(--line);
}

.library-group-head strong {
  font-size: 18px;
}

.library-group-head span {
  color: var(--muted);
  white-space: nowrap;
}

.toggle-category {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 8px;
  background: #eef5ff;
  color: var(--blue);
  font-size: 15px;
}

.delete-library {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: #fff0f0;
  color: #b42318;
}

.library-group-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.library-group-body.hidden {
  display: none;
}

.library-group-body .word-card {
  border-color: #e8eef7;
}

.empty-library {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfdff;
}

.word-card {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.teacher-mode .word-card {
  grid-template-columns: auto 1fr 1.3fr auto;
}

.word-card.editing {
  grid-template-columns: 1fr 110px 1.6fr 1fr 1fr auto;
  align-items: stretch;
}

.word-card.editing input,
.word-card.editing textarea {
  min-height: 42px;
  padding: 0 12px;
}

.word-card.editing textarea {
  min-height: 68px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

.edit-sentence,
.edit-translation {
  grid-column: 1 / -1;
}

.word-card.editing .word-actions {
  grid-column: 1 / -1;
}

.word-check {
  display: grid;
  width: 26px;
  place-items: center;
}

.word-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.word-card strong {
  font-size: 20px;
}

.meaning-list {
  line-height: 1.55;
}

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

.edit-word,
.save-word,
.cancel-edit,
.delete-word {
  min-width: 40px;
  height: 40px;
  border-radius: 8px;
}

.edit-word,
.cancel-edit {
  padding: 0 12px;
  background: #eef5ff;
  color: var(--blue);
}

.save-word {
  padding: 0 12px;
  background: var(--green);
  color: #fff;
}

.delete-word {
  background: #fff0f0;
  color: var(--red);
}

@media (max-width: 760px) {
  .topbar {
    padding: 10px 14px 0;
  }

  .brand {
    gap: 10px;
    padding-bottom: 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  h1 {
    font-size: 22px;
  }

  .brand p {
    display: none;
  }

  .rolebar {
    padding-bottom: 8px;
  }

  .rolebar button,
  #roleBadge {
    min-height: 30px;
    font-size: 13px;
  }

  main {
    width: min(100% - 18px, 980px);
    margin: 10px auto 24px;
  }

  .tabs,
  .stats,
  .answers,
  .manual-form,
  .word-card,
  .word-card.editing,
  .library-head,
  .category-manager,
  .category-row,
  .upload-row {
    grid-template-columns: 1fr;
  }

  .tabs,
  .upload-row,
  .library-head {
    display: grid;
  }

  .tab {
    min-width: 0;
    border-radius: 8px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
  }

  .stats article {
    min-height: 58px;
    padding: 7px 8px;
  }

  .stats strong {
    font-size: 21px;
  }

  .modebar {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 12px;
  }

  .mode {
    min-height: 86px;
    padding: 14px;
  }

  .mode strong {
    font-size: 20px;
  }

  .mode span {
    font-size: 13px;
  }

  .study-scope {
    margin-bottom: 8px;
    font-size: 13px;
  }

  .study-card {
    min-height: calc(100vh - 300px);
    padding: 16px 12px;
  }

  .card-head {
    margin-bottom: 4px;
  }

  #tagText {
    min-height: 26px;
    padding: 0 10px;
    font-size: 13px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .word {
    font-size: clamp(32px, 10vw, 48px);
    line-height: 1.16;
  }

  .study-card.sentence-mode .word {
    font-size: clamp(24px, 7vw, 34px);
    line-height: 1.25;
  }

  .progress-text {
    margin-top: 6px;
  }

  .hint {
    margin: 8px 0 12px;
  }

  .answers {
    display: grid;
    gap: 10px;
  }

  .answer {
    min-height: 54px;
    font-size: 18px;
  }

  .spell-box,
  .actions,
  .library-tools {
    flex-direction: column;
  }

  .library-group-head {
    grid-template-columns: 36px 1fr auto;
  }

  .delete-library {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
