:root {
  --study-background: #F6F7F9;
  --study-foreground: #111827;
  --study-card: #FFFFFF;
  --study-card-foreground: #111827;
  --study-popover: #FFFFFF;
  --study-popover-foreground: #111827;
  --study-primary: #0D9488;
  --study-primary-foreground: #FFFFFF;
  --study-muted: #F3F4F6;
  --study-muted-foreground: #6B7280;
  --study-border: #E5E7EB;
  --study-input: #E5E7EB;
  --study-ring: #0D9488;
  --study-destructive: #EF4444;
  --study-destructive-foreground: #FFFFFF;

  --study-surface: #FFFFFF;
  --study-surface-2: #F9FAFB;
  --study-ink: #111827;
  --study-ink-2: #4B5563;
  --study-ink-3: #9CA3AF;
  --study-line: #E5E7EB;

  --study-state-success: #10B981;
  --study-state-warning: #F59E0B;
  --study-state-error: #EF4444;
  --study-state-info: #3B82F6;

  --study-radius-sm: 4px;
  --study-radius-md: 8px;
  --study-radius-lg: 12px;

  --study-font-sans: Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --study-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --study-shadow-1: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 1px rgba(15, 23, 42, 0.03);
  --study-shadow-2: 0 8px 24px -8px rgba(15, 23, 42, 0.14);
}

@theme inline {
  --color-background: var(--study-background);
  --color-foreground: var(--study-foreground);
  --color-card: var(--study-card);
  --color-card-foreground: var(--study-card-foreground);
  --color-popover: var(--study-popover);
  --color-popover-foreground: var(--study-popover-foreground);
  --color-primary: var(--study-primary);
  --color-primary-foreground: var(--study-primary-foreground);
  --color-muted: var(--study-muted);
  --color-muted-foreground: var(--study-muted-foreground);
  --color-border: var(--study-border);
  --color-input: var(--study-input);
  --color-ring: var(--study-ring);
  --color-destructive: var(--study-destructive);
  --color-destructive-foreground: var(--study-destructive-foreground);
  --color-state-success: var(--study-state-success);
  --color-state-warning: var(--study-state-warning);
  --color-state-error: var(--study-state-error);
  --color-state-info: var(--study-state-info);

  --radius-sm: var(--study-radius-sm);
  --radius-md: var(--study-radius-md);
  --radius-lg: var(--study-radius-lg);
}

@layer base {
  body { background: var(--study-background); color: var(--study-foreground); font-family: var(--study-font-sans); }
  td, th { word-break: break-word; }
  th { white-space: nowrap; }
}

/* Semantic token fallback */
.bg-background { background-color: var(--study-background); }
.text-background { color: var(--study-background); }
.border-background { border-color: var(--study-background); }
.bg-foreground { background-color: var(--study-foreground); }
.text-foreground { color: var(--study-foreground); }
.border-foreground { border-color: var(--study-foreground); }
.bg-card { background-color: var(--study-card); }
.text-card { color: var(--study-card); }
.border-card { border-color: var(--study-card); }
.bg-card-foreground { background-color: var(--study-card-foreground); }
.text-card-foreground { color: var(--study-card-foreground); }
.border-card-foreground { border-color: var(--study-card-foreground); }
.bg-popover { background-color: var(--study-popover); }
.text-popover { color: var(--study-popover); }
.border-popover { border-color: var(--study-popover); }
.bg-popover-foreground { background-color: var(--study-popover-foreground); }
.text-popover-foreground { color: var(--study-popover-foreground); }
.border-popover-foreground { border-color: var(--study-popover-foreground); }
.bg-primary { background-color: var(--study-primary); }
.text-primary { color: var(--study-primary); }
.border-primary { border-color: var(--study-primary); }
.bg-primary-foreground { background-color: var(--study-primary-foreground); }
.text-primary-foreground { color: var(--study-primary-foreground); }
.border-primary-foreground { border-color: var(--study-primary-foreground); }
.bg-muted { background-color: var(--study-muted); }
.text-muted { color: var(--study-muted); }
.border-muted { border-color: var(--study-muted); }
.bg-muted-foreground { background-color: var(--study-muted-foreground); }
.text-muted-foreground { color: var(--study-muted-foreground); }
.border-muted-foreground { border-color: var(--study-muted-foreground); }
.bg-border { background-color: var(--study-border); }
.text-border { color: var(--study-border); }
.border-border { border-color: var(--study-border); }
.bg-input { background-color: var(--study-input); }
.text-input { color: var(--study-input); }
.border-input { border-color: var(--study-input); }
.bg-ring { background-color: var(--study-ring); }
.text-ring { color: var(--study-ring); }
.border-ring { border-color: var(--study-ring); }
.bg-destructive { background-color: var(--study-destructive); }
.text-destructive { color: var(--study-destructive); }
.border-destructive { border-color: var(--study-destructive); }
.bg-destructive-foreground { background-color: var(--study-destructive-foreground); }
.text-destructive-foreground { color: var(--study-destructive-foreground); }
.border-destructive-foreground { border-color: var(--study-destructive-foreground); }

/* Utilities */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

.critical-frame {
  width: 100%;
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  box-sizing: border-box;
  position: relative;
}

.critical-main {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.critical-main::-webkit-scrollbar { display: none; }
.critical-main { -ms-overflow-style: none; scrollbar-width: none; }

.has-bottom-nav .critical-frame {
  padding-bottom: 64px;
}

[data-mobile-nav="global"] {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 64px;
  background-color: var(--study-card);
  border-top: 1px solid var(--study-border);
}

.progress-ring-circle {
  transition: stroke-dashoffset 0.35s;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.shadow-1 { box-shadow: var(--study-shadow-1); }
.shadow-2 { box-shadow: var(--study-shadow-2); }

/* Subject tags */
.tag-math { background-color: rgba(245, 158, 11, 0.15); color: #B45309; }
.tag-physics { background-color: rgba(59, 130, 246, 0.15); color: #1D4ED8; }
.tag-chemistry { background-color: rgba(16, 185, 129, 0.15); color: #047857; }
.tag-english { background-color: rgba(139, 92, 246, 0.15); color: #6D28D9; }
.tag-chinese { background-color: rgba(239, 68, 68, 0.15); color: #B91C1C; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--study-radius-md);
  background-color: var(--study-primary);
  color: var(--study-primary-foreground);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.btn-primary:active { opacity: 0.9; }

.btn-muted {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--study-radius-md);
  background-color: var(--study-muted);
  color: var(--study-foreground);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.input-field {
  width: 100%;
  border-radius: var(--study-radius-md);
  border: 1px solid var(--study-input);
  background-color: var(--study-background);
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  color: var(--study-foreground);
  outline: none;
}
.input-field:focus {
  border-color: var(--study-primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.page-card {
  border-radius: var(--study-radius-lg);
  background-color: var(--study-card);
  box-shadow: var(--study-shadow-1);
}

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 0.75rem 1rem;
  border-radius: var(--study-radius-md);
  font-size: 0.875rem;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 90%;
}
.toast.show { opacity: 1; }
.toast.success { background-color: var(--study-state-success); }
.toast.error { background-color: var(--study-state-error); }
