/* ── SpeedCubeLab — Main Stylesheet ────────────────────────────────── */

.hidden { display: none !important; }

/* ── Splash Screen ────────────────────────────────────────────────── */

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1c1c1e;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  overflow: hidden;
}

.splash-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.3;
  animation: splash-pulse 4s ease-in-out infinite alternate;
}

.splash-bg-glow--blue {
  width: 300px;
  height: 300px;
  background: #0a84ff;
  top: 10%;
  right: 10%;
}

.splash-bg-glow--green {
  width: 250px;
  height: 250px;
  background: #30d158;
  bottom: 15%;
  left: 10%;
}

@keyframes splash-pulse {
  from { transform: scale(1); opacity: 0.2; }
  to   { transform: scale(1.3); opacity: 0.35; }
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 1;
}

.splash-logo-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splash-logo {
  width: 80px;
  height: 80px;
  border-radius: 18px;
  position: relative;
  z-index: 2;
  animation: splash-logo-in 0.8s ease-out both;
}

@keyframes splash-logo-in {
  from { transform: scale(0.5) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

.splash-logo-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(10, 132, 255, 0.3);
  animation: splash-ring 2s ease-out infinite;
}

.splash-logo-ring:nth-child(2) { animation-delay: 0.5s; }
.splash-logo-ring:nth-child(3) { animation-delay: 1s; }

@keyframes splash-ring {
  from { transform: scale(0.8); opacity: 0.6; }
  to   { transform: scale(1.6); opacity: 0; }
}

.splash-orbit {
  position: absolute;
  inset: -20px;
}

.splash-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--particle-color, #0a84ff);
  top: 50%;
  left: 50%;
  animation: splash-orbit-spin var(--orbit-dur, 3s) linear infinite;
  animation-delay: var(--orbit-delay, 0s);
  transform-origin: 0 0;
  --start: var(--orbit-start, 0deg);
}

@keyframes splash-orbit-spin {
  from { transform: rotate(var(--start)) translateX(55px) rotate(calc(-1 * var(--start))); }
  to   { transform: rotate(calc(var(--start) + 360deg)) translateX(55px) rotate(calc(-1 * (var(--start) + 360deg))); }
}

.splash-title {
  font-size: 28px;
  font-weight: 800;
  color: #f5f5f7;
  letter-spacing: -0.5px;
  animation: splash-fade-up 0.6s ease-out 0.3s both;
}

.splash-tagline {
  font-size: 14px;
  color: rgba(245, 245, 247, 0.5);
  animation: splash-fade-up 0.6s ease-out 0.5s both;
}

@keyframes splash-fade-up {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.splash-cubes {
  display: flex;
  gap: 4px;
  align-items: flex-end;
  height: 32px;
  margin-top: 8px;
}

.splash-cube-bar {
  width: 6px;
  border-radius: 3px;
  background: linear-gradient(to top, #ff3b30, #ff9f0a, #30d158, #0a84ff);
  animation: splash-bar var(--bar-speed, 0.6s) ease-in-out var(--bar-delay, 0s) infinite alternate;
}

@keyframes splash-bar {
  from { height: 6px; }
  to   { height: 28px; }
}

/* ── Variables ────────────────────────────────────────────────────── */

:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f0f3;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #aeaeb2;
  --accent: #0071e3;
  --accent-light: #e3f0fc;
  --border: #d2d2d7;
  --border-light: #e8e8ed;
  --success: #34c759;
  --warning: #ff9f0a;
  --danger: #ff3b30;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --header-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-card: #2c2c2e;
  --bg-card-hover: #3a3a3c;
  --text: #f5f5f7;
  --text-secondary: #aeaeb2;
  --text-muted: #636366;
  --accent: #0a84ff;
  --accent-light: #0a84ff22;
  --border: #48484a;
  --border-light: #3a3a3c;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.logo-icon { font-size: 24px; }

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.nav-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover { background: var(--bg-secondary); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }

.header-controls {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover { background: var(--bg-secondary); color: var(--text); }

/* ── Toolbar ──────────────────────────────────────────────────────── */

.toolbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.chip {
  padding: 5px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.search-box input {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
  width: 200px;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus { border-color: var(--accent); }

/* ── Cases Grid ───────────────────────────────────────────────────── */

.cases-grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.case-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.case-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.case-card img {
  width: 100%;
  max-width: 140px;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.case-card .case-name {
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}

.case-card .case-group {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.case-card .case-alg {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  font-family: "SF Mono", "Fira Code", monospace;
  word-break: break-all;
  line-height: 1.4;
}

/* ── Detail View ──────────────────────────────────────────────────── */

.view { display: none; }
.view.active { display: block; }

.detail-back {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 0;
}

.back-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.back-btn:hover { background: var(--bg-secondary); color: var(--text); }

.detail-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 24px;
}

.detail-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.detail-cube-container {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.detail-cube-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 16px;
}

.detail-cube-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover { background: var(--bg-secondary); color: var(--text); }
.action-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.action-btn.primary:hover { opacity: 0.9; }

.detail-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.detail-header h2 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.detail-badge {
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
}

.detail-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.main-alg {
  font-size: 18px;
  font-weight: 600;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text);
  word-break: break-word;
  line-height: 1.6;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.copy-btn:hover { color: var(--text); }
.copy-btn.copied { background: var(--success); color: #fff; border-color: var(--success); }

.alt-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alt-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  color: var(--text-secondary);
  gap: 8px;
}

.alt-item:hover { background: var(--bg-card-hover); }

.alt-item .alg-text {
  flex: 1;
  word-break: break-word;
}

/* ── Solution Player Overlay ─────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden { display: none; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
}

.overlay-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  z-index: 1;
}

.overlay-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.overlay-close:hover { background: rgba(255,255,255,0.3); }

.overlay-title {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  font-weight: 500;
}

.player-container {
  width: min(90vw, 400px);
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}

.player-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
}

.player-controls {
  display: flex;
  gap: 12px;
}

.ctrl-btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.ctrl-btn:hover { background: rgba(255,255,255,0.2); }
.ctrl-btn.primary { background: var(--accent); }
.ctrl-btn.primary:hover { opacity: 0.9; }

/* ── Responsive ───────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .detail-container {
    grid-template-columns: 1fr;
  }

  .cases-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .search-box input { width: 140px; }

  .detail-cube-container { max-width: 280px; }
}

@media (max-width: 480px) {
  .cases-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .header-inner { gap: 8px; }
  .logo h1 { font-size: 15px; }
  .nav-btn { padding: 5px 12px; font-size: 13px; }
}

/* ── Footer ───────────────────────────────────────────────────────── */

.app-footer {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.app-footer .app-version {
  margin-top: 0.25rem;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

/* ── Locked Screen ────────────────────────────────────────────────── */

.locked-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 64px);
  padding: 2rem;
}

.locked-screen.hidden { display: none; }

.locked-content {
  text-align: center;
  max-width: 320px;
}

.locked-logo {
  opacity: 0.7;
  margin-bottom: 1rem;
}

.locked-content h2 {
  color: var(--text-primary);
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.locked-content p {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

.locked-content .auth-submit {
  width: auto;
  padding: 10px 32px;
}

/* ── Auth Modal ───────────────────────────────────────────────────── */

.auth-modal {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: min(90vw, 360px);
  box-shadow: var(--shadow-lg);
}

.auth-title {
  color: var(--text-primary);
  font-size: 1.25rem;
  margin: 0 0 20px;
  text-align: center;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active { background: var(--bg-card); color: var(--text); box-shadow: var(--shadow); }

.auth-field {
  margin-bottom: 14px;
}

.auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.auth-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-field input:focus { border-color: var(--accent); }

.auth-error {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 59, 48, 0.1);
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 14px;
}

.auth-error.hidden { display: none; }

.auth-submit {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.auth-submit:hover { opacity: 0.9; }
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Auth User Indicator ─────────────────────────────────────────── */

.user-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 16px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.user-indicator:hover { opacity: 0.8; }

.user-menu {
  position: absolute;
  top: calc(var(--header-height) - 4px);
  right: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 200;
  min-width: 140px;
}

.user-menu.hidden { display: none; }

.user-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.user-menu button:hover { background: var(--bg-secondary); }
.user-menu .menu-danger { color: var(--danger); }
