/* ==========================================================================
   GaoShu-Review Reusable UI Components
   ========================================================================== */

/* 1. 按钮体系 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--c-surface-2);
  color: var(--c-text);
  font-size: var(--fs-14);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn:hover:not(:disabled) {
  background: var(--c-border);
  color: var(--c-text);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled,
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--c-primary-hover);
  border-color: var(--c-primary-hover);
  color: #ffffff;
}

.btn-outline,
.btn-secondary {
  background: var(--c-surface);
  border-color: var(--c-border);
  color: var(--c-text);
}

.btn-outline:hover:not(:disabled),
.btn-secondary:hover:not(:disabled) {
  border-color: var(--c-primary);
  color: var(--c-primary);
  background: var(--c-surface);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--c-text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--c-surface-2);
  color: var(--c-text);
}

.btn-danger {
  background: var(--c-danger);
  border-color: var(--c-danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
}

.btn-success {
  background: var(--c-success);
  border-color: var(--c-success);
  color: #ffffff;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: var(--fs-12);
  border-radius: 6px;
}

.btn-lg {
  height: 42px;
  padding: 0 20px;
  font-size: var(--fs-16);
  border-radius: 10px;
}

/* 2. 卡片 */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-hover {
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.card-hover:hover {
  transform: translateY(-2px);
  border-color: var(--c-primary);
  box-shadow: var(--shadow-lg);
}

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

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--c-text);
}

/* 3. 徽章与星级标签 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--fs-12);
  font-weight: 600;
  line-height: 1.4;
  background: var(--c-surface-2);
  color: var(--c-text-2);
  border: 1px solid var(--c-border);
}

.badge-primary {
  background: var(--c-primary-weak);
  color: var(--c-primary);
  border-color: transparent;
}

.badge-success {
  background: var(--c-success-weak);
  color: var(--c-success);
  border-color: transparent;
}

.badge-warning {
  background: var(--c-warning-weak);
  color: var(--c-warning);
  border-color: transparent;
}

.badge-danger {
  background: var(--c-danger-weak);
  color: var(--c-danger);
  border-color: transparent;
}

.badge-purple {
  background: var(--c-purple-weak);
  color: var(--c-purple);
  border-color: transparent;
}

.stars {
  color: #f59e0b;
  letter-spacing: 1px;
  font-size: var(--fs-14);
}

/* 4. 表单输入控件 */
.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-14);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input,
.select {
  height: 38px;
}

.textarea {
  min-height: 96px;
  line-height: 1.6;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-weak);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-label {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--c-text);
}

input[type="range"] {
  accent-color: var(--c-primary);
  cursor: pointer;
}

/* 进度条 */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--c-surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar > .progress-fill,
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--c-primary);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* 5. 题目选项行（选中蓝框、答对弹跳绿底、答错抖动红底） */
.option-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.option-item:hover:not(.is-disabled):not([disabled]) {
  border-color: var(--c-primary);
  background: var(--c-bg);
}

.option-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-size: var(--fs-14);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.option-content {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.option-item.is-selected,
.option-item.selected {
  border-color: var(--c-primary);
  background: var(--c-primary-weak);
}

.option-item.is-selected .option-key,
.option-item.selected .option-key {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #ffffff;
}

.option-item.is-correct,
.option-item.correct {
  border-color: var(--c-success);
  background: var(--c-success-weak);
  animation: optionPop 0.28s ease-out;
}

.option-item.is-correct .option-key,
.option-item.correct .option-key {
  background: var(--c-success);
  border-color: var(--c-success);
  color: #ffffff;
}

.option-item.is-wrong,
.option-item.wrong,
.option-item.is-incorrect {
  border-color: var(--c-danger);
  background: var(--c-danger-weak);
  animation: optionShake 0.3s ease-in-out;
}

.option-item.is-wrong .option-key,
.option-item.wrong .option-key,
.option-item.is-incorrect .option-key {
  background: var(--c-danger);
  border-color: var(--c-danger);
  color: #ffffff;
}

@keyframes optionPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

@keyframes optionShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

/* 6. 3D 翻转记忆卡片 (.flashcard) */
.flashcard-scene {
  perspective: 1200px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.flashcard {
  position: relative;
  width: 100%;
  min-height: 280px;
  transform-style: preserve-3d;
  transition: transform 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
  cursor: pointer;
}

.flashcard.is-flipped,
.flashcard.flipped {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow-y: auto;
}

.flashcard-back {
  transform: rotateY(180deg);
  border-color: var(--c-primary);
}

/* 7. 标签页 (.tabs) */
.tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.tab-item,
.tab-btn {
  padding: 6px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--c-text-2);
  font-size: var(--fs-14);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-item:hover,
.tab-btn:hover {
  color: var(--c-text);
}

.tab-item.is-active,
.tab-item.active,
.tab-btn.is-active,
.tab-btn.active {
  background: var(--c-surface);
  color: var(--c-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* 8. 数学软键盘 (.math-kb) */
.math-kb {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  margin-top: 8px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}

.math-kb-key {
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.math-kb-key:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
  background: var(--c-primary-weak);
}

.math-kb-key:active {
  transform: translateY(1px);
}

/* 9. 原生 <dialog> 弹窗 */
dialog.modal-dialog {
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-lg);
  width: calc(100% - 32px);
  max-width: 520px;
  margin: auto;
}

dialog.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
}

.modal-panel {
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}

.modal-title {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 0;
}

.modal-close-btn {
  font-size: 1.35rem;
  line-height: 1;
  width: 30px;
  height: 30px;
  padding: 0;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.7;
}

.modal-confirm-msg {
  margin: 0;
  color: var(--c-text);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
}

/* 10. Toast 轻提示 */
#toast-root {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 24px);
}

.toast {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-14);
  font-weight: 500;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  cursor: pointer;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-8px);
}

.toast-success { border-color: var(--c-success); }
.toast-warning { border-color: var(--c-warning); }
.toast-error { border-color: var(--c-danger); }

/* 11. 尊重减弱动态效果首选项 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .flashcard {
    transition: none !important;
  }
}
