:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --surface: #1a1d26;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #2d3342;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, input, textarea { font-family: inherit; }
img { max-width: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Navbar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px max(20px, env(safe-area-inset-right, 0px)) 12px max(20px, env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 600;
}

/* Navbar Links / Tabs */
.nav-links {
  display: flex;
  gap: 16px;
  align-items: center;
}

.tab-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  cursor: pointer;
  font-weight: 500;
  padding: 4px 0;
  text-decoration: none;
}

.tab-link:hover, .tab-link.active {
  color: var(--primary);
}

.share-link {
  color: var(--primary);
  font-weight: 600;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.status-pill[data-state="busy"]  { color: var(--primary); border-color: var(--primary); }
.status-pill[data-state="rec"]   { color: #ef4444; border-color: #ef4444; }
.status-pill[data-state="done"]  { color: #16a34a; border-color: #16a34a; }
.status-pill[data-state="error"] { color: #ef4444; border-color: #ef4444; }

/* Animated Hamburger Button */
.hamburger-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  position: relative;
}

.hamburger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.hamburger-btn.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger-btn.active span:nth-child(2) {
  opacity: 0;
}
.hamburger-btn.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* App Layout */
.app-layout > * { min-width: 0; }

.app-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

.panel, .output-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.page-title {
  font-size: 1.15rem;
  margin: 0 0 4px;
}

.panel h2, .output-box h2 {
  font-size: 0.95rem;
  margin: 0;
}

.text-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  font-weight: 500;
}
.text-btn:hover {
  text-decoration: underline;
}

.hint {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.hint.note { margin: 12px 0 0; font-size: 0.75rem; }
.noscript { margin: 0; padding: 10px 16px; text-align: center; background: #fef3c7; color: #78350f; font-size: 0.85rem; }

textarea {
  width: 100%;
  min-height: 160px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
}

textarea:focus, input:focus {
  border-color: var(--primary);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
textarea:focus-visible, input:focus-visible { outline-offset: 0; }

.options-row {
  margin: 14px 0;
}

.field {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input[type="number"] {
  width: 60px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  text-align: center;
}

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

.btn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  text-align: center;
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.05s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.btn.outline {
  background: transparent;
  color: var(--text);
}

.btn.outline:hover {
  background: var(--bg);
}

/* FAQ Content Styles */
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}
.faq-item {
  margin-bottom: 12px;
}
.faq-item h3 {
  font-size: 0.88rem;
  margin: 0 0 2px;
}
.faq-item p {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0;
}

/* Viewer & Canvas Section */
.viewer-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.canvas-box, .output-box {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

canvas, video {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
}

.output-box {
  background: var(--surface);
  padding: 16px;
}

.download-btn {
  margin-top: 12px;
}

/* Mobile Hamburger Menu */
@media (max-width: 850px) {
  .hamburger-btn {
    display: flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    flex-direction: column;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  }

  .nav-links.open {
    display: flex;
    gap: 0;
    align-items: stretch;
    animation: fadeIn 0.3s ease;
  }

  .nav-links .tab-link {
    text-align: left;
    padding: 12px 4px;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
  }
  .nav-links .tab-link:last-child { border-bottom: none; }

  .app-layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}

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

/* Output actions */
.out-actions { margin-top: 12px; }
.out-actions .download-btn { margin-top: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* SEO description block + footer */
.about {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.about h2 { font-size: 1rem; margin: 0 0 8px; }
.about h3 { font-size: 0.9rem; margin: 14px 0 4px; }
.about p { font-size: 0.85rem; line-height: 1.55; color: var(--text-muted); margin: 0; }
.about strong { color: var(--text); font-weight: 600; }

.site-footer {
  text-align: center;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  font-size: 0.78rem;
  color: var(--text-muted);
}
.site-footer p { margin: 0; }

/* Toast message */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 420px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
