:root {
  --bg-app: #0a0f0c;
  --bg-wrapper: rgba(6, 10, 8, 0.94);
  --glass-border: rgba(74, 122, 90, 0.08);
  --glass-glow: rgba(74, 122, 90, 0.04);
  --pane-bg: rgba(4, 7, 5, 0.85);
  --pane-border: rgba(61, 90, 78, 0.1);
  --pane-active-border: rgba(122, 168, 138, 0.3);
  --pane-header-bg: rgba(255, 255, 255, 0.015);
  --pane-header-text: rgba(168, 197, 181, 0.25);
  --accent: #4a7a5a;
  --accent-bright: #7aa88a;
  --accent-dim: rgba(74, 122, 90, 0.2);
  --accent-dark: #0a0f0c;
  --status-bg: #2d4a3e;
  --status-active-bg: #4a7a5a;
  --status-text: #a8c5b5;
  --status-fg: #d0e8d8;
  --pane-border-color: #3d5a4e;
  --pane-active-border-color: #7aa88a;
  --text: #d0e8d8;
  --text-bright: #e8f5ee;
  --text-dim: rgba(168, 197, 181, 0.3);
  --line-num: rgba(168, 197, 181, 0.15);
  --line-num-active: rgba(208, 232, 216, 0.4);
  --active-line-bg: rgba(74, 122, 90, 0.06);
  --scrollbar-bg: transparent;
  --scrollbar-thumb: rgba(74, 122, 90, 0.1);

  --token-keyword: #7aa88a;
  --token-string: #a8c5b5;
  --token-comment: #3d5a4e;
  --token-number: #d0e8d8;
  --token-builtin: #c8e6d0;
  --token-operator: #8ab89a;
  --token-punctuation: #b8d5c5;
  --token-decorator: #5a9a6a;
  --token-variable: #b8d5c5;
  --token-heading: #7aa88a;
  --token-bold: #e8f5ee;
  --token-italic: #d0e8d8;
  --token-code: #a8c5b5;
  --token-link: #8ab89a;
  --token-list: #7aa88a;
  --token-constant: #c8e6d0;
  --token-key: #8ab89a;

  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  font-family: var(--font-ui);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5vh 5vw;
  padding-top: calc(5vh + var(--safe-top));
  padding-bottom: calc(5vh + var(--safe-bottom));
  background:
    radial-gradient(ellipse at 20% 50%, rgba(74, 122, 90, 0.025) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(122, 168, 138, 0.02) 0%, transparent 50%),
    var(--bg-app);
}

.terminal-wrapper {
  width: 90vw;
  height: 90vh;
  max-width: 1600px;
  max-height: 1200px;
  display: flex;
  flex-direction: column;
  background: var(--bg-wrapper);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 0 60px var(--glass-glow),
    0 0 120px rgba(74, 122, 90, 0.02),
    0 8px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.tmux-panes {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--pane-bg);
  border-right: 1px solid var(--pane-border);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pane:last-child {
  border-right: none;
}

.pane.pane-active {
  border-color: var(--pane-active-border);
}

.pane.pane-focused {
  box-shadow: inset 0 0 20px rgba(74, 122, 90, 0.04);
}

.pane-active .pane-header {
  border-bottom-color: rgba(122, 168, 138, 0.25);
}

.pane-active .pane-header-title {
  color: var(--accent-bright);
}

.pane-active .pane-header-icon {
  opacity: 1;
  color: var(--accent-bright);
}

.pane:not(.pane-active) .neovim-content,
.pane:not(.pane-active) .terminal-viewport {
  opacity: 0.7;
}

.pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--pane-header-bg);
  border-bottom: 1px solid var(--pane-border);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.3px;
  color: var(--pane-header-text);
  user-select: none;
  flex-shrink: 0;
}

.pane-header-icon {
  opacity: 0.5;
}

.pane-header-title {
  font-weight: 600;
  color: var(--text-dim);
}

.pane-header-cwd {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.4;
}

.terminal-viewport,
.neovim-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
  display: flex;
  flex-direction: column;
}

.neovim-viewport:has(.nvim-browser-wrapper) {
  padding: 0;
  overflow: hidden;
}

.terminal-viewport::-webkit-scrollbar,
.neovim-viewport::-webkit-scrollbar {
  width: 6px;
}

.terminal-viewport::-webkit-scrollbar-track,
.neovim-viewport::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}

.terminal-viewport::-webkit-scrollbar-thumb,
.neovim-viewport::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

.terminal-viewport::-webkit-scrollbar-thumb:hover,
.neovim-viewport::-webkit-scrollbar-thumb:hover {
  background: rgba(74, 122, 90, 0.25);
}

.terminal-viewport {
  display: flex;
  flex-direction: column;
}

.terminal-output {
  flex-shrink: 0;
}

.output-line {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.5em;
  color: var(--text);
}

.output-line:empty {
  min-height: 0.5em;
}

.terminal-input-line {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  padding: 4px 0;
  min-height: 1.5em;
}

.prompt {
  display: inline-flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  white-space: pre;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  margin-right: 6px;
  user-select: none;
}

.prompt-path {
  color: var(--text);
}

.prompt-gt {
  color: var(--accent-bright);
  margin-left: 2px;
  font-weight: 600;
}

.input-text {
  color: var(--text-bright);
  white-space: pre;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  caret-color: transparent;
}

.cursor {
  display: inline;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  color: var(--accent-bright);
  text-shadow: 0 0 6px var(--accent-dim);
  opacity: 0.6;
}

.pane-active .cursor {
  animation: cursor-blink 1.06s step-end infinite;
  opacity: 1;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.neovim-content {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}

.neovim-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
  position: relative;
}

.neovim-viewport:has(.nvim-browser-wrapper) {
  padding: 0;
  overflow: hidden;
}

.neovim-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}

.nvim-browser-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font-ui);
  background: #0a0f0c;
  overflow: hidden;
}

.browser-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(74, 122, 90, 0.1);
  flex-shrink: 0;
}

.browser-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}

.browser-dot:hover {
  filter: brightness(1.3);
  transform: scale(1.15);
}

.browser-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.browser-url {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(168, 197, 181, 0.4);
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 10px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browser-content {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.browser-content iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
  background: #0a0f0c;
}

.browser-code-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: rgba(4, 7, 5, 0.6);
}

.browser-code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 20px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

.browser-token {
  white-space: pre;
}

.browser-error {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #ff5f57;
  padding: 40px 24px;
  text-align: center;
  line-height: 1.8;
}

.browser-md-wrapper {
  padding: 24px 28px;
  overflow-y: auto;
  height: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.browser-md-wrapper h1,
.browser-md-wrapper h2,
.browser-md-wrapper h3,
.browser-md-wrapper h4,
.browser-md-wrapper h5,
.browser-md-wrapper h6 {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  margin: 24px 0 12px;
  font-weight: 600;
}

.browser-md-wrapper h1 { font-size: 22px; border-bottom: 1px solid rgba(74,122,90,0.12); padding-bottom: 8px; }
.browser-md-wrapper h2 { font-size: 18px; }
.browser-md-wrapper h3 { font-size: 15px; }
.browser-md-wrapper h4 { font-size: 14px; }

.browser-md-wrapper p {
  margin: 8px 0;
  color: rgba(208,232,216,0.85);
}

.browser-md-wrapper ul,
.browser-md-wrapper ol {
  padding-left: 24px;
  margin: 8px 0;
}

.browser-md-wrapper li {
  margin: 3px 0;
  color: rgba(208,232,216,0.85);
}

.browser-md-wrapper code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(74,122,90,0.12);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent-bright);
}

.browser-md-wrapper pre {
  background: rgba(4,7,5,0.6);
  border: 1px solid rgba(74,122,90,0.08);
  border-radius: 6px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 12px 0;
}

.browser-md-wrapper pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}

.browser-md-wrapper blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 12px 0;
  color: rgba(168,197,181,0.7);
  font-style: italic;
  background: rgba(74,122,90,0.04);
  border-radius: 0 4px 4px 0;
}

.browser-md-wrapper hr {
  border: none;
  border-top: 1px solid rgba(74,122,90,0.1);
  margin: 24px 0;
}

.browser-md-wrapper strong {
  color: var(--text-bright);
  font-weight: 600;
}

.browser-md-wrapper a {
  color: var(--accent-bright);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.browser-md-wrapper a:hover {
  color: var(--text-bright);
}

.browser-table-wrap {
  overflow-x: auto;
  margin: 12px 0;
}

.browser-md-wrapper table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.browser-md-wrapper th,
.browser-md-wrapper td {
  border: 1px solid rgba(74,122,90,0.12);
  padding: 8px 14px;
  text-align: left;
}

.browser-md-wrapper th {
  background: rgba(74,122,90,0.08);
  color: var(--accent-bright);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 12px;
}

.browser-md-wrapper td {
  color: rgba(208,232,216,0.85);
}

.neovim-table tr {
  transition: background 0.1s ease;
}

.neovim-table tr.active-line {
  background: var(--active-line-bg);
}

.line-num {
  color: var(--line-num);
  text-align: right;
  padding: 0 12px 0 4px;
  user-select: none;
  font-size: 12px;
  width: 48px;
  min-width: 48px;
  max-width: 48px;
  vertical-align: top;
  border-right: 1px solid rgba(74, 122, 90, 0.06);
  overflow: hidden;
}

tr.active-line .line-num {
  color: var(--line-num-active);
}

.line-content {
  padding: 0 12px;
  white-space: pre-wrap;
  vertical-align: top;
  word-break: break-all;
  overflow-wrap: break-word;
}

.token-keyword { color: var(--token-keyword); }
.token-string { color: var(--token-string); }
.token-comment { color: var(--token-comment); font-style: italic; }
.token-number { color: var(--token-number); }
.token-builtin { color: var(--token-builtin); }
.token-operator { color: var(--token-operator); }
.token-punctuation { color: var(--token-punctuation); }
.token-decorator { color: var(--token-decorator); }
.token-variable { color: var(--token-variable); }
.token-heading { color: var(--token-heading); font-weight: 700; }
.token-bold { color: var(--token-bold); font-weight: 700; }
.token-italic { color: var(--token-italic); font-style: italic; }
.token-code { color: var(--token-code); background: rgba(168, 197, 181, 0.08); border-radius: 2px; padding: 0 4px; }
.token-link { color: var(--token-link); text-decoration: underline; }
.token-list { color: var(--token-list); }
.token-constant { color: var(--token-constant); }
.token-key { color: var(--token-key); }
.token-text { color: var(--text); }

.lualine {
  display: flex;
  align-items: center;
  height: 22px;
  padding: 0;
  background: rgba(21, 34, 28, 0.6);
  border-top: 1px solid rgba(74, 122, 90, 0.06);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  user-select: none;
}

.lualine-section {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 6px;
}

.lualine-sep {
  color: rgba(74, 122, 90, 0.15);
  padding: 0 2px;
}

.lualine-fill {
  flex: 1;
}

.lualine-mode {
  font-weight: 700;
  letter-spacing: 0.5px;
}

.nvim-cmdline {
  display: none;
  align-items: center;
  height: 22px;
  padding: 0 12px;
  background: rgba(31, 47, 40, 0.9);
  border-top: 1px solid rgba(74, 122, 90, 0.1);
  border-bottom: 1px solid rgba(74, 122, 90, 0.1);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-bright);
  flex-shrink: 0;
  overflow: hidden;
}

.cmdline-prompt {
  color: var(--accent-bright);
  font-weight: 600;
  margin-right: 4px;
  flex-shrink: 0;
}

.cmdline-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmdline-cursor {
  display: inline;
  animation: cursor-blink 1.06s step-end infinite;
  color: var(--accent-bright);
  margin-left: 1px;
}

.cursor-block {
  display: inline-block;
  background: var(--accent-bright);
  color: #1f2f28;
  min-width: 0.6em;
  height: 1.2em;
  line-height: 1.2em;
  vertical-align: text-bottom;
  opacity: 0.6;
}

.pane-active .cursor-block {
  animation: cursor-blink 1.06s step-end infinite;
  opacity: 1;
}

.cursor-nvim {
  display: inline-block;
  width: 0.6em;
  height: 1.2em;
  background: var(--accent-bright);
  vertical-align: text-bottom;
  opacity: 0.6;
}

.pane-active .cursor-nvim {
  animation: cursor-blink 1.06s step-end infinite;
  opacity: 1;
}

.explorer-header {
  color: var(--accent-bright);
  font-weight: 700;
  font-size: 14px;
}

.explorer-dir {
  color: var(--accent);
  font-weight: 600;
}

.explorer-file {
  color: var(--text);
}

.explorer-entry {
  cursor: pointer;
}

.explorer-entry:hover {
  background: rgba(74, 122, 90, 0.08);
}

.tmux-statusline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 24px;
  padding: 0 12px;
  background: var(--status-bg);
  border-top: 1px solid rgba(168, 197, 181, 0.06);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--status-text);
  flex-shrink: 0;
  user-select: none;
}

.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.status-item {
  display: flex;
  align-items: center;
  padding: 0 8px;
  height: 20px;
}

.status-session {
  background: #4a7a5a;
  color: #1f2f28;
  font-weight: 700;
  border-radius: 2px;
  padding: 0 6px;
  cursor: default;
}

.status-window {
  cursor: pointer;
  transition: background 0.15s ease;
  border-radius: 2px;
  padding: 0 5px;
}

.status-window:hover {
  background: rgba(74, 122, 90, 0.15);
}

.status-active {
  background: #4a7a5a;
  color: #1f2f28;
  font-weight: 700;
  border-radius: 2px;
}

.status-active:hover {
  background: #5a8a6a;
}

.status-prefix,
.status-suffix {
  opacity: 0.5;
}

.status-date-item {
  color: var(--text-dim);
  padding: 0 4px;
}

.status-time-item {
  color: var(--status-fg);
  font-weight: 600;
}

.mobile-keyboard {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 5px 4px;
  padding-bottom: calc(5px + var(--safe-bottom));
  background: rgba(31, 47, 40, 0.95);
  border-top: 1px solid rgba(74, 122, 90, 0.06);
  flex-shrink: 0;
}

.kb-strip {
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0;
  flex-shrink: 0;
}

.kb-strip::-webkit-scrollbar {
  display: none;
}

.kb-strip .kb-btn {
  display: inline-flex;
  vertical-align: middle;
}

.kb-btn {
  padding: 6px 10px;
  background: rgba(74, 122, 90, 0.1);
  border: 1px solid rgba(74, 122, 90, 0.12);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.kb-btn:active {
  background: rgba(74, 122, 90, 0.25);
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .terminal-wrapper {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
  }

  #app {
    padding: 0;
  }

  .tmux-panes {
    flex: 1;
    min-height: 0;
  }

  .pane {
    min-height: 0;
  }

  .pane-terminal {
    flex: 1;
    min-height: 0;
  }

  .pane-neovim {
    display: none;
  }

  .pane-neovim.nvim-visible {
    display: flex;
    flex: 1;
    min-height: 0;
  }

  .pane-terminal.terminal-hidden {
    display: none;
  }

  .status-window[data-pane="neovim"] {
    display: none;
  }

  .mobile-keyboard {
    display: block;
  }

  .kb-strip {
    padding: 4px 0;
  }

  .kb-strip .kb-btn {
    min-height: 28px;
    padding: 4px 8px;
    font-size: 11px;
    margin: 0 2px;
  }

  .terminal-viewport {
    font-size: 13px;
    padding: 4px 8px;
  }

  .neovim-viewport {
    font-size: 13px;
    padding: 4px 8px;
  }

  .pane-header {
    padding: 2px 8px;
    font-size: 10px;
    flex-shrink: 0;
  }

  .prompt,
  .input-text,
  .cursor {
    font-size: 12px;
  }

  .tmux-statusline {
    height: 20px;
    padding: 0 6px;
    font-size: 10px;
  }

  .status-host {
    display: none;
  }

  .status-date-item {
    font-size: 10px;
  }

  .status-time-item {
    font-size: 10px;
  }

  .status-item {
    padding: 0 4px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .pane-terminal {
    flex: 1.2;
  }

  .pane-neovim {
    flex: 1;
  }

  .line-num {
    min-width: 36px;
    font-size: 11px;
    padding: 0 10px 0 6px;
  }

  .neovim-content {
    font-size: 12px;
  }
}
