:root {
  color: #f4f7ff;
  background: #070b14;
  font: 15px/1.45 "Segoe UI", "Avenir Next", sans-serif;
  --ink: #f4f7ff;
  --muted: #9aa6c4;
  --line: rgba(168, 190, 255, 0.22);
  --gold: #e7c27a;
  --sapphire: #7aa2ff;
  --panel: #121826;
  --panel-2: #0c1220;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(980px 520px at 100% -12%, rgba(122, 162, 255, 0.22), transparent 58%),
    radial-gradient(760px 460px at -8% 8%, rgba(231, 194, 122, 0.14), transparent 52%),
    linear-gradient(180deg, #10182c 0%, #070b14 42%);
}

button, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }

.shell {
  height: 100%;
  margin: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.top { grid-column: 1 / -1; }

.features { grid-column: 1; min-height: 0; }

.main {
  grid-column: 2;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.top {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 14px;
  margin: 0;
  padding: 10px 14px;
  overflow-x: auto;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  object-fit: cover;
  background: #0c1220;
  border: 1px solid var(--line);
  box-shadow: 0 12px 28px rgba(4, 8, 20, 0.45);
}

h1 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1;
}

.tag, #boot, .log-head {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.tag { margin-top: 6px; }

#boot { color: var(--muted); white-space: nowrap; }

.card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 42%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 18px 40px rgba(4, 8, 20, 0.32);
}

.connect {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.port { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.port span { white-space: nowrap; }

select {
  min-width: 140px;
  padding: 10px 34px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23e7c27a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--ink);
  appearance: none;
}

.connect button, #pickImage, #stop, .log-head button {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
}

.connect button:hover:not(:disabled),
#pickImage:hover,
#stop:hover:not(:disabled) {
  border-color: var(--gold);
}

#lang {
  min-width: 112px;
  width: auto;
}

.dev-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}

.dev-toggle input {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
}

.dev-toggle input:checked {
  border-color: var(--gold);
  background: var(--gold) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='10' viewBox='0 0 12 10'%3E%3Cpath fill='none' stroke='%231a140c' stroke-width='2' d='M1 5l3 3 7-7'/%3E%3C/svg%3E") center / 12px 10px no-repeat;
}

.features {
  height: 100%;
  overflow: auto;
  margin: 0;
  padding: 12px;
}

.feat-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feat {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(168, 190, 255, 0.14);
  border-radius: 18px;
  background: #0c1220;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.feat:hover { border-color: rgba(122, 162, 255, 0.7); }

.feat:has(input:checked) {
  border-color: var(--gold);
  background: #182033;
  box-shadow: 0 0 0 1px var(--gold), 0 10px 24px rgba(4, 8, 20, 0.35);
}

.feat input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.feat img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: #121826;
  box-shadow: 0 0 0 1px rgba(231, 194, 122, 0.4);
}

.feat span { font-size: 13px; font-weight: 600; }

.desk {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

body.dev .desk {
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
}

.col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.pick { margin: 0; flex: none; }

.trace, .activity { display: none; }
body.dev .trace { display: block; }
body.dev .activity {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
}

.pick {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
}

.pick[hidden] { display: none; }

#imageName {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#open, #close {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 1;
}

#open:disabled span, #close:disabled span { opacity: 0.45; }

.led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2a3348;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  flex: none;
}

body.linked #open .led {
  background: #3ddc84;
  box-shadow: 0 0 8px rgba(61, 220, 132, 0.95);
}

body:not(.linked) #close .led {
  background: #ff4d5e;
  box-shadow: 0 0 8px rgba(255, 77, 94, 0.9);
}

#send, #stop { min-width: 120px; padding: 12px 18px; border-radius: 14px; }

#send {
  border: 0;
  background: linear-gradient(180deg, #f0d7a2, #e7c27a);
  color: #1a140c;
  font-weight: 700;
}

#send:hover:not(:disabled) { filter: brightness(1.05); }

#send:disabled {
  opacity: 1;
  background: #241c14;
  color: #a89878;
  border: 1px solid rgba(231, 194, 122, 0.28);
}

.log, .stage { padding: 10px 14px 8px; }

.trace { flex: 0 0 auto; }

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.log-head button {
  padding: 4px 10px;
  color: var(--gold);
  letter-spacing: 0.12em;
  font-size: 11px;
}

#cmdLog, #paramLog, #resultLog {
  width: 100%;
  resize: vertical;
  border: 0;
  background: transparent;
  color: #d7def2;
  font: 12px/1.55 Consolas, "Courier New", monospace;
}

#cmdLog {
  height: 44px;
  margin: 0 0 6px;
  padding: 0 0 6px;
  color: var(--muted);
  border-bottom: 1px solid rgba(168, 190, 255, 0.12);
}

#resultLog { height: 96px; }

.trace .log-head { margin-bottom: 4px; }

#paramLog { flex: 1; min-height: 0; }

#outcome {
  min-height: 1.4em;
  margin: 4px 2px 10px;
  font-size: 18px;
  font-weight: 600;
}

.stage {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.frame {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
}

.frame[hidden] { display: none; }

#view {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 3 / 4;
  background: #070b14;
  border-radius: 14px;
  border: 1px solid rgba(168, 190, 255, 0.18);
  box-shadow: inset 0 0 0 1px rgba(122, 162, 255, 0.08);
}

@media (max-width: 1100px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr); }
  h1 { font-size: 22px; }
  .logo { width: 44px; height: 44px; }
}

@media (max-width: 900px) {
  body.dev .desk { grid-template-columns: 1fr; }
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(160px, 32vh) minmax(0, 1fr);
  }
  .top, .features, .main { grid-column: 1; }
  .features { grid-row: 2; height: 100%; }
  .main { grid-row: 3; }
  .connect button { padding: 8px 10px; font-size: 13px; }
  select { min-width: 120px; }
}

@media (max-width: 640px) {
  h1 { font-size: 28px; }
  .logo { width: 52px; height: 52px; }
  .feat img { width: 44px; height: 44px; }
  .actions { align-items: stretch; }
  #send, #stop { flex: 1; min-width: 0; }
}
