:root {
  --bg-0: #06080c;
  --bg-1: #0f1825;
  --bg-2: #152235;
  --panel: rgba(17, 23, 33, 0.84);
  --panel-strong: rgba(20, 28, 42, 0.96);
  --stroke: rgba(166, 186, 215, 0.23);
  --text: #eff5ff;
  --muted: #a0b3cf;
  --accent: #40e0b8;
  --accent-warm: #ffb06b;
  --danger: #ff6b6b;
  --app-height: 100vh;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 85% -10%, #1f2f47 0%, var(--bg-0) 60%),
    linear-gradient(175deg, var(--bg-1), var(--bg-0) 56%);
  overflow: hidden;
}

.ambient-glow,
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.ambient-glow {
  background: radial-gradient(700px 300px at 12% 18%, rgba(64, 224, 184, 0.14), transparent 70%),
    radial-gradient(900px 300px at 90% 82%, rgba(255, 176, 107, 0.08), transparent 66%);
}

.grain {
  opacity: 0.08;
  background-image: radial-gradient(rgba(255, 255, 255, 0.5) 0.35px, transparent 0.35px);
  background-size: 3px 3px;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  min-height: 400px;
  padding: 16px 16px calc(98px + var(--safe-bottom));
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-stack h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-block;
  margin: 0 0 6px;
  padding: 4px 9px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(10, 17, 28, 0.75);
  color: var(--muted);
  font-size: 0.8rem;
}

.status-cluster {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(64, 224, 184, 0.8);
}

.ide-layout {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: linear-gradient(165deg, var(--panel), rgba(15, 22, 33, 0.8));
  backdrop-filter: blur(10px);
}

.side-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(82vw, 320px);
  padding: 14px;
  overflow: auto;
  border-right: 1px solid var(--stroke);
  background: var(--panel-strong);
  transform: translateX(-104%);
  transition: transform 180ms ease;
  z-index: 3;
}

.side-panel.open {
  transform: translateX(0);
}

.panel-group {
  display: none;
  animation: panelFade 180ms ease;
}

.panel-group.active {
  display: block;
}

.panel-group h2 {
  margin: 0 0 10px;
  color: var(--accent-warm);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.panel-group ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
}

.panel-body ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
}

.panel-group pre {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #b6ffc8;
  background: rgba(7, 12, 20, 0.7);
  padding: 11px;
  border-radius: 10px;
  border: 1px solid rgba(116, 159, 130, 0.26);
}

.ai-panel-body {
  display: grid;
  gap: 10px;
}

.ai-provider-row {
  display: grid;
  gap: 8px;
}

.ai-label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ai-panel-body textarea,
.ai-panel-body select,
.settings-grid input,
.settings-grid textarea,
.settings-grid select {
  width: 100%;
  border: 1px solid rgba(156, 182, 214, 0.34);
  background: rgba(7, 12, 20, 0.82);
  color: var(--text);
  border-radius: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 10px 11px;
  resize: vertical;
  min-height: 94px;
}

.ai-panel-body select,
.settings-grid input,
.settings-grid select {
  min-height: 40px;
}

.settings-grid input,
.settings-grid textarea {
  resize: none;
}

.ai-panel-body textarea:focus {
  outline: 1px solid rgba(88, 239, 200, 0.72);
}

.ai-panel-body select:focus,
.settings-grid input:focus,
.settings-grid textarea:focus,
.settings-grid select:focus {
  outline: 1px solid rgba(88, 239, 200, 0.72);
}

.ai-panel-body pre {
  min-height: 84px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.settings-panel-body {
  display: grid;
  gap: 10px;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.settings-grid {
  display: grid;
  gap: 7px;
}

.settings-grid label {
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-divider {
  border: 0;
  border-top: 1px solid rgba(156, 182, 214, 0.26);
  margin: 8px 0;
}

#agentAllowRootInput,
#agentRootCommandInput {
  width: 18px;
  height: 18px;
}

#agentOutputBody {
  min-height: 140px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.panel-loading,
.panel-error,
.panel-empty {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.4;
}

.panel-loading {
  color: var(--muted);
}

.panel-error {
  color: #ff9a9a;
}

.panel-empty {
  color: #f4c28f;
}

.editor-surface {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-tabs {
  display: flex;
  gap: 7px;
  padding: 12px;
  border-bottom: 1px solid var(--stroke);
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  border: 1px solid var(--stroke);
  background: rgba(15, 24, 37, 0.8);
  color: var(--muted);
  border-radius: 9px;
  padding: 8px 10px;
  white-space: nowrap;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
}

.tab.active {
  color: var(--text);
  border-color: rgba(128, 166, 216, 0.6);
}

.editor-viewport {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 10px;
  padding: clamp(18px, 4vw, 46px);
}

.viewport-label {
  margin: 0;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  letter-spacing: 0.02em;
}

.viewport-note {
  margin: 0;
  color: var(--muted);
  max-width: 52ch;
  line-height: 1.45;
}

.workspace-link {
  margin-top: 4px;
  color: #9bf4e0;
  text-decoration: none;
  border-bottom: 1px dashed rgba(155, 244, 224, 0.4);
  font-size: 0.9rem;
}

.workspace-link.hidden {
  display: none;
}

.workspace-action {
  border: 1px solid rgba(156, 182, 214, 0.5);
  background: rgba(16, 26, 40, 0.85);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.workspace-action:disabled {
  opacity: 0.6;
}

.rotate-tip {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(88px + var(--safe-bottom));
  z-index: 3;
  background: rgba(255, 176, 107, 0.15);
  border: 1px solid rgba(255, 176, 107, 0.45);
  color: #ffd4ac;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.83rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.app.show-rotate-tip .rotate-tip {
  opacity: 1;
}

.floating-bar {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 15px;
  border: 1px solid var(--stroke);
  background: rgba(8, 13, 22, 0.9);
  backdrop-filter: blur(10px);
  width: min(96vw, 760px);
  overflow-x: auto;
  z-index: 5;
}

.fab-btn {
  border: 1px solid rgba(156, 182, 214, 0.28);
  background: rgba(16, 26, 40, 0.8);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: transform 120ms ease, border-color 120ms ease, color 120ms ease;
}

.fab-btn:active {
  transform: translateY(1px) scale(0.99);
}

.fab-btn.active {
  color: var(--text);
  border-color: rgba(162, 200, 255, 0.62);
}

.fab-btn.primary {
  color: #031215;
  background: linear-gradient(135deg, #58efc8, #36d9e0);
  border-color: transparent;
}

@media (min-width: 980px) {
  .app {
    padding: 18px 22px calc(86px + var(--safe-bottom));
  }

  .ide-layout {
    grid-template-columns: 300px 1fr;
  }

  .side-panel {
    position: relative;
    width: auto;
    transform: none;
    border-right: 1px solid var(--stroke);
  }

  .side-panel.open {
    transform: none;
  }
}

@media (orientation: landscape) and (max-width: 980px) {
  .app {
    padding-bottom: calc(80px + var(--safe-bottom));
  }

  .side-panel {
    width: min(44vw, 330px);
  }
}

@keyframes panelFade {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
