/* ==========================================================================
   Screw Jam: Nuts & Bolts Puzzle - Master Stylesheet
   Pure CSS3, Zero External Dependencies, High-Contrast Tactile Workshop Theme
   ========================================================================== */

:root, [data-theme="slate"] {
  /* --- Iconic Workshop Slate-Blue Theme (High Contrast, Metallic & Crisp) --- */
  --bg-tabletop: radial-gradient(circle at 50% 18%, #24344d 0%, #162032 58%, #0c131f 100%);
  --bg-secondary: #162032;

  --board-bg: #111a29;
  --board-frame: linear-gradient(145deg, #283a56 0%, #192538 60%, #101826 100%);
  --board-border: #476491;
  --board-glow: rgba(56, 189, 248, 0.18);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-gold: #fbbf24;
  --card-bg: linear-gradient(145deg, #1e2d44 0%, #141f30 100%);
  --card-border: #385176;
}

[data-theme="timber"] {
  --bg-tabletop: radial-gradient(circle at 50% 18%, #472e1e 0%, #291a10 60%, #170e08 100%);
  --bg-secondary: #2e1d12;
  --board-bg: #1f130b;
  --board-frame: linear-gradient(145deg, #63402a 0%, #3d2517 60%, #26160d 100%);
  --board-border: #8c5d3e;
  --board-glow: rgba(245, 158, 11, 0.22);
  --text-main: #fffbeb;
  --text-muted: #deb896;
  --card-bg: linear-gradient(145deg, #422a1b 0%, #2b1a10 100%);
  --card-border: #734b32;
}

[data-theme="velvet"] {
  --bg-tabletop: radial-gradient(circle at 50% 18%, #281d28 0%, #171119 60%, #0d090f 100%);
  --bg-secondary: #1a131c;
  --board-bg: #140d16;
  --board-frame: linear-gradient(145deg, #3d263a 0%, #251623 60%, #170c16 100%);
  --board-border: #633c5a;
  --board-glow: rgba(234, 179, 8, 0.15);
  --text-main: #fffbeb;
  --text-muted: #c7a8bd;
}

:root {

  /* Screw & Toolbox Color System (Aesthetic Soft & Eye-Catching) */
  --color-yellow: #f59e0b;
  --color-yellow-light: #fef08a;
  --color-yellow-dark: #b45309;

  --color-red: #f43f5e;
  --color-red-light: #fecdd3;
  --color-red-dark: #9f1239;

  --color-blue: #0ea5e9;
  --color-blue-light: #bae6fd;
  --color-blue-dark: #0369a1;

  --color-green: #22c55e;
  --color-green-light: #bbf7d0;
  --color-green-dark: #15803d;

  --color-purple: #a855f7;
  --color-purple-light: #f3e8ff;
  --color-purple-dark: #6b21a8;

  --color-orange: #f97316;
  --color-orange-light: #ffedd5;
  --color-orange-dark: #9a3412;

}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html {
  font-size: 16px;
  background-color: #0d090f;
  background-image: var(--bg-tabletop);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  min-height: 100%;
  background-image: var(--bg-tabletop);
  background-attachment: fixed;
  overflow-x: hidden;
  touch-action: pan-y;
  line-height: 1.5;
}

/* Canvas Overlays */
#physicsCanvas, #confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* ==========================================================================
   First-Screen App Container (100vh Responsive)
   ========================================================================== */
.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px 14px;
  position: relative;
  box-sizing: border-box;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  gap: 10px;
  padding-bottom: 6px;
}

.header-left {
  display: flex;
  flex-direction: column;
}

.game-logo {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  background: linear-gradient(135deg, #fffbeb 0%, #fde68a 35%, #fbbf24 70%, #f59e0b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

.logo-sub {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-muted);
}

.level-indicator-box {
  display: flex;
  align-items: center;
}

.level-badge {
  background: linear-gradient(135deg, #b45309, #78350f);
  border: 1.5px solid #fbbf24;
  color: #fffbeb;
  padding: 5px 14px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.4);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.15);
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: var(--text-main);
  border-color: var(--accent-gold);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.93);
}

.svg-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* ==========================================================================
   Toolboxes Container (Active + Next Preview)
   ========================================================================== */
.toolboxes-container {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 16px;
  padding: 8px 12px;
  margin-bottom: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

.toolbox-header-title {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-align: center;
}

.toolboxes-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* Toolbox Card */
.toolbox-card {
  flex: 1;
  max-width: 170px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px;
  position: relative;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 1px 2px rgba(255, 255, 255, 0.4);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toolbox-card.active-box {
  transform: scale(1.02);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.2), inset 0 1px 2px rgba(255, 255, 255, 0.6);
}

.toolbox-card.next-box {
  opacity: 0.6;
  transform: scale(0.92);
}

.toolbox-color-tag {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.toolbox-slots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbox-slot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.toolbox-slot.filled {
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
  animation: slotSnapIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slotSnapIn {
  0% { transform: scale(0.4); }
  100% { transform: scale(1); }
}

.toolbox-card.completing {
  animation: boxRollAway 0.4s ease-in forwards;
}

@keyframes boxRollAway {
  0% { transform: scale(1) translateY(0); opacity: 1; }
  50% { transform: scale(1.1) translateY(-8px); filter: brightness(1.5); }
  100% { transform: scale(0.6) translateY(-40px); opacity: 0; }
}

/* ==========================================================================
   Main Board Viewport (Planks & Screws)
   ========================================================================== */
.board-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 0;
  position: relative;
}

.board-frame {
  width: min(88vw, 390px, 46vh);
  height: min(92vw, 420px, 52vh);
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border: 4px solid var(--board-border);
  outline: 1.5px solid rgba(0, 0, 0, 0.75);
  border-radius: 20px;
  box-shadow:
    0 20px 42px rgba(0, 0, 0, 0.75),
    0 0 20px var(--board-glow),
    inset 0 3px 8px rgba(0, 0, 0, 0.9);
  position: relative;
  overflow: hidden;
  touch-action: none;
}

/* Pegboard Background Grid Dots */
.pegboard-bg {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.08) 2px, transparent 2.5px);
  background-size: 24px 24px;
  background-position: 12px 12px;
  pointer-events: none;
}

/* Planks Container */
.planks-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Planks Styling */
.plank {
  position: absolute;
  border-radius: 24px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.65), inset 0 1.5px 2px rgba(255, 255, 255, 0.4);
  transition: transform 0.15s ease;
  pointer-events: none;
}

/* Plank Hole Sockets */
.plank-hole {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8), 0 1px 2px rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%);
}

/* Screws Container */
.screws-container {
  position: absolute;
  inset: 0;
}

/* 3D Interactive Screws */
.screw-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #e2e8f0 0%, #94a3b8 40%, #475569 100%);
  border: 2px solid #cbd5e1;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, filter 0.12s ease;
  z-index: 50;
  touch-action: manipulation;
}

.screw-btn:hover {
  transform: translate(-50%, -50%) scale(1.1);
  filter: brightness(1.15);
}

.screw-btn:active {
  transform: translate(-50%, -50%) scale(0.95);
}

/* Inner colored core */
.screw-core {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(255, 255, 255, 0.4);
}

/* Phillips Head Cross (+) in Chrome Steel */
.screw-cross {
  position: relative;
  width: 14px;
  height: 14px;
}

.screw-cross::before, .screw-cross::after {
  content: "";
  position: absolute;
  background: #1e293b;
  border-radius: 1px;
}

.screw-cross::before {
  left: 5px;
  top: 0;
  width: 4px;
  height: 14px;
}

.screw-cross::after {
  left: 0;
  top: 5px;
  width: 14px;
  height: 4px;
}

/* Screw Unscrewing Animation */
.screw-btn.unscrewing {
  animation: screwSpinPop 0.35s ease-out forwards;
  pointer-events: none;
  z-index: 999;
}

@keyframes screwSpinPop {
  0% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
  50% { transform: translate(-50%, -50%) rotate(360deg) scale(1.35); filter: brightness(1.4); }
  100% { transform: translate(-50%, -50%) rotate(720deg) scale(0.7); opacity: 0; }
}

/* Flying Screw Element */
.flying-screw {
  position: fixed;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.6));
  transform: translate(-50%, -50%);
  transition: all 0.38s cubic-bezier(0.25, 1, 0.5, 1);
}

/* ==========================================================================
   Bottom Staging Tray (5 Temporary Spare Holes)
   ========================================================================== */
.staging-container {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 18px;
  padding: 10px 14px;
  margin-top: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
}

.staging-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.staging-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.staging-counter {
  font-size: 0.78rem;
  font-weight: 900;
  color: #fffbeb;
}

.staging-slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.staging-slot {
  height: 48px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: border-color 0.15s ease;
}

.staging-slot.warning {
  border-color: #ef4444;
  animation: slotPulseRed 0.6s infinite alternate ease-in-out;
}

@keyframes slotPulseRed {
  0% { box-shadow: 0 0 4px rgba(239, 68, 68, 0.3); }
  100% { box-shadow: 0 0 12px rgba(239, 68, 68, 0.8); }
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 8, 14, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--card-bg);
  border: 2px solid var(--board-border);
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.8);
  transform: scale(0.9);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.modal-backdrop.show .modal-card {
  transform: scale(1);
}

.modal-icon {
  font-size: 3.2rem;
  margin-bottom: 4px;
}

.modal-title {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--text-main);
  margin-bottom: 4px;
}

.jam-title {
  color: #ef4444;
}

.modal-subtitle {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.btn-primary {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 50%, #b45309 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(234, 88, 12, 0.5), inset 0 1px 2px rgba(255, 255, 255, 0.4);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: scale(0.97);
}

/* ==========================================================================
   Below-the-Fold Crawlable SEO & FAQ Article
   ========================================================================== */
.seo-article-section {
  background: #140d16;
  border-top: 2px solid var(--board-border);
  padding: 48px 16px 64px;
}

.seo-container {
  max-width: 680px;
  margin: 0 auto;
}

.seo-badge {
  display: inline-block;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  border: 1px solid rgba(245, 158, 11, 0.35);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 5px 12px;
  border-radius: 9999px;
  margin-bottom: 12px;
}

.seo-main-title {
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1.25;
  color: var(--text-main);
  margin-bottom: 14px;
}

.seo-lead {
  font-size: 0.98rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 24px;
}

.seo-features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.seo-feature-card {
  background: #1e1520;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.seo-card-icon {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 6px;
}

.seo-feature-card h3 {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 4px;
}

.seo-feature-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.seo-sub-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 12px;
}

.seo-steps-list {
  padding-left: 20px;
  margin-bottom: 24px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.7;
}

.seo-steps-list strong {
  color: var(--text-main);
}

/* FAQ Accordions */
.faq-container {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.faq-accordion {
  background: #1e1520;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.faq-accordion[open] {
  border-color: var(--accent-gold);
}

.faq-question {
  padding: 14px 16px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: "+";
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent-gold);
  transition: transform 0.2s ease;
}

.faq-accordion[open] .faq-question::after {
  transform: rotate(45deg);
}

.faq-answer {
  padding: 0 16px 14px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Metadata Specs Table */
.seo-specs-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  background: #1e1520;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--card-border);
}

.seo-specs-table th, .seo-specs-table td {
  padding: 10px 14px;
  font-size: 0.85rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.seo-specs-table th {
  color: var(--text-muted);
  font-weight: 700;
  width: 35%;
}

.seo-specs-table td {
  color: var(--text-main);
  font-weight: 700;
}

.seo-footer {
  margin-top: 36px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}


/* Level Badge Interactive Cursor */
.level-indicator-box {
  cursor: pointer;
  transition: transform 0.12s ease;
}
.level-indicator-box:hover {
  transform: scale(1.05);
}

/* Screw Booster Bar */
.screw-booster-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.screw-booster-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid var(--card-border);
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.screw-booster-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent-gold);
  background: rgba(255, 255, 255, 0.11);
}

.screw-booster-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.screw-booster-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.booster-pill {
  background: rgba(251, 191, 36, 0.22);
  color: var(--accent-gold);
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 900;
}

.screw-btn.hint-glow {
  animation: screwHintPulse 0.75s infinite alternate ease-in-out;
  z-index: 50 !important;
}

@keyframes screwHintPulse {
  0% { transform: translate(-50%, -50%) scale(1); filter: drop-shadow(0 0 4px #facc15); }
  100% { transform: translate(-50%, -50%) scale(1.22); filter: drop-shadow(0 0 16px #facc15); }
}
