:root {
  --background: #121212;
  --surface: #1a1a1a;
  --surface-variant: rgba(18, 18, 18, 0.9);
  --on-surface: #e0e0e0;
  --on-surface-variant: #b0b0b0;
  --primary: #00f6ff;
  --primary-hover: #7fffff;
  --on-primary: #121212;
  --popup-shadow: rgba(0, 246, 255, 0.4);
  --error-shadow: rgba(255, 82, 82, 0.4);
  --shadow-primary: rgba(0, 246, 255, 0.2);
}

.light-theme {
  --background: #fffbfe;
  --surface: #f8f9ff;
  --surface-variant: rgba(255, 255, 255, 0.95);
  --on-surface: #1c1b1f;
  --on-surface-variant: #49454e;
  --primary: #6750a4;
  --primary-hover: #825ab6;
  --on-primary: #ffffff;
  --popup-shadow: rgba(103, 80, 164, 0.4);
  --shadow-primary: rgba(103, 80, 164, 0.2);
}

.high-contrast canvas,
.high-contrast .ui {
  filter: contrast(1.4);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--background);
  font-family: 'Inter', sans-serif;
  display: flex; justify-content: center; align-items: center;
  color: var(--on-surface);
}

canvas {
  display: block;
  border-radius: 24px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 0 20px var(--shadow-primary);
  background: var(--surface);
  max-width: calc(100% - 40px); max-height: calc(100% - 40px);
}

.ui {
  position: fixed;
  top: 16px; right: 16px; left: auto;
  background: var(--surface-variant);
  padding: 12px 16px;
  border-radius: 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 0 12px var(--shadow-primary);
  touch-action: manipulation;
  transition: transform 0.2s ease;
}

.ui:hover { transform: scale(1.05); }

.ui button {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s ease;
}

.ui button:hover { color: var(--primary-hover); }

.status {
  font-size: clamp(0.8rem, 3vw, 1rem);
  color: var(--on-surface-variant);
}

.tilt-indicator {
  position: fixed;
  bottom: 16px;
  left: 16px;
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: var(--surface-variant);
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.tilt-dot {
  width: 12px;
  height: 12px;
  border-radius: 6px;
  background: var(--primary);
  position: absolute;
  transition: transform 0.1s ease-out, background-color 0.3s ease;
}

.watermark {
  position: absolute;
  bottom: 8px; right: 8px;
  color: rgba(255,255,255,0.05);
  font-size: 4rem;
  font-weight: 600;
  user-select: none;
  pointer-events: none;
}

.light-theme .watermark {
  color: rgba(0,0,0,0.05);
}

#popup {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface-variant);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 0 20px var(--popup-shadow);
  text-align: center;
  display: none;
  z-index: 999;
  color: var(--on-surface);
}

#popup button {
  margin-top: 16px;
  padding: 8px 16px;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  color: var(--on-primary);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

#popup button:hover { background: var(--primary-hover); }

#warning, #permission {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface-variant);
  border-radius: 24px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 0 20px var(--error-shadow);
  display: none;
  z-index: 1000;
  color: var(--on-surface);
}

#permission button {
  margin: 8px;
  padding: 8px 16px;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  color: var(--on-primary);
  font-weight: 600;
  cursor: pointer;
}

#permission button:hover { background: var(--primary-hover); }

@media (max-width: 600px) {
  .tilt-indicator {
    width: 50px;
    height: 50px;
    bottom: 8px;
    left: 8px;
  }
}