*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e;
}

/* ---- LOGO ---- */
.logo-container {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: all;
}

.logo {
  width: 90px;
  height: auto;
  display: block;
  cursor: pointer;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
  transition: transform 0.1s ease;
}

.logo:active {
  transform: scale(0.9);
}

/* ---- SETTINGS MODAL ---- */
.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.settings-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.settings-content {
  background: #2d2d2d;
  border-radius: 20px;
  padding: 30px;
  max-width: 90%;
  width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.settings-content h2 {
  color: #fff;
  margin-bottom: 20px;
  font-size: 24px;
  text-align: center;
}

.setting-item {
  margin-bottom: 20px;
}

.setting-item label {
  display: block;
  color: #ddd;
  margin-bottom: 8px;
  font-size: 14px;
}

.setting-item input[type="range"] {
  width: 100%;
  accent-color: #6c63ff;
}

.range-value {
  display: block;
  text-align: right;
  color: #aaa;
  font-size: 13px;
  margin-top: 4px;
}

.settings-btn {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  border: none;
  border-radius: 8px;
  background: #1a1a2e;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s ease;
}

.settings-btn:active {
  background: #2a2a4e;
}

.settings-btn-secondary {
  background: #444;
}

.settings-btn-secondary:active {
  background: #555;
}

/* ---- SETTINGS TABS ---- */
.settings-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}

.settings-tab {
  flex: 1;
  padding: 10px 6px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: #444;
  color: #aaa;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.settings-tab.active {
  background: #1a1a2e;
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---- ANALYTICS TABLE ---- */
.analytics-table-wrap {
  overflow-x: auto;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.analytics-table th,
.analytics-table td {
  padding: 8px 6px;
  text-align: center;
  color: #ddd;
  border-bottom: 1px solid #444;
}

.analytics-table th {
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
  background: #0a0a1e;
}

.analytics-table td:first-child {
  text-align: left;
  font-size: 13px;
  word-break: break-word;
}

/* ---- GAME CONTAINER ---- */
.game {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ---- BACKGROUND IMAGE ---- */
.puzzle-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 1;
}

/* ---- SCRATCH CANVAS ---- */
.scratch-canvas {
  position: absolute;
  inset: 0;
  z-index: 10;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  transition: opacity 0.8s ease;
}

.scratch-canvas.scratch-done {
  opacity: 0;
  pointer-events: none;
}

/* ---- REFRESH BUTTON (top-left, like redcars back button) ---- */
.refresh-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 50;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 40px;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.refresh-btn:active {
  transform: scale(0.9) rotate(180deg);
}

/* ---- WIN OVERLAY ---- */
.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}

.win-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---- safe-area for notch devices ---- */
@supports (padding-top: env(safe-area-inset-top)) {
  .refresh-btn {
    top: max(16px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
  }
  .logo-container {
    top: max(0px, env(safe-area-inset-top));
  }
}
