* {
  touch-action: manipulation;
}

html, body {
  touch-action: manipulation;
  -ms-touch-action: manipulation;
  overscroll-behavior: none;
}

:root {
  --primary: #e90707;
  --primary-hover: #ff1a1a;
  --primary-glow: rgba(233, 7, 7, 0.4);
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #141414;
  --bg-elevated: #1c1c1e;
  --bg-glass: rgba(28, 28, 30, 0.72);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-tertiary: rgba(255, 255, 255, 0.4);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== ROOM STYLES ===== */
#room-page {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 1;
}

#canvas-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: grab;
}

#canvas-container.dragging-sticker { cursor: grabbing; }

#draw-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.6s var(--transition-smooth);
  padding: 20px;
  box-sizing: border-box;
}

#draw-screen > * {
  max-width: 85%;
}

#draw-screen.hidden { opacity: 0; pointer-events: none; }

.prompt-text {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 32px;
  letter-spacing: -0.01em;
  color: var(--text-secondary);
}

#draw-canvas {
  background: var(--bg-primary);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-lg);
  cursor: crosshair;
  touch-action: none;
  width: 100%;
  max-width: 450px;
  aspect-ratio: 1;
  image-rendering: pixelated;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.draw-controls { 
  display: flex; 
  gap: 12px; 
  margin-top: 32px; 
}

.draw-btn {
  padding: 14px 36px;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: -0.01em;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}

.draw-btn:hover { 
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: scale(1.02);
}

.draw-btn:active {
  transform: scale(0.98);
}

#fed-count {
  position: fixed;
  bottom: 24px;
  right: 24px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  z-index: 100;
  padding: 10px 18px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

#drag-preview {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.9;
  display: none;
}

#drag-preview img {
  width: 70px;
  height: 70px;
  object-fit: cover;
  border: 2px solid var(--text-primary);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#speech-ui {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  background: #000;
  border: 1px solid #fff;
  padding: 8px 16px;
  font-size: 14px;
  letter-spacing: 1px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  transform: translate(-50%, -100%);
}

#speech-ui.show { opacity: 1; }

#speech-ui::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #fff;
}

#click-hint {
  position: fixed;
  pointer-events: auto;
  cursor: pointer;
  z-index: 210;
  display: none;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-primary);
  transform: translate(-50%, 0);
  animation: pulse 1.5s ease-in-out infinite;
  padding: 10px 24px;
  background: var(--primary);
  border-radius: var(--radius-full);
}

#click-hint:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 20px var(--primary-glow);
}

#click-hint:active {
  transform: translate(-50%, 0) scale(0.95);
}

#click-hint.show { display: block; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

#artwork-modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.3s;
}

#artwork-modal.show { display: flex; opacity: 1; }

#artwork-modal img {
  max-width: 280px;
  max-height: 280px;
  object-fit: contain;
  border-radius: var(--radius-lg);
  margin-bottom: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#artwork-info { 
  text-align: center; 
  max-width: 320px; 
  padding: 0 24px; 
}

#artwork-title { 
  font-size: 1.25rem; 
  font-weight: 600;
  letter-spacing: -0.02em; 
  margin-bottom: 12px; 
}

#artwork-desc { 
  font-size: 0.875rem; 
  line-height: 1.7; 
  color: var(--text-secondary);
  margin-bottom: 32px; 
}

.modal-btns { 
  display: flex; 
  gap: 12px; 
  justify-content: center; 
}

.modal-btn {
  padding: 14px 28px;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: -0.01em;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}

.modal-btn:hover { 
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: scale(1.02);
}

.modal-btn:active {
  transform: scale(0.98);
}

.modal-btn.feed-btn { 
  background: var(--primary);
  color: var(--text-primary);
}

.modal-btn.feed-btn:hover { 
  background: var(--primary-hover);
  box-shadow: 0 0 24px var(--primary-glow);
}

#white-fade {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--text-primary);
  z-index: 2500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.5s;
}

#white-fade.show { opacity: 1; pointer-events: all; }

/* ===== GLITCH ART STYLES ===== */
#glitch-page {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 3000;
  display: none;
  background: var(--bg-secondary);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  justify-content: center;
  align-items: center;
  padding: 24px;
  -webkit-user-select: none;
  user-select: none;
  overflow-y: auto;
}

#glitch-page::before {
  content: '';
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 180px;
  background: linear-gradient(to bottom, rgba(233, 7, 7, 0.12), transparent);
  pointer-events: none;
  z-index: 0;
}

.glitch-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 12px;
  text-shadow: 0 0 20px var(--primary-glow), 0 0 40px rgba(233, 7, 7, 0.15);
}

#glitch-page.show { display: flex; }

#glitch-page #app {
  width: 100%;
  max-width: 100vw;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#glitch-page #gameView {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#glitch-page .message {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

#glitch-page .message-sub {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-tertiary);
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

#glitch-page .progress-wrap {
  width: 100%;
  margin-bottom: 24px;
  padding: 20px 24px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

#glitch-page .progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

#glitch-page .progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

#glitch-page .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  width: 0%;
  transition: width 0.3s;
  border-radius: var(--radius-full);
}

#glitch-page .canvas-container {
  position: relative;
  width: 100%;
  max-width: min(75vw, 75vh);
  aspect-ratio: 1;
  margin-bottom: 28px;
}

#glitch-page .canvas-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-xl);
  touch-action: none;
  box-shadow: 0 0 0 1px rgba(233, 7, 7, 0.3), 0 0 30px rgba(233, 7, 7, 0.15), 0 20px 60px rgba(0, 0, 0, 0.5);
}

#glitch-page #glitchDrawCanvas {
  background: #fff;
  z-index: 1;
}

#glitch-page #displayCanvas {
  z-index: 2;
  pointer-events: none;
}

#glitch-page .logo-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30%;
  height: 30%;
  opacity: 0.06;
  z-index: 0;
  pointer-events: none;
}

#glitch-page .controls {
  width: 100%;
  max-width: min(75vw, 75vh);
}

#glitch-page .btn-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
}

#glitch-page .btn {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: -0.01em;
}

#glitch-page .btn-tool {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
}

#glitch-page .btn-tool:hover {
  color: var(--text-secondary);
}

#glitch-page .btn-tool.active {
  background: var(--primary);
  color: var(--text-primary);
  box-shadow: 0 2px 12px var(--primary-glow);
}

#glitch-page .size-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  color: var(--text-tertiary);
  font-size: 0.8rem;
  font-weight: 500;
}

#glitch-page .size-wrap input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  outline: none;
}

#glitch-page .size-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#glitch-page .size-wrap input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

#glitch-page .size-preview {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
}

#glitch-page .size-preview::after {
  content: '';
  background: var(--bg-primary);
  border-radius: 50%;
}

#glitch-page .btn-row {
  display: flex;
  gap: 12px;
}

#glitch-page .btn-primary {
  flex: 1;
  padding: 16px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: -0.01em;
}

#glitch-page .btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--primary-glow);
}

#glitch-page .btn-primary:active {
  transform: translateY(0);
}

#glitch-page .btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#glitch-page .btn-secondary {
  flex: 1;
  padding: 16px;
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: -0.01em;
}

#glitch-page .btn-secondary:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#glitch-page .btn-fix {
  width: 100%;
  padding: 24px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-size: 1.125rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: -0.02em;
  transition: all var(--transition-fast);
}

#glitch-page .btn-fix:hover {
  background: var(--primary-hover);
  transform: scale(1.02);
  box-shadow: 0 12px 32px var(--primary-glow);
}

#glitch-page .btn-fix:active {
  transform: scale(0.98);
}

#glitch-page .card-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

#glitch-page .card-wrap {
  width: 100%;
  max-width: min(90vw, 380px);
}

#glitch-page .card-wrap canvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#glitch-page .card-buttons {
  justify-content: center;
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: min(90vw, 380px);
}

.save-modal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.save-modal.show {
  display: flex;
}

.save-modal-content {
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.save-modal-hint {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 16px;
  text-align: center;
}

.save-modal-content img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#glitch-page .hidden { display: none !important; }

/* ===== NAV MENU ===== */
#nav-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 9000;
  width: 40px;
  height: 40px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  transition: all var(--transition-fast);
}

#nav-toggle:hover {
  background: var(--bg-elevated);
  border-color: var(--border-medium);
}

#nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 1px;
  transition: all 0.3s;
}

#nav-toggle.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

#nav-toggle.open span:nth-child(2) {
  opacity: 0;
}

#nav-toggle.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

#nav-menu {
  position: fixed;
  top: 64px;
  left: 16px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#nav-menu.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary);
  color: var(--text-primary);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-full);
}
