/* ============================================================================
   3netri — Device Emulator
   Handcrafted CSS. No framework. Dark operator console + luminous device stage.
   ============================================================================ */

:root {
  --saffron: #E8772E;
  --saffron-light: #f0944f;
  --ochre: #C4712E;
  --cream: #FDF6EC;
  --earth: #3B2F2F;
  --leaf: #3A7D44;
  --sky: #1B4965;
  --sky-dark: #132f42;
  --slate: #6B7280;
  --white: #FFFFFF;
  --ink: #060e18;
  --panel: #0f1f2e;
  --panel-2: #142a3d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e9edf1;
  --text-dim: #8b97a3;

  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: 100vh;
  overflow-x: hidden;
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
select, input, textarea { font: inherit; }

/* ---------- Operator Console (left) ---------- */

.console {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px 22px;
  overflow-y: auto;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (max-width: 900px) {
  .console { max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
}

.console__header h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--saffron);
  letter-spacing: -0.02em;
}
.console__header h1 span { opacity: 0.5; }
.console__subtitle {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 2px;
}

.console__section {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.console__h {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--saffron);
  margin-bottom: 10px;
}

.console__field { margin-bottom: 10px; }
.console__field label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.console__field select {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.875rem;
}
.console__field select:focus { outline: 2px solid var(--saffron); outline-offset: -1px; }

.console__caption {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 6px;
}
.console__caption code {
  background: var(--ink);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--saffron-light);
}

.context-display {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 80px;
}
.context-display strong { color: var(--text); }

.backend-display {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--saffron-light);
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.trace-log {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  max-height: 280px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.7;
}
.trace-log__empty {
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  text-align: center;
  padding: 20px 0;
}
.trace-entry {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.trace-entry:last-child { border-bottom: none; }
.trace-entry .ts { color: var(--text-dim); }
.trace-entry .kind { color: var(--saffron-light); }
.trace-entry .details { color: var(--text-dim); padding-left: 16px; display: block; }

/* ---------- Device Stage (right) ---------- */

.stage {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  overflow: hidden;
}

.stage__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(27,73,101,0.55) 0%, transparent 70%),
    radial-gradient(circle 500px at 50% 50%, rgba(232,119,46,0.05) 0%, transparent 70%),
    linear-gradient(180deg, #060e18 0%, #0a1628 50%, #060e18 100%);
  z-index: 0;
}

.device-wrap {
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 40px 60px rgba(0,0,0,0.6));
}

.stage__caption {
  position: relative;
  z-index: 1;
  font-size: 0.875rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 32px;
  line-height: 1.7;
  max-width: 480px;
}
.caption-muted {
  font-size: 0.75rem;
  color: var(--slate);
}

/* ---------- Device Body ---------- */

.device {
  position: relative;
  width: 300px;
  height: 520px;
  background: linear-gradient(160deg, #2a3540 0%, #1a232f 60%, #0f1820 100%);
  border-radius: 36px;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow:
    inset 0 2px 6px rgba(255,255,255,0.1),
    inset 0 -2px 8px rgba(0,0,0,0.5),
    0 0 0 2px rgba(0,0,0,0.6),
    0 30px 60px rgba(0,0,0,0.5);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.device[data-power="off"] {
  filter: grayscale(0.4) brightness(0.5);
  pointer-events: none;
}
.device[data-power="off"] .device__screen { background: #000; }
.device[data-power="off"] .device__screen * { opacity: 0.15; }
.device[data-power="off"] .device__led { background: #333; box-shadow: none; }
.device[data-power="off"] .device__camera svg { opacity: 0.3; }
.device[data-power="off"] { pointer-events: auto; } /* power button still works */
.device[data-power="off"] .device__side-btn--power { pointer-events: auto; }

/* Belt clip accent */
.device__clip {
  position: absolute;
  right: -6px;
  top: 160px;
  width: 8px;
  height: 100px;
  background: linear-gradient(90deg, #2a3540, #0f1820);
  border-radius: 0 4px 4px 0;
  box-shadow: inset -1px 0 0 rgba(0,0,0,0.5);
}

/* Top bezel */
.device__bezel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 0;
}
.device__led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--saffron);
  box-shadow: 0 0 8px var(--saffron), 0 0 3px var(--saffron-light);
  transition: background 0.2s, box-shadow 0.2s;
}
.device__led.is-busy {
  animation: led-pulse 0.8s ease-in-out infinite alternate;
}
.device__led.is-error { background: #ff4444; box-shadow: 0 0 8px #ff4444; }
@keyframes led-pulse {
  from { background: var(--saffron); box-shadow: 0 0 8px var(--saffron); }
  to { background: var(--saffron-light); box-shadow: 0 0 14px var(--saffron-light); }
}

.device__brand {
  font-family: var(--font-serif);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--saffron);
  letter-spacing: -0.02em;
}
.device__heritage {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.05em;
}

/* Camera / Eye */
.device__camera {
  padding: 6px 20px 2px;
  display: flex;
  justify-content: center;
  animation: eye-pulse 4s ease-in-out infinite;
}
.device__camera svg {
  width: 100%;
  max-width: 180px;
  height: auto;
}
@keyframes eye-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}
.device__camera.is-capturing svg { animation: capture-flash 0.6s ease; }
@keyframes capture-flash {
  0%   { filter: brightness(1); }
  30%  { filter: brightness(2.5) drop-shadow(0 0 20px var(--saffron)); }
  100% { filter: brightness(1); }
}

/* Screen */
.device__screen {
  flex: 1;
  background: linear-gradient(180deg, #0a1a2a 0%, #06121e 100%);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.55;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05), inset 0 0 20px rgba(0,0,0,0.5);
}
/* subtle screen scanline */
.device__screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255,255,255,0.015) 0px,
    rgba(255,255,255,0.015) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
}

.screen__state {
  font-size: 0.625rem;
  letter-spacing: 0.15em;
  color: var(--saffron);
  margin-bottom: 8px;
  font-weight: 700;
}
.screen__content {
  flex: 1;
  color: var(--text);
  overflow-y: auto;
  padding-right: 4px;
}
.screen__content::-webkit-scrollbar { width: 4px; }
.screen__content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.screen__hint { color: var(--text-dim); text-align: center; padding: 30px 10px; line-height: 1.8; }
.screen__hint strong { color: var(--saffron); }

.screen__meta {
  font-size: 0.6875rem;
  color: var(--text-dim);
  padding-top: 6px;
  margin-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.05);
}

.screen__diagnosis {
  background: rgba(232,119,46,0.08);
  border-left: 2px solid var(--saffron);
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 0 4px 4px 0;
}
.screen__diagnosis .label { color: var(--saffron); font-weight: 700; font-size: 0.6875rem; letter-spacing: 0.1em; }
.screen__diagnosis .value { color: var(--text); font-size: 0.8125rem; margin-top: 2px; }
.screen__diagnosis .conf { color: var(--text-dim); font-size: 0.6875rem; margin-top: 2px; }

.screen__advisory { color: var(--text); margin-top: 6px; }
.screen__advisory .label { color: var(--saffron-light); font-weight: 700; font-size: 0.6875rem; letter-spacing: 0.1em; margin-bottom: 4px; }
.screen__playing { color: var(--saffron); animation: waveform 1s ease-in-out infinite; }
@keyframes waveform {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Speaker grille */
.device__speaker {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 4px 0;
}
.device__speaker span {
  display: block;
  width: 3px;
  height: 14px;
  background: #000;
  border-radius: 1px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.device__speaker.is-playing span {
  animation: speaker-bounce 0.6s ease-in-out infinite alternate;
  background: var(--saffron-light);
  box-shadow: 0 0 4px var(--saffron);
}
.device__speaker.is-playing span:nth-child(1) { animation-delay: 0s; }
.device__speaker.is-playing span:nth-child(2) { animation-delay: 0.1s; }
.device__speaker.is-playing span:nth-child(3) { animation-delay: 0.2s; }
.device__speaker.is-playing span:nth-child(4) { animation-delay: 0.3s; }
.device__speaker.is-playing span:nth-child(5) { animation-delay: 0.4s; }
.device__speaker.is-playing span:nth-child(6) { animation-delay: 0.5s; }
@keyframes speaker-bounce {
  from { transform: scaleY(0.3); }
  to { transform: scaleY(1); }
}

/* Buttons */
.device__buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 2px 4px;
}
.device__btn {
  height: 52px;
  border-radius: 12px;
  background: linear-gradient(180deg, #2f3a46 0%, #1a232d 100%);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 0.8125rem;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.12),
    inset 0 -2px 4px rgba(0,0,0,0.5),
    0 2px 4px rgba(0,0,0,0.4);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.device__btn:hover { background: linear-gradient(180deg, #3a4651 0%, #202a37 100%); }
.device__btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6), inset 0 -1px 0 rgba(255,255,255,0.05);
}
.device__btn--cap { color: var(--saffron-light); }
.device__btn--rep { color: var(--text); }

/* Side buttons */
.device__side-btn {
  position: absolute;
  right: -12px;
  width: 18px;
  height: 32px;
  background: linear-gradient(90deg, #2a3540, #1a2330);
  border-radius: 0 4px 4px 0;
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset -1px 0 0 rgba(0,0,0,0.5);
  transition: background 0.1s;
}
.device__side-btn:hover { background: linear-gradient(90deg, #3a4651, #2a3540); color: var(--text); }
.device__side-btn:active { transform: translateX(1px); }
.device__side-btn--power { top: 48px; }
.device__side-btn--power::before { content: ''; }
.device__side-btn--volume-up   { left: -12px; right: auto; top: 140px; border-radius: 4px 0 0 4px; }
.device__side-btn--volume-down { left: -12px; right: auto; top: 180px; border-radius: 4px 0 0 4px; }

/* Status bar */
.device__statusbar {
  display: flex;
  justify-content: space-between;
  padding: 2px 8px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
}
.status-item { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Camera (video viewfinder) ---------- */

/* When device is in camera mode, hide the static eye and show the live video */
.device[data-mode="camera"] .device__eye,
.device[data-mode="captured"] .device__eye,
.device[data-mode="analyzing"] .device__eye,
.device[data-mode="delivering"] .device__eye {
  display: none;
}
.device[data-mode="camera"] .device__video,
.device[data-mode="captured"] .device__video,
.device[data-mode="analyzing"] .device__video,
.device[data-mode="delivering"] .device__video {
  display: block;
}
.device[data-mode="camera"] .device__viewfinder {
  opacity: 1;
}
.device[data-mode="captured"] .device__video,
.device[data-mode="analyzing"] .device__video,
.device[data-mode="delivering"] .device__video {
  display: none;
}
.device[data-mode="captured"] .device__still,
.device[data-mode="analyzing"] .device__still,
.device[data-mode="delivering"] .device__still {
  display: block;
}
.device[data-mode="analyzing"] .device__still {
  filter: brightness(0.7);
  animation: scan-sweep 1.5s ease-in-out infinite;
}

@keyframes scan-sweep {
  0%, 100% { filter: brightness(0.7); }
  50% { filter: brightness(1) drop-shadow(0 0 8px var(--saffron)); }
}

.device__camera {
  position: relative;
  height: 150px;
  padding: 0;
  overflow: hidden;
  border-radius: 10px;
  background: #000;
  margin: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.device__video,
.device__still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.device__eye {
  width: 100%;
  max-width: 180px;
  height: auto;
  position: relative;
  z-index: 2;
}

/* Viewfinder overlay — corner brackets + crosshair */
.device__viewfinder {
  position: absolute;
  inset: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 3;
}
.vf-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--saffron);
  border-style: solid;
  border-width: 0;
}
.vf-corner--tl { top: 0; left: 0; border-top-width: 2px; border-left-width: 2px; }
.vf-corner--tr { top: 0; right: 0; border-top-width: 2px; border-right-width: 2px; }
.vf-corner--bl { bottom: 0; left: 0; border-bottom-width: 2px; border-left-width: 2px; }
.vf-corner--br { bottom: 0; right: 0; border-bottom-width: 2px; border-right-width: 2px; }
.vf-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 1px solid rgba(232, 119, 46, 0.6);
  border-radius: 50%;
}
.vf-reticle::before, .vf-reticle::after {
  content: '';
  position: absolute;
  background: rgba(232, 119, 46, 0.6);
}
.vf-reticle::before { top: 50%; left: -6px; right: -6px; height: 1px; }
.vf-reticle::after { left: 50%; top: -6px; bottom: -6px; width: 1px; }

/* ---------- Warnings & permission panel ---------- */

.warn {
  background: rgba(255, 196, 0, 0.08);
  border: 1px solid rgba(255, 196, 0, 0.25);
  border-left: 3px solid #ffc400;
  color: #ffe08a;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  line-height: 1.6;
  margin: 8px 0;
}
.warn code {
  background: rgba(0,0,0,0.35);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--saffron-light);
}

.perm-display {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
}
.perm-display > div {
  display: flex;
  justify-content: space-between;
}
.perm-status {
  font-weight: 700;
}
.perm-status[data-state="granted"] { color: var(--leaf); }
.perm-status[data-state="denied"]  { color: #ff7070; }
.perm-status[data-state="prompt"], .perm-status[data-state="—"] { color: var(--text-dim); }

.btn-req {
  width: 100%;
  background: var(--saffron);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.8125rem;
  padding: 8px 12px;
  border-radius: 6px;
  letter-spacing: 0.03em;
  transition: background 0.15s;
}
.btn-req:hover { background: var(--saffron-light); }

.admin-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--saffron-light);
  text-decoration: none;
  border-bottom: 1px dotted rgba(232,119,46,0.4);
}
.admin-link:hover { color: var(--saffron); border-bottom-color: var(--saffron); }

/* ---------- Tap-to-play fallback (appears when iOS blocks autoplay) ---------- */
.tap-to-play {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--saffron);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: none;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(232, 119, 46, 0.3);
  cursor: pointer;
  animation: tap-pulse 1.5s ease-in-out infinite;
  transition: background 0.15s, transform 0.08s;
}
.tap-to-play:hover { background: var(--saffron-light); }
.tap-to-play:active { transform: scale(0.97); }
.tap-to-play span { font-size: 1.1rem; }
@keyframes tap-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(232, 119, 46, 0.3); }
  50%      { box-shadow: 0 2px 16px rgba(232, 119, 46, 0.6); }
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  padding: 1px 5px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--text);
}
