*, *::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: #7f1d1d;
}

/* ---- 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);
}

/* ---- GRID ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  padding: 12px;
  padding-top: 40px;
  width: 100%;
  height: 100%;
}

.tile {
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.tile:active {
  transform: scale(0.93);
}

.tile .emoji {
  font-size: clamp(4rem, 18vw, 10rem);
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* shimmer effect */
.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}

/* ---- OVERLAY / POPUP ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

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

.overlay canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.close-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 110;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.7) url('assets/back.png') no-repeat center;
  background-size: 50%;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:active {
  background: rgba(255,255,255,0.4);
}

/* ---- 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;
}

/* ---- 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: #7f1d1d;
  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: #1a1a1a;
}

.analytics-table td:first-child {
  font-size: 20px;
}

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

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

.setting-item input[type="number"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #555;
  background: #1a1a1a;
  color: #fff;
  font-size: 16px;
}

.setting-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.setting-toggle label {
  margin-bottom: 0;
}

.toggle-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: #555;
  color: #aaa;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toggle-btn.active {
  background: #2e7d32;
  color: #fff;
}

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

.settings-btn:active {
  background: #991d1d;
}

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

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

/* safe-area for notch devices */
@supports (padding-top: env(safe-area-inset-top)) {
  .grid { 
    padding: max(40px, calc(env(safe-area-inset-top) + 40px)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); 
  }
  .close-btn { top: max(16px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); }
  .logo-container { top: max(12px, env(safe-area-inset-top)); }
}
