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

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #151515;
  color: #abb2bf;
}

/* ── Login Overlay ────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #151515;
  z-index: 1000;
}

#login-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px;
  width: 300px;
}

#login-title {
  font-size: 24px;
  font-weight: 700;
  color: #e0e0e0;
  text-align: center;
  margin-bottom: 8px;
}

#login-password {
  padding: 12px 14px;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  background: #0e0e0e;
  color: #e0e0e0;
  font-size: 15px;
  outline: none;
}

#login-password:focus {
  border-color: #555;
}

#login-btn {
  padding: 12px;
  border: none;
  border-radius: 6px;
  background: #e0e0e0;
  color: #151515;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#login-btn:hover {
  background: #fff;
}

#login-error {
  color: #e06c75;
  font-size: 13px;
  text-align: center;
}

/* ── App ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Floating Controls ────────────────────────────── */
#floating-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

#floating-controls > *, #floating-right > * {
  pointer-events: auto;
}

#floating-right {
  position: absolute;
  right: 12px;
  top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.floating-btn, #btn-send {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid rgba(69, 71, 90, 0.8);
  border-radius: 6px;
  background: rgba(21, 21, 21, 0.85);
  color: #abb2bf;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.floating-btn:hover, #btn-send:hover {
  background: rgba(69, 71, 90, 0.9);
}

.floating-btn.active {
  background: rgba(97, 175, 239, 0.9);
  color: #151515;
  border-color: #61afef;
}

#btn-split {
  border-radius: 0 0 6px 6px;
  border-top: none;
}

#lang-select {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid rgba(69, 71, 90, 0.8);
  border-radius: 6px;
  background: rgba(21, 21, 21, 0.85);
  color: #abb2bf;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#connection-status {
  font-size: 12px;
  color: #e06c75;
  transition: color 0.3s;
}

#connection-status.connected {
  color: #98c379;
}

/* ── Shared code font ────────────────────────────── */
:root {
  --code-font: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --code-size: 16px;
  --code-lh: 1.35;
  --code-pad: 16px;
}

/* ── Code Container ──────────────────────────────── */
#code-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.code-panel {
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Shiki output styling */
.shiki-output {
  height: 100%;
}

.shiki-output pre {
  margin: 0;
  min-height: 100%;
  background: #151515 !important;
}

.shiki-output code {
  display: block;
  padding: var(--code-pad);
  font-family: var(--code-font);
  font-size: var(--code-size);
  line-height: var(--code-lh);
  tab-size: 4;
  white-space: pre;
}

.shiki-output code .line:last-child:empty {
  display: none;
}

/* Fallback when shiki hasn't loaded */
.shiki-output pre.fallback {
  padding: var(--code-pad);
  font-family: var(--code-font);
  font-size: var(--code-size);
  line-height: var(--code-lh);
  tab-size: 4;
  white-space: pre;
  color: #abb2bf;
}

#code-single {
  height: 100%;
}

/* Split view */
.split-panels {
  display: flex;
  height: 100%;
  gap: 2px;
}

.split-left, .split-right {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.split-left {
  border-right: 2px solid #2a2a2a;
}

/* ── Editor (overlay technique) ──────────────────── */
#editor-wrap {
  position: absolute;
  inset: 0;
  display: flex;
}


#editor-area {
  flex: 3;
  position: relative;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#editor-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 100%;
  pointer-events: none;
}

#code-editor {
  position: relative;
  display: block;
  width: 100%;
  min-height: 100%;
  padding: var(--code-pad);
  background: transparent;
  color: transparent;
  caret-color: #528bff;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--code-font);
  font-size: var(--code-size);
  line-height: var(--code-lh);
  tab-size: 4;
  white-space: pre;
  overflow: hidden;
}

#code-editor::selection {
  background: rgba(97, 175, 239, 0.3);
}

/* ── Chat Panel (edit mode only) ─────────────────── */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #b0b8c4;
  background: #e0e4ea;
  min-width: 0;
}

#chat-panel-header {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #4a5568;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #b0b8c4;
  flex-shrink: 0;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  padding: 6px 10px;
  border-radius: 6px;
  background: #ffffff;
  color: #1a1a1a;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
}

/* ── Chat Bar ────────────────────────────────────── */
#chat-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: #d8dce3;
  border-top: 1px solid #b0b8c4;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  min-height: 44px;
  padding: 8px 14px;
  border: none;
  border-radius: 0;
  background: #d8dce3;
  color: #1a1a1a;
  font-size: 14px;
  outline: none;
  touch-action: manipulation;
}

#chat-input:focus {
  background: #e8ecf0;
}

#chat-input::placeholder {
  color: #6b7280;
}

#btn-send {
  border: none;
  border-left: 1px solid #b0b8c4;
  border-radius: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: #d8dce3;
  color: #1a1a1a;
}

/* Toast */
#chat-toast {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: #2a2a2a;
  color: #abb2bf;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 13px;
  max-width: 80%;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 100;
}

#chat-toast.show {
  opacity: 1;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 600px) {
  .split-panels {
    flex-direction: column;
  }

  .split-left {
    border-right: none;
    border-bottom: 2px solid #2a2a2a;
  }

  :root {
    --code-size: 13px;
  }

  .floating-btn, #btn-send {
    padding: 6px 10px;
    font-size: 14px;
  }
}
