:root {
  --bg: #07080d;
  --panel: #12141d;
  --line: #242838;
  --text: #e9ecf5;
  --muted: #99a0b5;
  --accent: #4cc2ff;
  --ok: #46d39a;
  --warn: #ffb454;
  --err: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 0.5px;
}

.topbar h1 span {
  color: var(--accent);
}

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.chip[data-state='ready'] {
  color: var(--ok);
  border-color: rgba(70, 211, 154, 0.4);
}

.chip[data-state='error'] {
  color: var(--err);
  border-color: rgba(255, 107, 107, 0.4);
}

.progress {
  padding: 12px 18px;
}

.progress .bar {
  height: 6px;
  border-radius: 3px;
  background: var(--panel);
  overflow: hidden;
}

.progress .bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.progress p {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 18px 0;
}

.tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  background: var(--panel);
  color: var(--text);
}

main {
  padding: 0 18px 32px;
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0 12px 12px 12px;
  padding: 18px;
}

.panel.active {
  display: block;
}

.dropzone {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
}

.dropzone.hover {
  border-color: var(--accent);
}

.dropzone span {
  color: var(--muted);
  font-size: 13px;
}

.modes {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.modes legend {
  color: var(--muted);
  font-size: 12px;
  padding: 0 6px;
}

.modes label {
  display: block;
  padding: 4px 0;
}

.modes label.inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.modes select,
.text-send textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #10121a;
  color: var(--text);
  font: inherit;
}

.text-send {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.text-send summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.text-send textarea {
  margin: 10px 0;
  resize: vertical;
}

.frame-counter {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.frame-counter:empty {
  display: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

button,
.button {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

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

button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05202c;
  font-weight: 600;
}

.file-button {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
}

.status {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}

.status[data-tone='ok'] {
  color: var(--ok);
}

.status[data-tone='warn'] {
  color: var(--warn);
}

.status[data-tone='err'] {
  color: var(--err);
}

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 14px 0 0;
  font-size: 13px;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.preview {
  margin-top: 16px;
  width: min(100%, 420px);
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  image-rendering: pixelated;
}

.camera-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
  aspect-ratio: 4 / 3;
  margin-bottom: 14px;
}

.camera-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-hint {
  position: absolute;
  inset: auto 0 0 0;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.55);
}

.result {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.result h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.result p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.result img {
  max-width: 100%;
  border-radius: 10px;
  margin-bottom: 12px;
}

.result pre {
  max-height: 200px;
  overflow: auto;
  background: #0b0d15;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

[hidden] {
  display: none !important;
}

.fullscreen {
  position: fixed;
  inset: 0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.fullscreen canvas {
  max-width: 100vmin;
  max-height: 100vmin;
  image-rendering: pixelated;
}

#close-fullscreen {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-color: transparent;
}

@media (min-width: 720px) {
  main {
    max-width: 860px;
    margin: 0 auto;
  }

  .tabs {
    max-width: 860px;
    margin: 0 auto;
  }
}

.credit {
  margin: 28px 0 8px;
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.6;
}

.credit a {
  color: inherit;
}
