:root {
  --ink: #15242b;
  --muted: #61717a;
  --line: #d7e7e8;
  --teal: #0d8b93;
  --teal-dark: #066b72;
  --soft: #edf8f7;
  --paper: #fbfefe;
  --red: #b42318;
  --amber: #b76a00;
  --green: #087443;
  --shadow: 0 18px 44px rgba(16, 54, 63, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #f5fbfb;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 20px;
  color: #fff;
  background: #10292f;
  overflow: auto;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,.16);
}

.mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #dff5f3;
  color: var(--teal-dark);
  font-weight: 900;
}

h1, h2, p { margin: 0; }

.brand h1 {
  font-size: 21px;
}

.brand p {
  margin-top: 5px;
  color: rgba(255,255,255,.68);
  line-height: 1.5;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 20px 0;
}

.stats div {
  padding: 13px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
}

.stats b {
  display: block;
  font-size: 24px;
}

.stats span {
  color: rgba(255,255,255,.66);
  font-size: 12px;
}

.label {
  display: block;
  margin: 16px 0 7px;
  color: rgba(255,255,255,.68);
  font-size: 13px;
}

select,
input,
button {
  font: inherit;
}

select {
  width: 100%;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  padding: 11px 12px;
  color: #fff;
  background: #183940;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: white;
}

.side-actions {
  display: grid;
  gap: 9px;
  margin-top: 18px;
}

.userbox {
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
  padding: 10px 12px;
  color: rgba(255,255,255,.78);
  background: rgba(255,255,255,.06);
  font-size: 13px;
}

.target-box {
  margin-top: 2px;
}

.target-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.target-row input {
  border-color: rgba(255,255,255,.2);
  color: #fff;
  background: #183940;
}

.target-row span,
.target-box p {
  color: rgba(255,255,255,.66);
  font-size: 13px;
}

.target-box p {
  min-height: 18px;
  margin-top: 7px;
}

.bank-box {
  display: none;
  margin: 4px 0 18px;
}

.bank-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin: 16px 0 8px;
  color: rgba(255,255,255,.7);
  font-size: 13px;
}

.bank-head b {
  color: #dff5f3;
  font-size: 12px;
}

.bank-menu {
  display: grid;
  gap: 8px;
}

.bank-item {
  width: 100%;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  padding: 12px;
  color: rgba(255,255,255,.78);
  background: rgba(255,255,255,.05);
  text-align: left;
  cursor: pointer;
}

.bank-item strong,
.bank-item span {
  display: block;
}

.bank-item strong {
  color: #fff;
  font-size: 15px;
}

.bank-item span {
  margin-top: 4px;
  color: rgba(255,255,255,.62);
  font-size: 12px;
  line-height: 1.45;
}

.bank-item:hover,
.bank-item.active {
  border-color: rgba(122,230,224,.8);
  background: #173f46;
}

.bank-item.active {
  box-shadow: inset 4px 0 0 #7ae6e0;
}

.ghost {
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  padding: 11px 12px;
  color: #fff;
  background: transparent;
  cursor: pointer;
}

.ghost:hover { background: rgba(255,255,255,.1); }
.danger:hover { border-color: #ffb4ad; }

.main {
  padding: 30px;
}

.top {
  max-width: 1050px;
  margin: 0 auto 18px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.top h2 {
  font-size: 28px;
}

.top p {
  margin-top: 6px;
  color: var(--muted);
}

.counter {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--teal-dark);
  font-weight: 800;
}

.card {
  max-width: 1050px;
  min-height: 560px;
  margin: 0 auto;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.pills {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--soft);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.memory-panel {
  display: grid;
  gap: 5px;
  margin-top: 18px;
  border: 1px solid #d7e7e8;
  border-radius: 8px;
  padding: 12px 14px;
  background: #f6fbfa;
}

.memory-panel strong {
  color: var(--teal-dark);
}

.memory-panel span {
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.question {
  margin: 22px 0;
  font-size: 26px;
  line-height: 1.55;
}

.choice-title {
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.choices {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.choice {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: start;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: white;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  line-height: 1.65;
}

.choice span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--teal-dark);
  font-weight: 900;
}

.choice b {
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}

.choice:hover {
  border-color: var(--teal);
}

.choice.correct {
  border-color: rgba(8,116,67,.55);
  background: #f0fbf5;
}

.choice.wrong {
  border-color: rgba(180,35,24,.45);
  background: #fff5f4;
}

.choice-feedback {
  min-height: 24px;
  color: var(--muted);
  font-size: 14px;
}

.grade-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  border: 1px solid #cfe3e5;
  border-radius: 8px;
  padding: 12px;
  background: #f7fcfc;
}

.grade-actions span {
  margin-right: auto;
  color: var(--muted);
  font-size: 14px;
}

.answer {
  display: none;
  border: 1px solid #cfe3e5;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  padding: 18px;
  background: #f7fcfc;
}

.answer.show { display: block; }

.answer h3 {
  margin: 0 0 9px;
  color: var(--teal-dark);
  font-size: 17px;
}

.answer p {
  line-height: 1.82;
  white-space: pre-line;
}

.answer-section {
  border: 1px solid #d7e9e8;
  border-radius: 8px;
  padding: 12px 14px;
  background: white;
}

.answer-section h4 {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-size: 15px;
}

.answer-section p {
  margin: 0 0 8px;
}

.answer-section p:last-child {
  margin-bottom: 0;
}

.answer-notes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.answer-note {
  border: 1px solid #d7e9e8;
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
}

.answer-note b {
  display: block;
  margin-bottom: 4px;
  color: #b65f13;
  font-size: 13px;
}

.answer-note span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.related-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
  border: 1px solid #cfe3e5;
  border-radius: 8px;
  padding: 12px;
  background: #f7fcfc;
}

.related-head {
  grid-column: 1 / -1;
}

.related-head h3 {
  margin: 0 0 3px;
  color: var(--teal-dark);
  font-size: 16px;
}

.related-head span {
  color: var(--muted);
  font-size: 13px;
}

.return-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #cfe3e5;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  padding: 12px 14px;
  background: #f0fbfa;
}

.return-box h3 {
  margin: 0 0 3px;
  color: var(--teal-dark);
  font-size: 16px;
}

.return-box p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 20px;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 15px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

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

.btn.good { border-color: rgba(8,116,67,.35); color: var(--green); }
.btn.fuzzy { border-color: rgba(183,106,0,.35); color: var(--amber); }
.btn.bad { border-color: rgba(180,35,24,.35); color: var(--red); }
.btn.danger-text { color: var(--red); }

.btn:hover {
  border-color: var(--teal);
}

.study-tools {
  display: grid;
  grid-template-columns: minmax(260px, .8fr) minmax(420px, 1.4fr);
  gap: 14px;
  align-items: start;
  margin-top: 22px;
}

.tool-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
}

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

.tool-head h3 {
  margin: 0;
  font-size: 17px;
}

.tool-head span {
  color: var(--muted);
  font-size: 12px;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fbfefe;
  line-height: 1.7;
  resize: vertical;
}

textarea:focus {
  outline: 2px solid rgba(13,139,147,.18);
  border-color: var(--teal);
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 10px;
}

.ai-output {
  min-height: 92px;
  margin-top: 12px;
  border: 1px solid #dbe9ea;
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: #f7fcfc;
  line-height: 1.65;
  max-height: 520px;
  overflow: auto;
}

.ai-output + .btn {
  margin-top: 10px;
}

.ai-output.error {
  border-color: rgba(180,35,24,.35);
  color: var(--red);
  background: #fff7f6;
  white-space: pre-wrap;
}

.ai-output section + section {
  margin-top: 13px;
}

.ai-output h4 {
  margin: 0 0 5px;
  color: var(--teal-dark);
  font-size: 15px;
}

.ai-output p {
  margin: 0;
}

.ai-output p + p {
  margin-top: 6px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 480px;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  margin-bottom: 8px;
  color: var(--ink);
}

.auth-card {
  max-width: 430px;
  margin: 36px auto;
}

.auth-card h2 {
  font-size: 28px;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 22px;
}

.auth-card label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 14px;
}

.auth-card .btn {
  width: 100%;
  margin-top: 10px;
}

.auth-error {
  min-height: 24px;
  margin-top: 10px;
  color: var(--red);
  line-height: 1.5;
}

.auth-switch {
  margin-top: 14px;
  text-align: center;
}

.link-btn {
  border: 0;
  padding: 8px;
  color: var(--teal-dark);
  background: transparent;
  cursor: pointer;
}

.admin-panel {
  display: grid;
  gap: 16px;
}

.admin-create {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.admin-create label,
.user-edit-grid label {
  display: grid;
  gap: 6px;
}

.admin-create label > span,
.user-edit-grid label > span {
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 8px 0 16px;
  color: var(--ink);
}

.check-row input {
  width: auto;
}

.check-row.compact {
  margin: 0;
  align-self: center;
}

.admin-label {
  display: block;
  margin: 10px 0 7px;
  color: var(--muted);
  font-size: 14px;
}

.hint {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.user-table {
  display: grid;
  gap: 10px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfefe;
}

.user-row strong,
.user-row span,
.user-row em {
  display: block;
}

.user-row span,
.user-row em {
  margin-top: 4px;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  line-height: 1.5;
}

.user-meta {
  margin-bottom: 12px;
}

.user-edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
}

.user-edit-grid input {
  padding: 10px;
}

.user-actions {
  display: grid;
  gap: 8px;
  min-width: 84px;
}

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

.progress {
  max-width: 1050px;
  height: 10px;
  margin: 18px auto 0;
  border-radius: 999px;
  overflow: hidden;
  background: #dcebec;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--teal);
}

@media (max-width: 900px) {
  .shell { display: block; }
  .side {
    position: static;
    height: auto;
  }
  .main { padding: 18px 12px; }
  .top { display: block; }
  .counter { display: inline-block; margin-top: 12px; }
  .card { padding: 18px; min-height: 500px; }
  .question { font-size: 21px; }
  .study-tools { grid-template-columns: 1fr; }
  .answer-notes { grid-template-columns: 1fr; }
  .related-box { grid-template-columns: 1fr; }
  .return-box { display: grid; }
  .admin-create,
  .user-row,
  .user-edit-grid {
    grid-template-columns: 1fr;
  }
  .user-actions {
    grid-template-columns: 1fr 1fr;
  }
  .ai-output { max-height: none; }
}
