/* ============================================
   NeonCPP · iPad-style Split View Layout
   ============================================ */

:root {
  --bg-0: #05070d;
  --bg-1: #0a0e1a;
  --bg-2: #0f1525;
  --bg-3: #141b30;
  --line: #1c2542;
  --line-2: #243056;
  --text: #d6e1ff;
  --text-dim: #8593b8;
  --text-mute: #5a6890;
  --neon-cyan: #00f0ff;
  --neon-blue: #2b6cff;
  --neon-purple: #a855f7;
  --neon-pink: #ff2bd6;
  --neon-green: #00ff9c;
  --neon-amber: #ffb800;
  --danger: #ff4757;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-0);
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
}

/* ====== 背景层 ====== */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: #0a0e1a;
  overflow: hidden;
}
.bg-layer::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(43, 108, 255, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(43, 108, 255, .04) 1px, transparent 1px);
  background-size: 50px 50px;
  mask-image: radial-gradient(ellipse at center, black 0%, transparent 80%);
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: .25;
  animation: floatOrb 20s ease-in-out infinite;
}
.orb-1 { width: 400px; height: 400px; background: #00f0ff; top: -200px; left: -100px; }
.orb-2 { width: 500px; height: 500px; background: #a855f7; bottom: -200px; right: -100px; animation-delay: -7s; }
.orb-3 { width: 300px; height: 300px; background: #ff2bd6; top: 40%; left: 50%; opacity: .15; animation-delay: -14s; }
@keyframes floatOrb {
  0%, 100% { transform: translate(0,0); }
  50%      { transform: translate(40px, -30px); }
}
.scanline {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(180deg, transparent 0px, transparent 2px, rgba(0, 240, 255, .008) 3px, transparent 4px);
  pointer-events: none;
}

/* ====== 主框架 (3 行: 标题栏 / 主体 / 底部) ====== */
.app {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}

/* ====== 标题栏 (iPad 紧凑风格) ====== */
.titlebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 8px;
  background: rgba(15, 21, 37, .9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(20px);
  position: relative;
}
.titlebar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--neon-cyan), var(--neon-purple), transparent);
  opacity: .5;
}

.tb-left, .tb-right {
  display: flex;
  align-items: center;
  gap: 2px;
}
.tb-right { justify-content: flex-end; }
.tb-center {
  display: flex;
  gap: 4px;
}

.tb-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 16px;
  transition: all .15s;
}
.tb-icon:hover:not(:disabled) {
  background: rgba(43, 108, 255, .12);
  color: var(--neon-cyan);
}
.tb-icon:disabled { opacity: .35; cursor: not-allowed; }

.tb-select {
  background: rgba(20, 27, 48, .8);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  font-weight: 500;
}
.tb-select:focus { border-color: var(--neon-cyan); }

.file-name {
  font-size: 13px;
  color: var(--text);
  font-family: 'JetBrains Mono', 'Cascadia Code', monospace;
  padding: 0 6px;
  margin: 0 4px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 4px;
  height: 26px;
  display: flex;
  align-items: center;
  min-width: 80px;
}

.btn-run-tb {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px;
  height: 32px;
  background: linear-gradient(135deg, #00ff9c, #00d97c);
  color: #001a10;
  font-weight: 700;
  font-size: 13px;
  border-radius: 6px;
  border: none;
  margin: 0 4px;
  letter-spacing: 1px;
  transition: all .15s;
  box-shadow: 0 0 12px rgba(0, 255, 156, .35);
}
.btn-run-tb:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 18px rgba(0, 255, 156, .6);
}
.btn-run-tb:disabled { opacity: .4; cursor: not-allowed; }
.btn-run-tb .play-icon { font-size: 11px; }

/* ====== 主体: 左右分屏 ====== */
.main {
  display: grid;
  grid-template-columns: 1fr 6px 1fr;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.left-pane {
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 200px;
  position: relative;
}
#editor {
  flex: 1;
  min-height: 0;
}

/* 分隔条 */
.splitter {
  background: var(--line);
  cursor: col-resize;
  position: relative;
  transition: background .15s;
}
.splitter::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 30px;
  background: var(--line-2);
  border-radius: 1px;
  transition: all .2s;
}
.splitter:hover, .splitter.dragging {
  background: var(--neon-cyan);
}
.splitter:hover::before, .splitter.dragging::before {
  background: var(--neon-cyan);
  box-shadow: 0 0 8px var(--neon-cyan);
}

/* 右侧 webview */
.right-pane {
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 200px;
}
.main.webview-collapsed {
  grid-template-columns: 1fr 6px 0;
}
.main.webview-collapsed .right-pane { display: none; }
.main.webview-collapsed .splitter { display: none; }

.webview-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: linear-gradient(180deg, rgba(15, 21, 37, .95), rgba(10, 14, 26, .9));
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.wv-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: rgba(20, 27, 48, .8);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  transition: all .15s;
}
.wv-btn:hover:not(:disabled) {
  background: rgba(0, 240, 255, .1);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
}
.wv-btn:disabled { opacity: .3; cursor: not-allowed; }
.wv-go {
  background: linear-gradient(135deg, #00ff9c, #00d97c);
  color: #001a10;
  border: none;
  font-weight: 700;
}
.wv-go:hover { box-shadow: 0 0 12px rgba(0, 255, 156, .5); }

.webview-url {
  flex: 1;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 10px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  outline: none;
  min-width: 0;
}
.webview-url:focus { border-color: var(--neon-cyan); }
.webview-url::placeholder { color: var(--text-mute); }

.webview-host {
  flex: 1;
  position: relative;
  background: #fff;
  overflow: hidden;
}
#webview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
  display: block;
}

.webview-blocked {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2));
  display: grid;
  place-items: center;
  padding: 20px;
}
.blocked-card {
  max-width: 500px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
}
.blocked-icon { font-size: 48px; margin-bottom: 8px; }
.blocked-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--neon-amber);
}
.blocked-card p {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.6;
  margin: 6px 0;
}
.blocked-card code {
  background: rgba(0, 240, 255, .1);
  color: var(--neon-cyan);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.webview-blocked-url {
  color: var(--neon-cyan) !important;
  font-family: 'JetBrains Mono', monospace;
  word-break: break-all;
  font-size: 11px !important;
  padding: 6px 10px;
  background: var(--bg-0);
  border-radius: 4px;
  margin: 10px 0 !important;
}
.blocked-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

/* ====== 底部面板 (3 栏: 样例 / 输出 / 关键字) ====== */
.bottom-pane {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 240px;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: transform .25s;
  z-index: 10;
}
.bottom-pane.collapsed { transform: translateY(calc(100% - 32px)); }

.bp-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  height: 32px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.bp-toggle {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 14px;
  border-radius: 4px;
}
.bp-toggle:hover { background: var(--bg-3); color: var(--neon-cyan); }
.bp-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.bp-status {
  font-size: 11px;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}
.bp-spacer { flex: 1; }

.bp-content {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 240px;
  gap: 1px;
  background: var(--line);
  overflow: hidden;
  min-height: 0;
}
.bottom-pane.collapsed .bp-content { display: none; }

/* 样例栏 */
.bp-samples {
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.bp-samples-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.bp-mini {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
}
.bp-mini:hover { border-color: var(--neon-cyan); color: var(--neon-cyan); }

.bp-samples-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 8px 0;
  overflow-x: auto;
  flex-shrink: 0;
}
.bp-samples-tabs::-webkit-scrollbar { height: 4px; }
.bp-samples-tabs::-webkit-scrollbar-thumb { background: var(--line-2); }
.sample-tab {
  padding: 3px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  position: relative;
}
.sample-tab:hover { color: var(--text); }
.sample-tab.active {
  background: var(--bg-1);
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
}
.sample-tab .x {
  margin-left: 6px;
  color: var(--text-mute);
  font-size: 12px;
}
.sample-tab .x:hover { color: var(--danger); }

.bp-input {
  flex: 1;
  background: var(--bg-0);
  color: var(--text);
  border: none;
  padding: 8px 12px;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  resize: none;
  outline: none;
  user-select: text;
}
.bp-input::placeholder { color: var(--text-mute); font-style: italic; }
.bp-input:focus { background: var(--bg-1); }

.bp-samples-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  font-size: 10.5px;
  color: var(--text-mute);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  font-family: 'JetBrains Mono', monospace;
}

/* 输出栏 */
.bp-output {
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.bp-tabs {
  display: flex;
  gap: 1px;
  background: var(--bg-2);
  padding: 0 4px;
  flex-shrink: 0;
}
.bp-tab {
  padding: 5px 14px;
  font-size: 11.5px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  transition: all .15s;
}
.bp-tab:hover { color: var(--text); }
.bp-tab.active {
  color: var(--neon-cyan);
  border-bottom-color: var(--neon-cyan);
  background: var(--bg-1);
}
.bp-pane {
  flex: 1;
  margin: 0;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  overflow: auto;
  display: none;
  user-select: text;
  min-height: 0;
}
.bp-pane.active { display: block; }
.bp-pane .hint { color: var(--text-mute); font-style: italic; }
.bp-pane .line-stdout { color: var(--text); }
.bp-pane .line-stderr { color: var(--neon-amber); }
.bp-pane .line-success { color: var(--neon-green); }
.bp-pane .line-error { color: var(--danger); }
.bp-pane .line-info { color: var(--neon-cyan); }
.bp-pane::-webkit-scrollbar { width: 8px; height: 8px; }
.bp-pane::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.bp-pane::-webkit-scrollbar-thumb:hover { background: var(--neon-blue); }

/* 关键字栏 */
.bp-keywords {
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.kw-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px;
  overflow: auto;
}
.kw-btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 4px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  transition: all .15s;
}
.kw-btn:hover {
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  background: rgba(0, 240, 255, .08);
  transform: translateY(-1px);
}

/* ====== Modal 设置面板 ====== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 100;
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  width: min(640px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 240, 255, .15);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-3);
}
.modal-head h3 {
  margin: 0;
  font-size: 15px;
  color: var(--text);
  letter-spacing: 1px;
}
.modal-body {
  padding: 16px;
  overflow: auto;
  flex: 1;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.opt-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.opt-block label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: .5px;
}
.select-mini {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  font-family: inherit;
}
.select-mini:focus { border-color: var(--neon-cyan); }

.settings-quick {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.settings-quick h4 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
.quick-btn {
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  text-align: left;
  transition: all .15s;
}
.quick-btn:hover {
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  background: rgba(0, 240, 255, .05);
}

/* ====== 响应式 ====== */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .splitter, .right-pane { display: none; }
  .titlebar { grid-template-columns: auto 1fr auto; }
  .tb-center { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
}
