:root {
  --bg: #0d0d0d;
  --fg: #f0f0f0;
  --fg-light: #999;
  --border: #2a2a2a;
  --border-dark: #444;
  --surface: #1a1a1a;
  --accent: #ffffff;
  --accent-hover: #e0e0e0;
  --blue: #2b6ef2;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
}

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

html, body {
  height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  padding: 32px 24px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, #1a1a1a, #121212);
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo {
  width: 32px;
  height: 32px;
}

.brand {
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.5px;
  margin-bottom: 0;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

.sub {
  color: var(--fg-light);
  font-size: 15px;
  font-weight: 400;
}

.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
  display: grid;
  grid-template-columns: 1fr 480px;
  gap: 32px;
  align-items: start;
}

.editor-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ai-menu-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  box-shadow: var(--shadow);
}

.ai-menu-bar::-webkit-scrollbar {
  display: none; /* Safari and Chrome */
}

.ai-menu-bar .btn {
  flex-shrink: 0;
  padding: 8px 16px;
  font-size: 14px;
}

.ai-top-bar {
  display: none; /* Hide old AI tools bar */
}

.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: floatUp 2s ease-in-out infinite;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--fg-light);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes floatUp {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes floatSubtle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.canvas-container {
  position: relative;
  border: 1px solid var(--border-dark);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.canvas-container:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--blue);
}

#editorCanvas {
  width: 100%;
  height: auto;
  display: block;
  transition: opacity 0.3s ease;
}

.hint {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  font-size: 13px;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.hint.hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.hint-close {
  flex-shrink: 0;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg-light);
  padding: 4px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.hint-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  animation: floatSubtle 3s ease-in-out infinite;
  animation-delay: 0.5s;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.controls-panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-light);
}

.file-input input {
  display: none;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-dark);
  background: var(--surface);
  color: var(--fg);
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  white-space: nowrap;
}

.btn:hover {
  background: var(--border);
  border-color: var(--border-dark);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
  transition: all 0.1s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--bg);
}

.btn:hover:not(.btn-primary) {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-icon {
  padding: 10px;
  width: 44px;
  height: 44px;
}

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

.zoom-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zoom-control input {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-dark);
  outline: none;
  -webkit-appearance: none;
}

.zoom-control input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
}

.zoom-control input::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
}

.zoom-value {
  font-size: 13px;
  color: var(--fg-light);
  text-align: right;
}

.answer-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 32px;
}

.prompt-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.prompt-input {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border: 1px solid var(--border-dark);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  background: var(--surface);
  color: var(--fg);
  transition: all 0.3s ease;
}

.prompt-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 110, 242, 0.2);
}

.btn-ask {
  min-width: 140px;
}

.ai-toolbar {
  display: none;
}

.status {
  font-size: 14px;
  color: var(--fg-light);
  padding: 8px 0;
  min-height: 30px;
}

.answer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  animation: float 4s ease-in-out infinite;
  animation-delay: 1s;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.answer-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(43, 110, 242, 0.1);
  border-color: var(--blue);
}

.answer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.1);
}

.answer-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.answer-box {
  padding: 24px;
  min-height: 300px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--fg-light);
  font-size: 15px;
  transition: color 0.3s ease;
}

.camera-wrap {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(0, 0, 0, 0.95);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.camera-wrap.open {
  display: flex;
}

.camera-modal {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.btn-flip {
  position: absolute;
  bottom: 40px;
  right: calc(50% - 72px / 2 - 50px);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--accent);
  cursor: pointer;
  display: none; /* Hidden by default, shown on mobile */
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-flip:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-capture {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--bg);
  background: var(--accent);
  color: var(--accent);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-capture:active {
  transform: translateX(-50%) scale(0.95);
}

.btn-close {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.mobile-toolbar {
  display: none;
}

.desktop-only {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (max-width: 1200px) {
  .app-main {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 24px 16px;
  }

  .answer-section {
    position: static;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 24px 16px 16px;
  }

  .brand {
    font-size: 22px;
  }

  .sub {
    font-size: 14px;
  }

  .app-main {
    padding: 16px 12px;
    padding-bottom: 100px; /* Space for mobile toolbar */
    gap: 16px;
  }

  .hint {
    font-size: 12px;
    padding: 10px 12px;
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .controls-panel {
    padding: 16px;
    gap: 16px;
  }

  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
    padding: 8px;
  }

  .btn-group {
    gap: 6px;
  }

  .prompt-bar {
    gap: 8px;
  }

  .prompt-input {
    padding: 10px 14px;
    font-size: 14px;
    min-width: 100%;
  }

  .btn-ask {
    width: 100%;
  }

  .ai-menu-bar {
    display: none;
  }

  .ai-top-bar {
    display: none;
  }

  .desktop-only {
    display: none;
  }

  .mobile-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    z-index: 100;
  }
  
  .mobile-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--fg-light);
    background: transparent;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    flex: 1;
    transition: background 0.2s ease, color 0.2s ease;
  }

  .mobile-btn:hover {
    background: var(--border);
  }

  .mobile-btn.primary {
    color: var(--accent);
    font-weight: 600;
  }

  .mobile-btn svg {
    width: 24px;
    height: 24px;
  }

  .answer-card {
    border-radius: 12px;
  }

  .answer-header {
    padding: 16px;
  }

  .answer-header h2 {
    font-size: 16px;
  }

  .answer-box {
    padding: 16px;
    min-height: 200px;
    font-size: 14px;
  }

  .btn-flip {
    display: flex; /* Show on mobile */
  }

  .btn-capture {
    bottom: 32px;
    width: 64px;
    height: 64px;
  }

  .btn-flip {
    bottom: 32px;
    right: calc(50% - 64px / 2 - 40px);
    width: 44px;
    height: 44px;
  }

  .btn-close {
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
  }

  .control-group {
    gap: 10px;
  }

  .group-label {
    font-size: 12px;
  }
}