/* Сканер рисунков (переведено из инлайн-<style> capture.html, п.21 аудита) */
:root {
  --ink: #0f2b5c;
  --muted: #475569;
  --accent: #0284c7;
  --accent-light: #38bdf8;
  --ok: #059669;
  --ok-light: #10b981;
  --card-bg: rgba(255, 255, 255, 0.88);
  --card-border: rgba(255, 255, 255, 0.95);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  margin: 0;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: linear-gradient(145deg, #dcfce7 0%, #e0f2fe 50%, #fef9c3 100%);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.4 'Nunito', sans-serif;
  font-weight: 700;
  text-align: center;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Top Navigation Bar */
.top-nav {
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #fff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 900;
  padding: 6px 11px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
  white-space: nowrap;
  transition: transform 0.1s;
  flex-shrink: 0;
}
.nav-btn:active { transform: translateY(2px); }
.nav-back {
  background: linear-gradient(135deg, #0284c7, #0369a1);
}
.nav-print {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}
.nav-title {
  font-size: 15px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Embed mode: inside aquarium iframe */
body.embed { background: none; padding: 4px 14px 20px; }
body.embed .top-nav { display: none; }

/* Screen Containers */
.screen {
  display: none;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  flex: 1;
}
.screen.on {
  display: flex;
  flex-direction: column;
}

/* Clean UI Cards */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid var(--card-border);
  border-radius: 20px;
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: 0 4px 16px rgba(15, 43, 92, 0.08);
}

/* TV Connection Bar */
.card-tv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 10px;
}
.tv-label {
  font-size: 13px;
  font-weight: 900;
  color: var(--muted);
  white-space: nowrap;
}
#manual-room-code {
  background: #fff;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  color: var(--ink);
  padding: 5px 6px;
  font-size: 16px;
  font-weight: 900;
  text-align: center;
  width: 76px;
  font-family: 'Space Mono', monospace;
  letter-spacing: 2px;
  flex-shrink: 1;
  min-width: 60px;
}
#manual-room-code:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}
.btn-connect {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 #0369a1;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-connect:active { transform: translateY(3px); box-shadow: 0 0 0 #0369a1; }
.room-status-text {
  min-height: 18px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ok);
  margin: -4px 0 6px;
}

/* Fish Kind Select */
.card-fish-select {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}
.card-fish-select label {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}
#manual-fish-kind {
  flex: 1;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid #cbd5e1;
  background: #fff;
  color: var(--ink);
}

/* Action Buttons Grid */
.action-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0;
}
.secondary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 6px 0;
}

.big {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  border: 2.5px solid #fff;
  border-radius: 20px;
  padding: 13px 16px;
  cursor: pointer;
  box-shadow: 0 5px 0 #0369a1, 0 8px 15px rgba(2, 132, 199, 0.25);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-sizing: border-box;
}
.big:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 #0369a1;
}
.big.green {
  background: linear-gradient(135deg, #34d399, #059669);
  box-shadow: 0 5px 0 #047857, 0 8px 15px rgba(5, 150, 105, 0.25);
  font-size: 17px;
  padding: 14px 18px;
}
.big.green:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 #047857;
}
.big.ghost {
  background: #fff;
  color: var(--ink);
  border: 2px solid #cbd5e1;
  box-shadow: 0 4px 0 #94a3b8;
  font-size: 15px;
  padding: 11px 12px;
}
.big.ghost:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #94a3b8;
}

.hintline {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  margin: 8px 0 0;
  padding: 0 6px;
}

/* Camera preview */
.camera-panel { display: none; margin: 8px 0; }
.camera-panel.on { display: block; }
.camera-guide { position: relative; border-radius: 18px; overflow: hidden; }
.guide-frame {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.guide-frame path {
  fill: none; stroke: rgba(255,255,255,0.9); stroke-width: 1.4;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.camera-preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 18px;
  border: 3px solid #fff;
  background: #071827;
  transform: scaleX(-1);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}
.camera-actions { display: flex; gap: 8px; margin-top: 8px; }
.camera-actions .big { flex: 1; padding: 11px; font-size: 14px; }
.quality { min-height: 20px; margin: 6px 0 0; font-size: 13px; font-weight: 800; color: var(--muted); }
.quality.good { color: #047857; }
.quality.bad { color: #b91c1c; }

/* Joystick screen */
#s-joystick {
  flex-direction: column;
  height: 100%;
  min-height: calc(100vh - 70px);
  min-height: calc(100dvh - 70px);
}
#s-joystick.on { display: flex; }
.joy-modes { display: flex; gap: 8px; margin-bottom: 8px; }
.joy-modes .big { flex: 1; margin: 0; padding: 10px 6px; font-size: 14px; }
.joy-status { min-height: 18px; margin: 0 0 6px; font-size: 13px; font-weight: 900; color: var(--muted); }
.joy-status.connected { color: #047857; }
.joy-status.fallback { color: #b45309; }
.joy-status.reconnecting { color: #b91c1c; }
#touch-pad {
  flex: 1;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  background: rgba(2, 132, 199, 0.08);
  border: 2px dashed rgba(2, 132, 199, 0.4);
  border-radius: 20px;
  min-height: 200px;
  outline: none;
}
#touch-pad:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,0.4); }
.joy-base {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  border-radius: 50%; border: 3px solid rgba(2, 132, 199, 0.5);
  background: rgba(2, 132, 199, 0.12); pointer-events: none;
}
.joy-thumb {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  border-radius: 50%; background: linear-gradient(135deg, #38bdf8, #0284c7);
  opacity: 0.9;
  pointer-events: none; will-change: left, top;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}
.joy-hint { margin-top: 8px; }

/* 3D Preview and other screens */
.stage3d {
  width: 100%; aspect-ratio: 4 / 3; margin-top: 10px;
  border-radius: 20px; overflow: hidden; position: relative;
  border: 3px solid #fff;
  background: linear-gradient(180deg, #e0f2fe 0%, #bae6fd 100%);
  box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.stage3d canvas { display: block; width: 100%; height: 100%; }
.stage3d .spin3d {
  position: absolute; inset: 0; display: grid; place-content: center;
  color: var(--ink); font-size: 16px; font-weight: 900;
}
.fishname { font-size: 20px; font-weight: 900; margin: 10px 0 2px; }
.boostrow {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 2px 0; text-align: left;
}
.boostrow label { flex: none; color: var(--ink); font-size: 14px; font-weight: 900; }
.boostrow input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }

.spin {
  width: 44px; height: 44px; margin: 24px auto 12px;
  border: 4px solid rgba(56, 189, 248, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-wrap {
  width: 100%; height: 10px; margin: 14px 0 8px;
  background: rgba(56,189,248,.18); border-radius: 999px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(to right, #7dd3fc, #0ea5e9);
  border-radius: 999px; transition: width .2s ease;
}
.status-line { color: var(--muted); font-size: 13px; min-height: 18px; margin: 0; }
.err {
  background: #fee2e2;
  border: 2px solid #f87171;
  border-radius: 18px; padding: 14px;
  color: #b91c1c; font-size: 15px; margin-top: 14px;
  text-align: left;
  font-weight: 700;
}
.err-checklist {
  background: #fff7ed;
  border: 2px solid #fdba74;
  border-radius: 18px; padding: 12px 14px;
  margin-top: 10px; text-align: left;
  color: #7c2d12; font-size: 13.5px; font-weight: 700;
}
.err-checklist b { display: block; margin-bottom: 4px; }
.err-checklist ul { margin: 0 0 8px; padding-left: 18px; }
.err-checklist li { margin-bottom: 3px; }
.err-checklist span { color: #9a3412; font-weight: 600; }

.crop-point {
  position: absolute;
  width: 36px; height: 36px;
  margin-left: -18px; margin-top: -18px;
  background: rgba(56, 189, 248, 0.4);
  border: 3px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  z-index: 10;
}
.crop-point:active { cursor: grabbing; background: var(--accent); }

/* Landscape on mobile */
@media (orientation: landscape) and (max-height: 520px) {
  .top-nav { margin-bottom: 6px; }
  .card { padding: 6px 10px; margin-bottom: 6px; }
  .action-grid { flex-direction: row; }
  .action-grid .big { flex: 1; padding: 10px; font-size: 14px; }
  .secondary-grid .big { padding: 8px; font-size: 13px; }
  #touch-pad { min-height: 130px; }
}
/* Клавиатурный фокус виден всегда */
a:focus-visible, button:focus-visible, label:focus-visible, input:focus-visible,
select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #0284c7; outline-offset: 2px; border-radius: 8px;
}

/* Атрибуты style= переведены в классы/ID (п.21 аудита) */
#file { display: none; }
.btn-gap-top { margin-top: 12px; }
.warning-amber { color: #b45309; }
.crop-warning { color: #b91c1c; margin-bottom: 8px; }
.crop-container {
  position: relative;
  margin: 0 auto;
  display: inline-block;
  max-width: 100%;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  touch-action: none;
}
.crop-canvas { display: block; max-width: 100%; }
.crop-confirm { margin-top: 16px; }
#crop-pt-tl { left: 10%; top: 10%; }
#crop-pt-tr { left: 90%; top: 10%; }
#crop-pt-bl { left: 10%; top: 90%; }
#crop-pt-br { left: 90%; top: 90%; }
