:root {
  --primary: #4A90D9;
  --primary-dark: #357ABD;
  --accent: #5BC0EB;
  --success: #52C41A;
  --warning: #FAAD14;
  --danger: #FF4D4F;
  --bg: #F0F4F8;
  --surface: #FFFFFF;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --radius: 12px;
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.header {
  background: linear-gradient(135deg, var(--primary) 0%, #6BB5FF 100%);
  color: white;
  padding: 12px 16px 0;
  box-shadow: var(--shadow);
  z-index: 10;
  flex-shrink: 0;
}

.header-inner { text-align: center; margin-bottom: 10px; }
.logo { font-size: 1.4rem; font-weight: 700; }
.subtitle { font-size: 0.8rem; opacity: 0.85; margin-top: 2px; }

.nav-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  flex: 1;
  min-width: 80px;
  padding: 10px 8px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: all 0.25s;
  white-space: nowrap;
}
.nav-tab.active {
  background: var(--bg);
  color: var(--primary);
  font-weight: 700;
}
.nav-tab:hover:not(.active) { background: rgba(255,255,255,0.25); }

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #E8EDF2;
}

#canvas3d {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.view-badges {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}

.view-badge {
  background: rgba(255,255,255,0.92);
  border-radius: 8px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 0.75rem;
  animation: fadeIn 0.4s ease;
}

.view-badge .label { font-weight: 700; color: var(--primary); }
.view-badge canvas { border-radius: 4px; }

.subtitle-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.65);
  color: white;
  padding: 10px 16px;
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.4;
}

.control-panel {
  background: var(--surface);
  padding: 16px;
  border-top: 1px solid #E0E6ED;
  flex: 0 0 45vh;
  overflow-y: auto;
}

.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-desc {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-bottom: 14px;
  line-height: 1.5;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.btn {
  padding: 10px 18px;
  border: 2px solid var(--primary);
  background: white;
  color: var(--primary);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}
.btn:hover { background: #EBF4FF; }
.btn.active, .btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { border-color: var(--success); color: var(--success); }
.btn-success.active { background: var(--success); color: white; }
.btn-danger { border-color: var(--danger); color: var(--danger); }

.slider-group {
  margin-bottom: 14px;
}
.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 6px;
  font-weight: 500;
}
.slider-group input[type=range] {
  width: 100%;
  accent-color: var(--primary);
  height: 6px;
}

.status-bar {
  background: #EBF4FF;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.status-bar .count { font-weight: 700; color: var(--primary); font-size: 1.1rem; }

.net-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.net-item {
  border: 2px solid #E0E6ED;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  position: relative;
}
.net-item.active { border-color: var(--primary); background: #EBF4FF; }
.net-item canvas { width: 100%; height: auto; }
.net-item .tag {
  position: absolute;
  top: 2px; right: 2px;
  font-size: 0.6rem;
  padding: 1px 4px;
  border-radius: 4px;
  color: white;
}
.tag.correct { background: var(--success); }
.tag.wrong { background: var(--danger); }

.net-section {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px dashed #E0E6ED;
}
.net-section:last-of-type { border-bottom: none; }
.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 4px;
}
.section-formula {
  font-size: 0.75rem;
  color: #D48806;
  font-weight: 600;
  margin-bottom: 8px;
}
.net-section .net-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 0;
}
.net-section .net-item { padding: 4px; }
.net-section .net-item .tag { font-size: 0.55rem; padding: 1px 3px; }

.projection-preview {
  display: flex;
  gap: 12px;
  margin: 12px 0;
  justify-content: center;
}
.proj-box {
  text-align: center;
}
.proj-box .proj-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}
.proj-box canvas {
  border: 2px solid #E0E6ED;
  border-radius: 6px;
  background: white;
}

/* 自由搭建模式 */
.build-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 10px 0;
  max-width: 220px;
  margin-left: auto;
  margin-right: auto;
}
.build-cell {
  aspect-ratio: 1;
  border: 2px solid #D0D7DE;
  border-radius: 6px;
  background: #FAFBFC;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
}
.build-cell:hover { border-color: var(--primary); background: #EBF4FF; }
.build-cell.filled {
  background: var(--accent);
  border-color: var(--primary);
  color: white;
}
.build-cell.base {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: white;
}
.build-layers {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 10px;
}
.build-layer-btn {
  padding: 6px 14px;
  border: 2px solid #D0D7DE;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
}
.build-layer-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.build-info {
  font-size: 0.78rem;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 8px;
}

.observer-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.observer-card {
  border: 2px solid #E0E6ED;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.observer-card.active {
  border-color: var(--primary);
  background: #EBF4FF;
}
.observer-card .avatar { font-size: 2rem; margin-bottom: 4px; }
.observer-card .name { font-weight: 700; font-size: 0.9rem; }

.install-banner {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  background: var(--text);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  z-index: 100;
  font-size: 0.85rem;
}
.install-banner.hidden { display: none; }
.install-banner button {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
}
#installBtn { background: var(--primary); color: white; }
.close-btn { background: transparent; color: #aaa; margin-left: auto; font-size: 1rem; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 768px) {
  .main {
    flex-direction: row;
    height: 100%;
  }
  .canvas-wrap { flex: 2; min-height: unset; }
  .control-panel {
    flex: 0 0 380px;
    max-width: 380px;
    max-height: unset;
    border-top: none;
    border-left: 1px solid #E0E6ED;
    overflow-y: auto;
  }
  .logo { font-size: 1.6rem; }
  .nav-tab { font-size: 0.9rem; padding: 12px 16px; }
}
