:root {
  --bg: #05060a;
  --panel: rgba(14, 18, 28, 0.82);
  --panel-border: rgba(120, 150, 200, 0.18);
  --text: #e7ecf3;
  --muted: #9aa6b8;
  --accent: #66ccff;
  --accent2: #ffcc66;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }

#app { position: relative; width: 100vw; height: 100vh; }

#scene-container { position: absolute; inset: 0; }
#scene-container canvas { display: block; }

.view-context {
  position: absolute; top: 12px; left: 50%; z-index: 3;
  transform: translateX(-50%); max-width: calc(100vw - 700px);
  padding: 6px 10px; border: 1px solid var(--panel-border); border-radius: 999px;
  background: rgba(8, 12, 20, 0.78); color: var(--muted); font-size: 11px;
  text-align: center; pointer-events: none; backdrop-filter: blur(8px);
}
.view-context.matched { color: var(--accent); border-color: rgba(102,204,255,0.35); }

.card {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(120,150,200,0.4) transparent;
}
.card::-webkit-scrollbar { width: 6px; }
.card::-webkit-scrollbar-thumb { background: rgba(120,150,200,0.4); border-radius: 3px; }

#panel { top: 12px; left: 12px; width: 290px; max-height: calc(100vh - 24px); }
#info { top: 12px; right: 12px; width: 340px; max-height: calc(100vh - 24px); }

h1 { font-size: 16px; margin: 0 0 2px; letter-spacing: 0.3px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--accent); margin: 14px 0 6px; }
.subtitle { font-size: 11px; color: var(--muted); margin: 0 0 6px; }
section { border-top: 1px solid var(--panel-border); padding-top: 8px; }
section:first-of-type { border-top: none; padding-top: 0; }

input[type="datetime-local"], select {
  width: 100%; padding: 6px 8px; background: rgba(0,0,0,0.3); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px; font-size: 13px;
}
label { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 4px 0; cursor: pointer; }
.row { display: flex; gap: 6px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

button {
  flex: 1; padding: 6px 8px; background: rgba(102,204,255,0.12); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px; font-size: 12px; cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: rgba(102,204,255,0.25); }
button.full { width: 100%; flex: none; margin-top: 6px; }
#play { background: rgba(255,204,102,0.18); }
#play:hover { background: rgba(255,204,102,0.3); }

.speed { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); flex: 1; }
.speed input[type="range"] { width: 100%; }
input[type="range"] { accent-color: var(--accent); }

.date-display { font-size: 11px; color: var(--muted); margin-top: 6px; }
.scale-note { font-size: 11px; color: var(--muted); margin-top: 4px; }
.hint { font-size: 10px; color: var(--muted); margin-top: 10px; opacity: 0.7; }

/* Phase panel */
.phase-row { display: flex; gap: 12px; align-items: center; }
#phaseMini { background: transparent; border-radius: 50%; }
.phase-name { font-size: 18px; font-weight: 600; color: var(--accent2); }
.phase-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rotation-status { color: var(--accent); margin-top: 5px; }
.phase-view-note {
  margin-top: 5px; color: var(--accent); font-size: 10px; line-height: 1.35;
}

.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; margin: 3px 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; color: var(--text); }

.explain { font-size: 12px; line-height: 1.5; color: var(--text); }
.explain p { margin: 0 0 8px; }
.explain b { color: var(--accent2); }
.sme-note { font-size: 11px; color: var(--accent); border-left: 2px solid var(--accent); padding-left: 8px; }

/* CSS2D labels */
.sme-label {
  color: #cfe3ff; font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
  text-shadow: 0 0 6px rgba(0,0,0,0.9), 0 0 3px rgba(0,0,0,1);
  padding: 1px 4px; pointer-events: none; white-space: nowrap;
  transform: translateY(-2px);
}

/* Loading */
#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: var(--bg); color: var(--muted); font-size: 13px; z-index: 10;
}
.spinner {
  width: 38px; height: 38px; border: 3px solid rgba(102,204,255,0.2);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  #panel, #info { width: 260px; }
  .view-context { display: none; }
}

@media (max-width: 560px) {
  #panel, #info { left: 12px; right: 12px; width: auto; }
  #panel { top: 12px; max-height: calc(55vh - 18px); }
  #info { top: auto; bottom: 12px; max-height: calc(45vh - 18px); }
}
