:root {
  --bg: #111418;
  --panel: #1a1f26;
  --panel-2: #222933;
  --text: #f2f5f7;
  --muted: #b6c0ca;
  --accent: #2fbf71;
  --danger: #d14f45;
  --border: #313a46;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #1b2230 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 16px 14px 28px;
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.viewer {
  position: relative;
  margin-top: 14px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0a0c10;
  aspect-ratio: 4 / 3;
}

.media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

#cameraVideo.active,
#resultCanvas.active {
  display: block;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 16px;
  font-size: 0.95rem;
}

.placeholder.hidden {
  display: none;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 10px;
  align-content: center;
  background: rgba(10, 12, 16, 0.6);
  backdrop-filter: blur(2px);
}

.loading.hidden {
  display: none;
}

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

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

.resultPanel {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.resultPanel p {
  margin: 0;
}

.resultPanel .status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  word-break: break-word;
}

.controls {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

button {
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: #07140d;
  border-color: transparent;
}

button.danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.notes {
  margin-top: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
  padding: 10px 12px;
}

.notes summary {
  cursor: pointer;
  color: var(--muted);
}

.notes ul {
  margin: 10px 0 0 18px;
  padding: 0;
  color: var(--muted);
}

.hiddenCanvas {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
}

@media (max-width: 480px) {
  .controls {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}
