* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #e2e8f0;
  
  /* Deep vibrant animated background */
  background: radial-gradient(circle at 15% 50%, #1e1b4b, #020617, #0f172a);
  background-size: 200% 200%;
  animation: bgShift 15s ease infinite;
  
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

@keyframes bgShift { 
  0% {background-position: 0% 50%} 
  50% {background-position: 100% 50%} 
  100% {background-position: 0% 50%} 
}

/* --- Glassmorphism UI Shell --- */
header, #tools, #panel, .card {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
header {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1); flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 50;
  position: relative;
}
h1 { font-size: 17px; margin: 0 12px 0 0; color: #f8fafc; text-shadow: 0 0 10px rgba(255,255,255,0.2); }

/* --- Form controls & Neon glow --- */
button, select, input {
  font: inherit; padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #f8fafc;
  cursor: pointer; touch-action: manipulation;
  transition: all 0.2s ease;
}
button:hover:not(:disabled) { background: rgba(255,255,255,0.15); box-shadow: 0 0 10px rgba(255,255,255,0.1); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* Primary buttons with Neon glow */
button.primary { background: #4f46e5; border-color: #6366f1; box-shadow: 0 0 12px rgba(99,102,241,0.5); }
button.primary:hover { background: #6366f1; box-shadow: 0 0 18px rgba(99,102,241,0.8); }

#mode-toggle { background: rgba(16, 185, 129, 0.2); border-color: #34d399; color: #a7f3d0; box-shadow: 0 0 10px rgba(16,185,129,0.3); }
#mode-toggle:hover { background: rgba(16, 185, 129, 0.4); box-shadow: 0 0 15px rgba(16,185,129,0.6); }

/* --- Containers --- */
main { flex: 1; display: flex; position: relative; z-index: 1; }

#tools, #panel { padding: 12px; }

/* --- Stage (White Background is strictly enforced) --- */
#stage {
  flex: 1; 
  position: relative; 
  overflow: hidden; 
  z-index: 10;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}
#ed { 
  position: absolute; inset: 0; width: 100%; height: 100%; 
  background: #ffffff; cursor: crosshair; touch-action: none; 
}
.canvas-container-3d { position: relative; width: 100%; height: 320px; border-radius: 10px; overflow: hidden; margin: 8px 0; }
#v3 { position: absolute; top:0; left:0; width: 100%; height: 100%; background: #ffffff; touch-action: none; cursor: grab; }


/* --- UI Elements --- */
.grp { display: grid; gap: 6px; margin-bottom: 12px; }
.grp button { height: 40px; padding: 2px; font-weight: 700; font-size: 15px; }

.grp button.on, .pre.on, .tab.on {
  background: rgba(99, 102, 241, 0.4);
  border-color: #818cf8;
  box-shadow: 0 0 12px rgba(129, 140, 248, 0.6), inset 0 0 6px rgba(129,140,248,0.4);
  color: #fff;
}

#elements button { filter: brightness(1.5) drop-shadow(0 0 3px currentColor); background: rgba(0,0,0,0.2); }
#elements button.on { background: rgba(99,102,241,0.4); filter: brightness(2) drop-shadow(0 0 5px currentColor); }

.grp svg { width: 22px; height: 22px; stroke: #e2e8f0; stroke-width: 2; fill: none; }
.grp svg polygon { fill: #e2e8f0; }

.sect { font-size: 11px; font-weight: 700; color: #94a3b8; margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.hintsm { font-size: 11px; color: #cbd5e1; margin-bottom: 8px; line-height: 1.3; }
#status { margin-top: 10px; font-size: 12px; color: #94a3b8; }
.lbl { font-size: 12px; color: #94a3b8; }
.big { font-size: 22px; font-weight: 700; color: #f8fafc; text-shadow: 0 0 8px rgba(255,255,255,0.3); }

/* --- Tags / Pills --- */
.chip { display: inline-block; padding: 4px 10px; border-radius: 99px; font-weight: 700; color: #fff; margin: 6px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.aromatic { background: #16a34a; box-shadow: 0 0 10px rgba(22,163,74,0.5); }
.antiaromatic { background: #dc2626; box-shadow: 0 0 10px rgba(220,38,38,0.5); }
.nonaromatic, .acyclic { background: #64748b; }
.mixed { background: #d97706; }
.ring { border-left: 4px solid #94a3b8; padding: 8px; margin: 8px 0; background: rgba(255,255,255,0.05); border-radius: 0 8px 8px 0; font-size: 13px; }
.ring.aromatic { border-color: #16a34a; } 
.ring.antiaromatic { border-color: #dc2626; }
.warn { background: rgba(245, 158, 11, 0.15); border: 1px solid #f59e0b; border-radius: 8px; padding: 8px; font-size: 13px; margin: 6px 0; color: #fcd34d; }
.hint { font-size: 12px; color: #cbd5e1; }

.prow { display: flex; gap: 6px; margin-bottom: 6px; }
.prow button { flex: 1; min-width: 0; height: 36px; font-size: 12px; font-weight: 600; }
.prow input { width: 50px; text-align: center; }

nav { display: flex; gap: 6px; margin-bottom: 12px; }
nav button { flex: 1; min-height: 40px; }
#panel>div>button { width: 100%; margin-bottom: 8px; padding: 10px; }
.row { display: flex; justify-content: space-between; margin-top: 6px; }
.row3 { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

/* Splitters */
.split { flex: none; width: 7px; cursor: col-resize; background: rgba(255,255,255,0.05); position: relative; touch-action: none; z-index: 20; }
.split::after { content: ""; position: absolute; left: 2px; top: 50%; width: 3px; height: 36px; margin-top: -18px; border-radius: 2px; background: rgba(255,255,255,0.2); }
.split:hover, .split.drag { background: rgba(99,102,241,0.3); }
.split:hover::after, .split.drag::after { background: #818cf8; box-shadow: 0 0 8px #818cf8; }

/* =========================================
   MODE SPECIFIC STYLES 
   ========================================= */

/* --- LAPTOP MODE --- */
body.laptop-mode main { flex-direction: row; }
body.laptop-mode #tools { width: 180px; overflow-y: auto; z-index: 20; border-right: 1px solid rgba(255,255,255,0.1); }
body.laptop-mode #panel { width: 360px; overflow-y: auto; z-index: 20; border-left: 1px solid rgba(255,255,255,0.1); }
body.laptop-mode .grp { grid-template-columns: repeat(auto-fill, minmax(45px, 1fr)); }
body.laptop-mode .grp.small button { font-size: 11px; padding: 4px; }
body.laptop-mode .split { display: block; }

/* --- MOBILE MODE --- */
body.mobile-mode { overflow-y: auto; overflow-x: hidden; }
body.mobile-mode main { flex-direction: column; overflow: visible; }
body.mobile-mode .split { display: none !important; }

/* 1. Canvas at the top */
body.mobile-mode #stage {
  order: 1;
  width: 100%;
  flex: none;
  height: 55vh; 
  min-height: 350px;
}

/* 2. Tools dock below canvas (Fixes Clutter) */
body.mobile-mode #tools {
  order: 2;
  width: 100% !important;
  flex: none;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  border-right: none;
  padding: 12px 16px;
}
/* Horizontal scrolling grids for tools */
body.mobile-mode .grp {
  display: flex; flex-wrap: nowrap; overflow-x: auto;
  gap: 10px; padding-bottom: 10px; -webkit-overflow-scrolling: touch;
}
body.mobile-mode .grp button { flex: 0 0 auto; width: 48px; }
body.mobile-mode .grp.small button { width: auto; padding: 0 16px; font-size: 13px; }

/* 3. Panel at the bottom */
body.mobile-mode #panel {
  order: 3;
  width: 100% !important;
  flex: none;
  border-left: none;
  padding: 16px;
}
/* --- Footer --- */
#site-footer { flex: none; padding: 5px 12px; text-align: center; font-size: 11px; line-height: 1.35; color: #94a3b8; background: rgba(15,23,42,0.85); border-top: 1px solid rgba(255,255,255,0.08); position: relative; z-index: 30; }
#site-footer p { margin: 0; }
#site-footer a { color: #a5b4fc; }
.chip.dpn { background: #64748b; } .chip.dpw { background: #0ea5e9; } .chip.dpp { background: #d97706; } .chip.dps { background: #dc2626; }
body.laptop-mode main { min-height: 0; }
body.laptop-mode { height: 100dvh; }
body.laptop-mode #stage { min-height: 0; }
select option {
  background: #0f172a;
  color: #f8fafc;
}

/* --- Tutorial --- */
#tour-btn { background: rgba(245,158,11,0.18); border-color: #fbbf24; color: #fde68a; box-shadow: 0 0 10px rgba(245,158,11,0.35); font-weight: 600; }
#tour-btn:hover { background: rgba(245,158,11,0.35); }
#tour-block { position: fixed; inset: 0; z-index: 9990; background: transparent; }
#tour-block.dim { background: rgba(2,6,23,0.82); }
#tour-hole { position: fixed; z-index: 9991; pointer-events: none; border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(2,6,23,0.80), 0 0 0 2px #a5b4fc, 0 0 28px 6px rgba(129,140,248,0.65);
  transition: left .25s, top .25s, width .25s, height .25s; }
#tour-card { position: fixed; z-index: 9992; background: #0f172a; border: 1px solid rgba(129,140,248,0.6); border-radius: 14px; padding: 14px 16px 12px; color: #e2e8f0; box-shadow: 0 12px 40px rgba(0,0,0,0.65); font-size: 13.5px; line-height: 1.45; }
#tour-card h3 { margin: 2px 0 6px; font-size: 16px; color: #f8fafc; }
#tour-card p { margin: 0 0 10px; color: #cbd5e1; }
#tour-card .tc-step { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #a5b4fc; }
#tour-card .tc-bar { height: 3px; background: rgba(255,255,255,0.1); border-radius: 3px; margin-bottom: 10px; overflow: hidden; }
#tour-card .tc-bar i { display: block; height: 100%; background: #818cf8; }
#tour-card .tc-actions { display: flex; gap: 6px; align-items: center; }
#tour-card .tc-actions span { flex: 1; }
#tour-card .tc-actions button { padding: 6px 12px; }

.ring.ezE { border-color: #d97706; } .ring.ezZ { border-color: #0284c7; }

.ring.rsR { border-color: #dc2626; } .ring.rsS { border-color: #2563eb; } .ring.rsU { border-color: #64748b; }

.sol { display: inline-block; padding: 3px 9px; border-radius: 99px; margin: 2px 3px 2px 0; font-size: 12px; font-weight: 600; color: #fff; }
.sol small { opacity: .8; font-weight: 400; }
.sol.good { background: #16a34a; } .sol.partial { background: #d97706; } .sol.poor { background: #64748b; }

/* --- 2D zoom controls --- */
#zoombox { position: absolute; top: 10px; right: 10px; z-index: 12; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px; border-radius: 12px; background: rgba(15,23,42,0.78); border: 1px solid rgba(255,255,255,0.15); box-shadow: 0 4px 16px rgba(0,0,0,0.35); }
#zoombox button { width: 40px; height: 40px; padding: 0; font-size: 22px; font-weight: 700; line-height: 1; }
#zoombox span { font-size: 11px; color: #cbd5e1; font-variant-numeric: tabular-nums; }
#full { background: linear-gradient(90deg, #059669, #4f46e5); border-color: #34d399; }
#full:hover { background: linear-gradient(90deg, #10b981, #6366f1); }
