/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; }

body {
  background: linear-gradient(135deg, #c8e8f8 0%, #dff0fb 40%, #e8f5ff 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== App Wrapper ===== */
.app-wrapper {
  width: 96vw;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.8);
  box-shadow: 0 4px 20px rgba(70,150,220,0.12);
}
.header-icon { font-size: 1.6rem; }
.app-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1a5f8a;
  letter-spacing: 1px;
}

/* ===== Main Layout ===== */
.main-content {
  display: flex;
  gap: 20px;
  align-items: stretch;
}

/* ===== Panel Base ===== */
.panel {
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(14px);
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.85);
  box-shadow: 0 8px 32px rgba(70,150,220,0.15);
  padding: 18px;
  position: relative;
}

.panel-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #3a88bb;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 10px;
  padding: 3px 10px;
  background: rgba(91,184,232,0.18);
  border-radius: 20px;
  display: inline-block;
}

/* ===== 3D Panel ===== */
.panel-3d {
  flex: 1.4;
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.scene-container {
  flex: 1;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(160deg, #e4f4ff 0%, #f0f8ff 100%);
  border: 1px solid rgba(91,184,232,0.3);
  min-height: 340px;
}

#threeCanvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ===== Icon Buttons (rotate/undo/delete) ===== */
.icon-btn {
  background: rgba(255,255,255,0.8);
  border: 1.5px solid rgba(91,184,232,0.5);
  border-radius: 10px;
  width: 42px;
  height: 42px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s ease;
  color: #1a5f8a;
  box-shadow: 0 2px 8px rgba(70,150,220,0.15);
}
.icon-btn:hover {
  background: rgba(91,184,232,0.25);
  border-color: #5BB8E8;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(91,184,232,0.35);
}
.icon-btn:active { transform: translateY(0); }
.icon-btn.active {
  background: #5BB8E8;
  color: white;
  border-color: #5BB8E8;
}

.rotate-btn {
  position: absolute;
  top: 48px;
  left: 18px;
  z-index: 10;
  font-size: 1.4rem;
}

/* ===== View Buttons ===== */
.view-btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.view-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 12px;
  border: 1.5px solid rgba(91,184,232,0.5);
  background: rgba(255,255,255,0.75);
  color: #1a5f8a;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: 0 2px 8px rgba(70,150,220,0.1);
}
.view-btn:hover {
  background: rgba(91,184,232,0.2);
  border-color: #5BB8E8;
  transform: translateY(-1px);
}
.view-btn.active {
  background: #5BB8E8;
  color: white;
  border-color: #5BB8E8;
  box-shadow: 0 4px 14px rgba(91,184,232,0.4);
}
.btn-reset {
  background: rgba(255,255,255,0.9);
  border-color: rgba(150,200,240,0.6);
}

/* ===== Grid Panel ===== */
.panel-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 280px;
}

.grid-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== 4x4 Grid ===== */
.grid-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  aspect-ratio: 1;
  max-width: 300px;
}

.grid-cell {
  border-radius: 10px;
  border: 2px solid rgba(180,220,250,0.6);
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
  box-shadow: 0 2px 6px rgba(70,150,220,0.1);
  position: relative;
  overflow: hidden;
  min-height: 60px;
}
.grid-cell:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 14px rgba(70,150,220,0.25);
}
.grid-cell.empty {
  background: rgba(255,255,255,0.7);
  color: transparent;
  border-color: rgba(180,220,250,0.5);
}
.grid-cell.selected {
  border-color: #2ecc71 !important;
  box-shadow: 0 0 0 3px rgba(46,204,113,0.35), 0 4px 14px rgba(46,204,113,0.2);
  transform: scale(1.06);
}

/* Layer colors for grid cells */
.grid-cell[data-height="1"] { background: linear-gradient(135deg, #5BB8E8, #3A9DD4); }
.grid-cell[data-height="2"] { background: linear-gradient(135deg, #2D7FBF, #1A5F9A); }
.grid-cell[data-height="3"] { background: linear-gradient(135deg, #4CAF50, #2E7D32); }
.grid-cell[data-height="4"] { background: linear-gradient(135deg, #FF9800, #E65100); }
.grid-cell[data-height="5"] { background: linear-gradient(135deg, #9C27B0, #6A0080); }
.grid-cell[data-height="6"] { background: linear-gradient(135deg, #F44336, #B71C1C); }

/* ===== Number Selector ===== */
.number-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: rgba(255,255,255,0.7);
  border-radius: 14px;
  border: 1.5px solid rgba(91,184,232,0.4);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(70,150,220,0.1);
}

.num-btn {
  background: transparent;
  border: none;
  padding: 12px 24px;
  font-size: 1.4rem;
  font-weight: 700;
  color: #1a5f8a;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1;
}
.num-btn:hover { background: rgba(91,184,232,0.2); }
.num-btn:active { background: rgba(91,184,232,0.4); }

.num-display {
  flex: 1;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: #1a5f8a;
  min-width: 50px;
  border-left: 1px solid rgba(91,184,232,0.3);
  border-right: 1px solid rgba(91,184,232,0.3);
  padding: 10px 0;
}

/* ===== Legend ===== */
.legend {
  background: rgba(255,255,255,0.5);
  border-radius: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(91,184,232,0.2);
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #3a6f8f;
  font-weight: 600;
  flex-wrap: wrap;
}
.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ===== Responsive ===== */
@media (max-width: 700px) {
  .main-content { flex-direction: column; }
  .panel-3d { min-height: 320px; }
}
