/* ═══════════════════════════════════════════
   LeetCode-style OJ Design System
   河码 OJ — Purple brand
   ═══════════════════════════════════════════ */

:root {
  --brand: #6C5CE7;
  --brand-dark: #5A4BD1;
  --brand-light: #A29BFE;
  --brand-bg: rgba(108,92,231,0.06);

  --green: #00B894;
  --green-bg: rgba(0,184,148,0.08);
  --yellow: #E17055;
  --yellow-bg: rgba(225,112,85,0.08);
  --red: #D63031;
  --red-bg: rgba(214,48,49,0.08);

  --nav-h: 56px;
  --gray-50: #FAFAFA;
  --gray-100: #F5F5F5;
  --gray-200: #E8E8E8;
  --gray-300: #D9D9D9;
  --gray-400: #BFBFBF;
  --gray-500: #8C8C8C;
  --gray-600: #595959;
  --gray-700: #434343;
  --gray-800: #262626;
  --gray-900: #1F1F1F;

  --text-primary: #262626;
  --text-secondary: #595959;
  --text-tertiary: #8C8C8C;
  --bg-body: #F0F2F5;
  --bg-card: #FFFFFF;
  --border: #E8E8E8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ═══ Nav ═══ */
nav {
  position: sticky; top:0; z-index:100;
  height: var(--nav-h);
  background: var(--gray-900);
  padding: 0 24px;
  display: flex;
  align-items: center;
}
nav .nav-inner {
  max-width: 1200px; width:100%; margin:0 auto;
  display:flex; align-items:center; justify-content:space-between;
}
nav .logo-area { display:flex; align-items:center; gap:10px; text-decoration:none; }
nav .logo-area img { width:28px; height:28px; border-radius:6px; flex-shrink:0; }
nav .logo-text { font-size:17px; font-weight:700; color:#fff; letter-spacing:-0.3px; }

nav .nav-links { display:flex; gap:4px; align-items:center; }
nav .nav-links a {
  text-decoration:none; color: rgba(255,255,255,0.65);
  padding: 8px 16px; border-radius: 6px;
  font-size: 14px; font-weight: 500;
  transition: all 0.15s;
}
nav .nav-links a:hover { color: #fff; background: rgba(255,255,255,0.08); }
nav .nav-links a.active { color: #fff; background: rgba(255,255,255,0.12); }
nav .nav-links a.btn-brand {
  background: var(--brand); color: #fff !important;
  padding: 6px 16px; font-weight:600;
}
nav .nav-links a.btn-brand:hover { background: var(--brand-dark); }

nav .user-menu { display:flex; align-items:center; gap:10px; }
nav .user-tag {
  font-size: 12px; padding: 3px 10px; border-radius: 100px; font-weight:600;
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.85);
}
nav .user-tag.admin { background: rgba(214,48,49,0.5); color: #fff; }
nav .user-tag.teacher { background: rgba(0,184,148,0.5); color: #fff; }
nav .logout-link { color: rgba(255,255,255,0.5); font-size:13px; text-decoration:none; }
nav .logout-link:hover { color: #fff; }

/* ═══ Layout ═══ */
.main-content { max-width:1200px; margin:0 auto; padding:24px; width:100%; min-height: calc(100vh - var(--nav-h) - 60px); }

/* ═══ Cards ═══ */
.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between;
}
.card-body { padding: 24px; }
.card-footer { padding: 12px 24px; border-top: 1px solid var(--border); background: var(--gray-50); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ═══ Buttons ═══ */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  padding: 8px 20px; border-radius: 6px;
  font-size: 14px; font-weight:600;
  text-decoration:none; transition: all 0.15s;
  font-family: inherit; cursor: pointer; border: none;
  white-space: nowrap;
}
.btn-brand { background: var(--brand); color:#fff; }
.btn-brand:hover { background: var(--brand-dark); }
.btn-outline { background: #fff; color: var(--text-primary); border: 1px solid var(--gray-300); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: var(--red); color:#fff; }
.btn-danger:hover { opacity:0.9; }
.btn-sm { padding: 5px 14px; font-size:13px; }
.btn-xs { padding: 3px 10px; font-size:12px; border-radius:4px; }

/* ═══ Badges ═══ */
.badge {
  display:inline-flex; align-items:center; gap:4px;
  padding: 2px 10px; border-radius: 100px;
  font-size: 12px; font-weight:500; white-space:nowrap;
}
.badge-dot { width:6px; height:6px; border-radius:50%; flex-shrink:0; }
.badge-easy { background: var(--green-bg); color: var(--green); }
.badge-easy .badge-dot { background: var(--green); }
.badge-medium { background: var(--yellow-bg); color: var(--yellow); }
.badge-medium .badge-dot { background: var(--yellow); }
.badge-hard { background: var(--red-bg); color: var(--red); }
.badge-hard .badge-dot { background: var(--red); }
.badge-accepted { background: var(--green-bg); color: var(--green); }
.badge-wrong { background: var(--red-bg); color: var(--red); }
.badge-pending { background: var(--brand-bg); color: var(--brand); }
.badge-neutral { background: var(--gray-100); color: var(--text-secondary); }

/* ═══ Tables ═══ */
table { width:100%; border-collapse:collapse; }
thead th {
  padding: 10px 16px; text-align:left;
  font-size:12px; font-weight:600; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing:0.3px;
  border-bottom: 2px solid var(--border);
  background: var(--gray-50);
}
tbody td {
  padding: 12px 16px;
  font-size:14px;
  border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: var(--brand-bg); }
tbody tr:last-child td { border-bottom:none; }

/* ═══ Forms ═══ */
.form-group { margin-bottom: 20px; }
.form-label {
  display:block; font-size:13px; font-weight:600; color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-label .required { color: var(--red); }
.form-input, .form-textarea, .form-select {
  width:100%; padding: 9px 14px; border-radius: 6px;
  border: 1px solid var(--gray-300);
  font-family: inherit; font-size: 14px;
  background: #fff; color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(108,92,231,0.1);
}
.form-input::placeholder { color: var(--gray-400); }
.form-textarea {
  resize:vertical; min-height:120px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Courier New", monospace;
  font-size: 13px; line-height: 1.6;
}
.form-select { cursor:pointer; appearance:none; }
.form-hint { font-size:12px; color: var(--text-tertiary); margin-top:4px; }

/* ═══ Page header ═══ */
.page-header {
  margin-bottom: 24px;
  display:flex; align-items:center; justify-content:space-between;
  flex-wrap:wrap; gap:12px;
}
.page-title { font-size:22px; font-weight:700; color: var(--text-primary); }
.page-subtitle { font-size:14px; color: var(--text-secondary); margin-top:4px; }

/* ═══ Stats row ═══ */
.stats-row {
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px 24px;
  text-align:center;
}
.stat-card .stat-value { font-size:32px; font-weight:800; color: var(--text-primary); line-height:1.2; }
.stat-card .stat-label { font-size:13px; color: var(--text-tertiary); margin-top:4px; }
.stat-card.brand .stat-value { color: var(--brand); }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.red .stat-value { color: var(--red); }

/* ═══ Code editor ═══ */
.code-editor {
  background: #1E1E2E;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--gray-800);
}
.code-editor-header {
  padding: 10px 16px;
  background: #181825;
  display:flex; align-items:center; justify-content:space-between;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.code-editor-header .lang-tag {
  font-size: 12px; font-weight:600; color: rgba(255,255,255,0.5);
}
.code-editor textarea {
  width:100%; min-height:300px; padding: 16px;
  background: transparent; border:none; resize:vertical;
  color: #CDD6F4; font-family: "SF Mono", "Fira Code", "Cascadia Code", "Courier New", monospace;
  font-size: 14px; line-height: 1.7;
  tab-size: 4;
  outline: none;
}
.code-editor textarea::placeholder { color: rgba(205,214,244,0.25); }

/* ═══ Alerts ═══ */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 14px; margin-bottom: 16px;
  display:flex; align-items:flex-start; gap:8px;
}
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(214,48,49,0.15); }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(0,184,148,0.15); }
.alert-info { background: var(--brand-bg); color: var(--brand); border: 1px solid rgba(108,92,231,0.15); }

/* ═══ Empty state ═══ */
.empty-state {
  text-align:center; padding: 48px 24px;
}
.empty-state .empty-icon { font-size:40px; margin-bottom:12px; opacity:0.5; }
.empty-state .empty-title { font-size:16px; font-weight:600; color: var(--text-secondary); margin-bottom:4px; }
.empty-state .empty-desc { font-size:14px; color: var(--text-tertiary); }

/* ═══ Footer ═══ */
footer {
  padding: 24px;
  text-align:center;
  font-size: 13px; color: var(--text-tertiary);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
footer .footer-brand { font-weight:700; color: var(--text-secondary); margin-bottom:2px; }
footer a { color: var(--brand); text-decoration:none; }
footer a:hover { text-decoration:underline; }

/* ═══ Portal hero ═══ */
.portal-hero {
  text-align:center; padding: 56px 24px 32px;
}
.portal-hero .hero-logo { width:72px; height:72px; border-radius:16px; margin-bottom:16px; }
.portal-hero h1 { font-size:36px; font-weight:800; letter-spacing:-0.5px; margin-bottom:8px; }
.portal-hero .hero-sub { font-size:16px; color: var(--text-secondary); max-width:480px; margin:0 auto 24px; }
.portal-hero .hero-actions { display:flex; gap:12px; justify-content:center; flex-wrap:wrap; }

/* ═══ Problem grid ═══ */
.problem-grid {
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.problem-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px 24px;
  transition: all 0.15s;
  text-decoration:none; color:inherit; display:block;
}
.problem-card:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-md);
}
.problem-card .pc-title { font-size:16px; font-weight:700; margin-bottom:8px; display:flex; align-items:center; gap:8px; }
.problem-card .pc-meta { font-size:13px; color: var(--text-tertiary); }
.problem-card .pc-stats { font-size:13px; color: var(--text-secondary); margin-top:8px; display:flex; gap:16px; }

/* ═══ Split layout ═══ */
.split-layout {
  display:grid; grid-template-columns:1fr 1fr; gap:24px;
}
@media (max-width:900px) {
  .split-layout { grid-template-columns:1fr; }
}

/* ═══ Ranking table ═══ */
.rank-num { font-weight:700; font-size:15px; }
.rank-1, .rank-2, .rank-3 { font-size:20px; }

/* ═══ Pagination ═══ */
.pagination { display:flex; gap:4px; justify-content:center; margin-top:24px; }
.pagination a {
  min-width:36px; height:36px; display:inline-flex; align-items:center; justify-content:center;
  border-radius:6px; font-size:14px; font-weight:500;
  text-decoration:none; color: var(--text-secondary);
  border:1px solid var(--border); background:#fff;
}
.pagination a:hover { border-color: var(--brand); color: var(--brand); }
.pagination a.active { background: var(--brand); color:#fff; border-color: var(--brand); }

/* ═══ App Carousel ═══ */
.app-carousel-wrap {
  position: relative;
  margin-bottom: 24px;
}
.app-carousel {
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 4px 4px 12px 4px;
  scroll-behavior: smooth;
}
.app-carousel::-webkit-scrollbar { height: 4px; }
.app-carousel::-webkit-scrollbar-track { background: transparent; }
.app-carousel::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

.app-carousel-card {
  flex: 0 0 300px;
  scroll-snap-align: start;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 160px;
}
.app-carousel-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
.app-carousel-card.featured {
  border: 2px solid var(--brand);
  background: linear-gradient(135deg, #fff 0%, #f0f4ff 100%);
}
.app-carousel-card .ac-icon {
  font-size: 32px; margin-bottom: 12px;
}
.app-carousel-card .ac-title {
  font-size: 16px; font-weight: 700; margin-bottom: 6px;
}
.app-carousel-card .ac-desc {
  font-size: 13px; color: var(--text-tertiary); line-height: 1.5;
}
.app-carousel-card .ac-tag {
  display: inline-block;
  margin-top: 10px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
}
.app-carousel-card.placeholder .ac-tag {
  background: var(--gray-200);
  color: var(--text-tertiary);
}

.carousel-arrow {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  font-size: 20px; line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.carousel-arrow:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: #f0f4ff;
}

/* ═══ Responsive ═══ */
@media (max-width:768px) {
  nav { padding:0 12px; }
  nav .nav-links a { padding:6px 10px; font-size:13px; }
  .main-content { padding:16px; }
  .page-title { font-size:18px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .split-layout { grid-template-columns:1fr; }
  .problem-grid { grid-template-columns:1fr; }
  .portal-hero h1 { font-size:26px; }
}
