/* ============================================================
   GEARLOCK · CSS STYLES
   Knotrix-style modern HTML5 layout with embedded vector UI.
   Offline file:// compatible, zero external dependencies.
   ============================================================ */

:root {
  --bg-top: #2c3e50;
  --bg-bot: #1c2732;
  --panel: #243342;
  --panel-border: rgba(242, 232, 213, 0.12);
  --ink: #f2e8d5;
  --muted: #8fa3b0;
  --accent: #d9a441;
  --accent-light: #f4c568;
  --accent-dark: #b5832a;
  --tile: #2d3d4f;
  --tile-edge: #46586a;
  --shadow: 0 10px 30px rgba(10, 16, 24, 0.35);
  --gear: #8fa3b0;
  --gold: #e9c46a;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 50% 0%, var(--bg-top), var(--bg-bot));
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==================== PRELOADER ==================== */
#preloader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 25%, #2c3e50, #161e27);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: none !important;
}

.logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 22px;
}

.logo-gear {
  width: 105px;
  height: 105px;
  animation: floatGear 3s ease-in-out infinite;
}

@keyframes floatGear {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-8px) rotate(8deg);
  }
}

#preloader h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 2px;
  margin: 0 0 6px;
  color: var(--ink);
}

#preloader p {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.bar-track {
  width: 220px;
  height: 10px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--accent-light), var(--accent));
  transition: width 0.18s ease;
}

.preload-skip {
  margin-top: 18px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.2s ease;
}

.preload-skip:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
}

/* ==================== HEADER (TOP BAR) ==================== */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  z-index: 10;
  pointer-events: auto;
}

.top-group {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.91);
  background: rgba(70, 88, 106, 0.8);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

#levelLabel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 5px 16px;
  border-radius: 20px;
  transition: transform 0.15s ease, background 0.15s ease;
}

#levelLabel:active {
  transform: scale(0.94);
  background: rgba(70, 88, 106, 0.8);
}

.hud-title {
  font-size: 0.95rem;
  color: var(--ink);
  letter-spacing: 0.5px;
}

.hud-title span {
  color: var(--accent-light);
  font-weight: 800;
}

.hud-moves {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-dim);
}

.hud-moves b {
  color: var(--accent-light);
  font-weight: 700;
}

/* ==================== STAGE (CANVAS) ==================== */
#stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  touch-action: none;
}

/* ==================== BOTTOM BAR ==================== */
#bottombar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px 16px max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  pointer-events: auto;
}

.pill-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 50px;
  min-width: 50px;
  padding: 0 20px;
  border-radius: 25px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.pill-btn:active {
  transform: scale(0.93);
}

.pill-btn svg {
  width: 20px;
  height: 20px;
}

.pill-btn .badge {
  background: var(--accent);
  color: #1b2631;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 2px;
}

.pill-btn.primary {
  background: linear-gradient(135deg, #7fd47f, #5cb85c);
  color: #fff;
  border: none;
  box-shadow: 0 8px 24px rgba(92, 184, 92, 0.4);
}

.pill-btn.accent {
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  color: #1b2631;
  font-weight: 800;
  border: none;
  box-shadow: 0 8px 24px rgba(217, 164, 65, 0.4);
}

.pill-btn.accent svg {
  stroke: #1b2631;
}

.pill-btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ==================== MODALS & OVERLAYS ==================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(14, 20, 28, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: 16px;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 26px;
  padding: 28px 24px 22px;
  max-width: 390px;
  width: 100%;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(16px) scale(0.96);
  transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
  text-align: center;
  color: var(--ink);
}

.overlay.show .card {
  transform: translateY(0) scale(1);
}

.card h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 4px 0 6px;
  letter-spacing: 0.5px;
  color: var(--ink);
}

.card p.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  margin: 0 0 16px;
}

.card .cta {
  margin-top: 14px;
  width: 100%;
  border: none;
  height: 50px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  color: #1b2631;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(217, 164, 65, 0.35);
  transition: transform 0.15s ease;
}

.card .cta:active {
  transform: scale(0.96);
}

.menu-card {
  padding: 32px 26px 26px;
}

.menu-card .logo-wrap {
  margin-bottom: 14px;
}

.menu-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.menu-btns .menu-btn {
  width: 100%;
  justify-content: center;
  height: 52px;
  font-size: 1rem;
}

/* ==================== HOW TO PLAY ==================== */
.minilogo {
  margin-bottom: 6px;
}

.howto-row {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  margin: 14px 0;
}

.howto-row .ico {
  flex: 0 0 46px;
  height: 46px;
  border-radius: 14px;
  background: rgba(217, 164, 65, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-light);
}

.howto-row .ico svg {
  width: 24px;
  height: 24px;
}

.howto-row strong {
  display: block;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 2px;
  font-weight: 700;
}

.howto-row p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.35;
}

/* ==================== LEVEL SELECT GRID ==================== */
.levels-card {
  max-width: 410px;
}

.chapter-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.ch-tab {
  padding: 6px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--tile);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ch-tab.active {
  background: var(--accent);
  color: #1b2631;
  border-color: var(--accent);
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 10px 0 14px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
}

.level-tile {
  position: relative;
  aspect-ratio: 1/1;
  border-radius: 14px;
  border: 1px solid var(--tile-edge);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  background: var(--tile);
  color: var(--ink);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.level-tile:active {
  transform: scale(0.92);
}

.level-tile.completed {
  border-color: rgba(217, 164, 65, 0.5);
}

.level-tile.current {
  border-color: var(--accent-light);
  box-shadow: 0 0 14px rgba(217, 164, 65, 0.4);
}

.level-tile.locked {
  background: rgba(36, 48, 62, 0.4);
  color: #5a6d80;
  border-color: rgba(60, 75, 92, 0.3);
  cursor: not-allowed;
}

.level-tile.locked:active {
  transform: none;
}

.level-tile .tile-stars {
  display: flex;
  gap: 2px;
  margin-top: 3px;
}

.level-tile .tile-stars svg {
  width: 9px;
  height: 9px;
}

.level-tile .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1e2833;
  border: 1px solid #46586a;
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-tile .badge svg {
  width: 10px;
  height: 10px;
  stroke: #8fa3b0;
}

/* ==================== SETTINGS MODAL ==================== */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 18px;
  text-align: left;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--tile);
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  font-size: 0.95rem;
  font-weight: 600;
}

.toggle-btn {
  width: 48px;
  height: 26px;
  border-radius: 13px;
  background: #3d4f61;
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-btn .knob {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f2e8d5;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
  display: block;
}

.toggle-btn.active {
  background: var(--accent);
}

.toggle-btn.active .knob {
  transform: translateX(22px);
  background: #1b2631;
}

.danger-btn {
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(224, 92, 74, 0.2);
  border: 1px solid #e05c4a;
  color: #f28a7d;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.danger-btn:active {
  background: rgba(224, 92, 74, 0.4);
}

/* ==================== WIN OVERLAY ==================== */
.stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 14px;
}

.stars svg.star-icon {
  width: 36px;
  height: 36px;
  opacity: 0;
  transform: scale(0.2);
}

.stars svg.pop {
  animation: starPop 0.5s cubic-bezier(0.3, 1.6, 0.4, 1) forwards;
}

@keyframes starPop {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.win-meta {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 4px;
}

.win-btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.win-btns button {
  flex: 1;
}

/* ==================== CONFETTI & TOAST ==================== */
#confettiCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 105;
}

.toast {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(22, 32, 42, 0.95);
  backdrop-filter: blur(4px);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 10px 22px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 250;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== RESPONSIVE QUERIES ==================== */
@media (max-width: 440px) {
  #levelLabel {
    font-size: 0.95rem;
    padding: 6px 12px;
  }
  .pill-btn {
    padding: 0 16px;
    height: 48px;
    font-size: 0.9rem;
  }
  .card {
    padding: 24px 18px 20px;
  }
}
