:root {
  --app-bg: #1a1614;
  --app-panel: #14110f;
  --app-toolbar: #221d1a;
  --app-console: #0d0a08;
  --app-border: rgba(255, 255, 255, 0.06);
  --app-border-strong: rgba(255, 255, 255, 0.12);
  --app-btn: #2a2522;
  --app-btn-hover: #322c28;
  --app-text: #e7e2dc;
  --app-text-dim: #8a827a;
  --app-text-faint: #5a534d;
  --log-time: #fbbf24;
  --log-success: #4ade80;
  --log-info: #e7e2dc;
  --log-error: #ef4444;
  --log-warn: #fb923c;
  --log-accent: #ff7849;
}

html, body { height: 100%; overflow: hidden; }
body { background: var(--app-bg); color: var(--app-text); font-family: 'Manrope', sans-serif; }
body::before, body::after { display: none !important; }

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: 130px 1fr;
  background: var(--app-bg);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-side {
  background: var(--app-panel);
  border-right: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.loading-side .bottom {
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--app-border);
  justify-content: center;
}

.loading-side .bottom .mini {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  color: var(--app-text-dim);
}
.loading-side .bottom .mini svg { width: 14px; height: 14px; }

.loading-main {
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(800px 600px at 50% 50%, rgba(255, 120, 73, 0.08), transparent 70%),
    var(--app-bg);
}

.loading-main::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 120, 73, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 120, 73, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  mask: radial-gradient(circle at center, #000 20%, transparent 70%);
  -webkit-mask: radial-gradient(circle at center, #000 20%, transparent 70%);
  pointer-events: none;
}

.loading-content {
  text-align: center;
  position: relative;
  z-index: 1;
}

.loading-logo {
  width: 180px;
  height: 180px;
  object-fit: contain;
  margin-bottom: 48px;
  filter: drop-shadow(0 0 40px rgba(255, 120, 73, 0.5));
  animation: logo-pulse 2s ease-in-out infinite;
}

@keyframes logo-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 40px rgba(255, 120, 73, 0.4)); }
  50% { transform: scale(1.04); filter: drop-shadow(0 0 60px rgba(255, 120, 73, 0.7)); }
}

.loading-title {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
  background: linear-gradient(135deg, #fff, #ff7849);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.loading-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--app-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 32px;
}

.loading-bar-wrap {
  width: 320px;
  max-width: 80vw;
  margin: 0 auto;
}

.loading-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--log-accent), #ffa17a);
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(255, 120, 73, 0.6);
  transition: width 3s linear;
}

.loading-overlay.loading .loading-fill { width: 100%; }

.loading-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--app-text-dim);
}

.loading-row .status { color: var(--log-accent); }
.loading-row .percent { color: var(--app-text); font-weight: 700; }

.app-shell {
  display: grid;
  grid-template-columns: 130px 1fr;
  grid-template-rows: 1fr auto;
  height: 100vh;
}

/* ============ LEFT SIDEBAR ============ */
.app-side {
  grid-column: 1;
  grid-row: 1 / 3;
  background: var(--app-panel);
  border-right: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.app-side .bot-card {
  background: linear-gradient(180deg, rgba(255, 120, 73, 0.08), transparent);
  border: 1px solid var(--app-border-strong);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  position: relative;
}

.app-side .bot-card.empty { opacity: 0.35; pointer-events: none; }

.app-side .bot-card .avatar {
  width: 54px;
  height: 54px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2a2522, #14110f);
  border: 2px solid var(--log-accent);
  display: grid;
  place-items: center;
  font-size: 22px;
}

.app-side .bot-card .name {
  font-size: 12px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--app-text);
}

.app-side .bot-card .state {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 4px;
}

.state-connected { color: var(--log-success); }
.state-combat { color: var(--log-accent); }
.state-idle { color: var(--app-text-dim); }

.app-side-bottom {
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--app-border);
  justify-content: center;
}

.app-side-bottom .mini {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  cursor: pointer;
  color: var(--app-text-dim);
}
.app-side-bottom .mini:hover { color: var(--log-accent); border-color: var(--log-accent); }
.app-side-bottom .mini svg { width: 14px; height: 14px; }

/* ============ MAIN AREA WRAPPER ============ */
.app-main-wrap {
  grid-column: 2;
  grid-row: 1 / 3;
  display: grid;
  grid-template-columns: 50px 1fr 150px;
  grid-template-rows: 1fr auto;
  background: var(--app-bg);
}

/* ============ ICON STRIP ============ */
.app-icons {
  grid-column: 1; grid-row: 1;
  background: var(--app-panel);
  border-right: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  gap: 4px;
}

.app-icons button {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--app-text-dim);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s;
  position: relative;
}

.app-icons button:hover {
  background: var(--app-btn);
  color: var(--app-text);
}

.app-icons button.active {
  background: rgba(255, 120, 73, 0.12);
  color: var(--log-accent);
  border-color: rgba(255, 120, 73, 0.3);
}

.app-icons button.active::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--log-accent);
  border-radius: 0 3px 3px 0;
}

.app-icons button svg { width: 18px; height: 18px; }

/* ============ MAIN CONTENT (status + console) ============ */
.app-content {
  grid-column: 2; grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--app-toolbar);
  border-bottom: 1px solid var(--app-border);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}

.status-bar .status-label { color: var(--app-text-dim); }
.status-bar .status-value { color: var(--log-success); }
.status-bar .status-value.combat { color: var(--log-accent); }
.status-bar .sep { color: var(--app-text-faint); }
.status-bar .script-name { color: var(--log-time); }

.status-bar .mode-toggle {
  margin-left: auto;
  display: flex;
  background: var(--app-console);
  border-radius: 6px;
  padding: 2px;
}

.status-bar .mode-toggle button {
  padding: 4px 12px;
  font-size: 11px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--app-text-dim);
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  font-weight: 600;
}

.status-bar .mode-toggle button.on {
  background: var(--app-btn);
  color: var(--app-text);
}

.status-bar .controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.status-bar .controls button,
.status-bar .controls .ctrl-btn {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  display: grid; place-items: center;
  color: var(--app-text-dim);
  cursor: pointer;
  transition: all 0.15s;
}
.status-bar .controls .ctrl-btn.play { background: rgba(74, 222, 128, 0.12); border-color: rgba(74, 222, 128, 0.3); color: var(--log-success); }
.status-bar .controls .ctrl-btn.stop { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.3); color: var(--log-error); }
.status-bar .controls button:hover { background: var(--app-btn-hover); }
.status-bar .controls svg { width: 14px; height: 14px; }

.status-bar .disconnect {
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--app-text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}

.status-bar .close-x {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--app-text-dim);
  cursor: pointer;
}
.status-bar .close-x:hover { background: rgba(239, 68, 68, 0.15); color: var(--log-error); }

/* ============ CONFIG ROWS ============ */
.config-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--app-toolbar);
  border-bottom: 1px solid var(--app-border);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
}

.config-row .trophy { color: var(--log-accent); font-size: 14px; }

.config-row .level-label { color: var(--app-text-dim); }

.config-row .level-pill {
  background: var(--log-accent);
  color: #1a0e08;
  padding: 4px 16px;
  border-radius: 4px;
  font-weight: 800;
  font-size: 13px;
}

.config-row .btn-app {
  padding: 6px 14px;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  color: var(--app-text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
}
.config-row .btn-app:hover { background: var(--app-btn-hover); }

.config-row .subscription {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.config-row .subscription .label { color: var(--app-text-dim); }
.config-row .subscription .value { color: var(--log-error); font-weight: 600; }

.config-row select.dropdown,
.config-row .dropdown {
  background: var(--app-console);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--app-text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.config-row .checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--app-text-dim);
}

.config-row .checkbox input { accent-color: var(--log-accent); }

.config-row .location {
  margin-left: auto;
  color: var(--log-time);
  font-weight: 600;
}

/* ============ CONSOLE ============ */
.console-area {
  flex: 1;
  background: var(--app-console);
  overflow-y: auto;
  padding: 12px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.55;
  min-height: 0;
}

.console-area::-webkit-scrollbar { width: 10px; }
.console-area::-webkit-scrollbar-track { background: var(--app-console); }
.console-area::-webkit-scrollbar-thumb { background: var(--app-btn); border-radius: 4px; }
.console-area::-webkit-scrollbar-thumb:hover { background: var(--app-btn-hover); }

.log-line {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-time-tag { color: var(--log-time); }
.log-success-tag { color: var(--log-success); }
.log-info-tag { color: var(--log-info); }
.log-error-tag { color: var(--log-error); }
.log-warn-tag { color: var(--log-warn); }
.log-accent-tag { color: var(--log-accent); }

.log-section {
  color: var(--log-time);
  margin: 6px 0 4px;
  font-weight: 600;
}

/* ============ CHAT INPUT ============ */
.chat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--app-toolbar);
  border-top: 1px solid var(--app-border);
}

.chat-row .chat-channel {
  background: var(--app-console);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--app-text);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  min-width: 100px;
}

.chat-row .chat-input {
  flex: 1;
  background: var(--app-console);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  padding: 7px 12px;
  color: var(--app-text);
  font-size: 12px;
  font-family: inherit;
}
.chat-row .chat-input:focus { outline: none; border-color: var(--log-accent); }

.chat-row .chat-btn {
  padding: 7px 14px;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  border-radius: 6px;
  color: var(--app-text-dim);
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
}
.chat-row .chat-btn:hover { color: var(--app-text); }

/* ============ RIGHT ACTION BUTTONS ============ */
.right-actions {
  grid-column: 3; grid-row: 1;
  background: var(--app-panel);
  border-left: 1px solid var(--app-border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.right-actions .top-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.right-actions .top-row .mini-btn {
  flex: 1;
  padding: 5px;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  border-radius: 5px;
  color: var(--app-text);
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
}

.right-actions .action {
  padding: 7px 8px;
  background: var(--app-btn);
  border: 1px solid var(--app-border-strong);
  border-radius: 5px;
  color: var(--app-text);
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  text-align: center;
  font-weight: 500;
  transition: all 0.15s;
}

.right-actions .action:hover {
  background: rgba(255, 120, 73, 0.1);
  border-color: var(--log-accent);
  color: var(--log-accent);
}

.right-actions .spacer { height: 2px; }

/* ============ STATS BAR ============ */
.stats-bar {
  grid-column: 1 / 4;
  grid-row: 2;
  background: var(--app-toolbar);
  border-top: 1px solid var(--app-border-strong);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-item .icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--app-btn);
  color: var(--log-accent);
}
.stat-item .icon svg { width: 12px; height: 12px; }

.stat-item .bar {
  width: 130px;
  height: 18px;
  background: var(--app-console);
  border: 1px solid var(--app-border-strong);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.stat-item .bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--log-accent), #ffa17a);
  width: var(--p, 100%);
  transition: width 0.4s ease;
}

.stat-item .bar .text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  z-index: 2;
}

.stat-item.kamas { margin-left: auto; }
.stat-item.kamas .value { color: var(--log-time); font-weight: 700; font-size: 14px; }
.stat-item.position .value { color: var(--log-accent); font-weight: 700; }

/* ============ VIEW STATES ============ */
.view { display: none; flex-direction: column; flex: 1; min-height: 0; }
.view.active { display: flex; }

/* WELCOME VIEW */
.welcome-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--app-console);
  position: relative;
}

.welcome-view::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(600px 400px at 50% 50%, rgba(255, 120, 73, 0.06), transparent 70%);
  pointer-events: none;
}

.welcome-content {
  text-align: center;
  position: relative;
  z-index: 1;
}

.welcome-content img {
  width: 220px;
  height: 220px;
  object-fit: contain;
  filter: drop-shadow(0 0 40px rgba(255, 120, 73, 0.35));
  margin-bottom: 24px;
  animation: float-soft 4s ease-in-out infinite;
}

@keyframes float-soft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-content .ctitle {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.welcome-content .ctitle .accent { color: var(--log-accent); }

.welcome-content .csub {
  color: var(--app-text-dim);
  font-size: 14px;
  margin-bottom: 28px;
}

.welcome-content .cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--log-accent);
  color: #1a0e08;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 8px 30px -8px rgba(255, 120, 73, 0.5);
  transition: all 0.2s;
}

.welcome-content .cta:hover { transform: translateY(-2px); box-shadow: 0 14px 40px -8px rgba(255, 120, 73, 0.6); }

/* ARCHIS VIEW */
.archis-view {
  flex: 1;
  background: var(--app-console);
  padding: 20px;
  overflow-y: auto;
}

.archis-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.archis-header h2 {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.archis-header .pill {
  padding: 3px 10px;
  background: rgba(255, 120, 73, 0.12);
  border: 1px solid rgba(255, 120, 73, 0.3);
  border-radius: 999px;
  color: var(--log-accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
}

.archis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
}

.archi-card {
  background: #1e1b18;
  border-radius: 8px;
  padding: 16px;
  border-left: 4px solid #5865f2;
  display: flex;
  gap: 14px;
  position: relative;
}

.archi-card.from-imagiro { border-left-color: #00b8d4; }
.archi-card.from-ilyzaelle { border-left-color: #5865f2; }

.archi-card .card-body { flex: 1; min-width: 0; }

.archi-card .head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

.archi-card .head .av {
  width: 28px; height: 28px; border-radius: 50%;
  background: #5865f2;
  display: grid; place-items: center;
  color: #fff;
}
.archi-card.from-imagiro .head .av { background: #00b8d4; }

.archi-card .head .av svg { width: 14px; height: 14px; }

.archi-card .head .name {
  color: var(--app-text);
  font-weight: 600;
}

.archi-card .head .bot-badge {
  background: #5865f2;
  color: #fff;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
}
.archi-card.from-imagiro .head .bot-badge { background: #00b8d4; }

.archi-card .head .time {
  margin-left: auto;
  color: var(--app-text-faint);
  font-size: 11px;
}

.archi-card .title {
  color: #00afff;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  font-family: 'JetBrains Mono', monospace;
}

.archi-card .fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  font-size: 11px;
}

.archi-card .fld-label {
  color: var(--app-text);
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.archi-card .fld-value {
  background: #14110f;
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--app-text);
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  font-size: 11px;
}

.archi-card .fld-value.link {
  color: var(--log-accent);
  cursor: pointer;
  text-decoration: underline;
}

.archi-card .creature {
  width: 64px;
  height: 64px;
  background: #14110f;
  border: 1px solid var(--app-border-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  align-self: flex-start;
  font-size: 28px;
}

/* RESPONSIVE */
@media (max-width: 1180px) {
  .config-row { gap: 8px; font-size: 11px; padding: 8px 12px; }
  .config-row .btn-app { padding: 5px 10px; font-size: 11px; }
  .status-bar { gap: 10px; padding: 8px 12px; font-size: 12px; }
  .right-actions { padding: 8px; gap: 5px; }
  .right-actions .action { padding: 6px; font-size: 10px; }
  .stats-bar { gap: 10px; padding: 6px 12px; }
  .stat-item .bar { width: 100px; }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 80px 1fr; }
  .app-side { padding: 8px; }
  .app-side .bot-card .name { font-size: 10px; }
  .app-main-wrap { grid-template-columns: 44px 1fr 0; }
  .right-actions { display: none; }
  .stat-item .bar { width: 80px; }
  .stat-item.kamas .value { font-size: 12px; }
  .config-row { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .app-shell { grid-template-columns: 0 1fr; }
  .app-side { display: none; }
  .stats-bar { flex-wrap: wrap; gap: 8px; padding: 6px 10px; font-size: 10px; }
  .stat-item .bar { width: 60px; height: 14px; }
}
