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

:root {
  --bg: #0a0a0a;
  --bg1: #111111;
  --bg2: #1a1a1a;
  --bg3: #222222;
  --border: #252525;
  --border2: #303030;
  --fg: #e2e8f0;
  --fg2: #94a3b8;
  --fg3: #94a3b8;
  --green: #22c55e;
  --green-dk: #15803d;
  --green-gl: #00ff41;
  --red: #ef4444;
}

html {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ── Header ───────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 0 90px; /* left: clear compact back button on all viewports */
  height: 52px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-title {
  margin: 0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.08em;
  white-space: nowrap;
  text-shadow: 0 0 12px rgba(34, 197, 94, 0.5);
  user-select: none;
}

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 18px;
  border: 1px solid var(--border2);
  border-radius: 6px;
  background: var(--bg2);
  color: var(--fg2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  min-height: 44px;
  min-width: 80px;
}

.tab-btn:hover:not(.active) {
  border-color: var(--green);
  color: var(--fg);
}

.tab-btn.active {
  background: var(--green-dk);
  border-color: var(--green);
  color: #fff;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.2);
}

/* ── Canvas area ──────────────────────────── */
#canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  transition: outline 0.12s;
}

#canvas-wrap.drag-over {
  outline: 2px dashed var(--green);
  outline-offset: -3px;
}

#ascii-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}
#ascii-canvas.mirrored {
  transform: scaleX(-1);
}

#tom-pip {
  position: absolute;
  bottom: 52px;
  right: 10px;
  width: clamp(140px, 22vw, 200px);
  aspect-ratio: 16/9;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(167, 139, 250, 0.4);
  display: none;
  z-index: 9;
  transition: opacity 0.3s;
}
#tom-pip iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}
#tom-pip-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  padding: 3px 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent);
  pointer-events: none;
  letter-spacing: 0.05em;
}

#btn-fullscreen {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
  padding: 0;
}
#canvas-wrap:hover #btn-fullscreen,
#canvas-wrap:focus-within #btn-fullscreen {
  opacity: 1;
}
#btn-fullscreen:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  opacity: 1;
}

/* Fullscreen state */
#canvas-wrap:fullscreen,
#canvas-wrap:-webkit-full-screen {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#canvas-wrap:fullscreen #ascii-canvas,
#canvas-wrap:-webkit-full-screen #ascii-canvas {
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
}
#canvas-wrap:fullscreen #btn-fullscreen,
#canvas-wrap:-webkit-full-screen #btn-fullscreen {
  opacity: 1;
}

#video-feed {
  display: none;
}

/* ── Overlay ──────────────────────────────── */
#overlay-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
}

.drop-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 44px 52px;
  border: 2px dashed var(--border2);
  border-radius: 14px;
  text-align: center;
  max-width: 340px;
}

.drop-icon {
  font-size: 52px;
  line-height: 1;
  filter: drop-shadow(0 0 16px rgba(34, 197, 94, 0.35));
}

.drop-hint p {
  color: var(--fg2);
  font-size: 15px;
  line-height: 1.5;
}
.drop-hint .drop-sub {
  font-size: 12px;
  color: var(--fg3);
  margin-top: -6px;
}

/* ── Controls ─────────────────────────────── */
.controls-panel {
  flex-shrink: 0;
  background: var(--bg1);
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
  overflow-y: auto;
  max-height: 200px;
}

.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
  margin-bottom: 10px;
}

.ctrl-row:last-child {
  margin-bottom: 0;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-label {
  color: var(--fg3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.ctrl-val {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: var(--green);
  min-width: 30px;
  text-align: right;
}

select {
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border2);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  height: 30px;
  outline: none;
}

select:focus {
  border-color: var(--green);
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--green);
  cursor: pointer;
  box-shadow: 0 0 5px rgba(34, 197, 94, 0.4);
}

input[type='range']::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--green);
  cursor: pointer;
  border: none;
}

input[type='text'] {
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border2);
  border-radius: 5px;
  padding: 4px 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  width: 150px;
  height: 30px;
  outline: none;
}

input[type='text']:focus {
  border-color: var(--green);
}

/* ── Buttons ──────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: 1px solid var(--border2);
  border-radius: 6px;
  background: var(--bg2);
  color: var(--fg2);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  min-height: 44px;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--green);
  color: var(--fg);
}

.btn-primary {
  background: var(--green-dk);
  border-color: var(--green);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 26px;
  min-height: 44px;
}

.btn-primary:hover {
  background: var(--green);
  color: #000;
}

.btn-danger {
  border-color: #7f1d1d;
  color: #fca5a5;
}
.btn-danger:hover {
  border-color: var(--red);
  color: var(--red);
}
.btn-tom {
  border-color: #5b21b6;
  color: #c4b5fd;
}
.btn-tom:hover {
  border-color: #a78bfa;
  color: #a78bfa;
}
.btn-tom.active {
  background: #5b21b6;
  color: #fff;
  border-color: #a78bfa;
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.5);
  animation: tomPulse 0.35s ease infinite alternate;
}
@keyframes tomPulse {
  from {
    box-shadow: 0 0 6px rgba(167, 139, 250, 0.3);
  }
  to {
    box-shadow: 0 0 18px rgba(167, 139, 250, 0.8);
  }
}
@media (prefers-reduced-motion: reduce) {
  .btn-tom.active {
    animation: none;
  }
}

/* ── Webcam controls ──────────────────────── */
.webcam-ctrl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.cam-error {
  color: #fca5a5;
  font-size: 13px;
  padding: 7px 12px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 6px;
  flex: 1;
  min-width: 0;
}

/* ── Export row ───────────────────────────── */
.export-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.export-label {
  color: var(--fg3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-right: 2px;
}

/* ── Mobile ───────────────────────────────── */
@media (max-width: 600px) {
  .app-title {
    font-size: 13px;
  }
  .tab-btn {
    padding: 6px 12px;
    min-width: 66px;
    font-size: 12px;
  }
  .controls-panel {
    max-height: 220px;
  }
  input[type='range'] {
    width: 72px !important;
  }
  input[type='text'] {
    width: 110px;
  }
  .btn {
    font-size: 12px;
    padding: 6px 10px;
  }
  .btn-primary {
    padding: 9px 18px;
  }
}
