/* ==========================================================================
   Python 在线练习平台 · 界面样式
   --------------------------------------------------------------------------
   设计语言：
   · 浅色“教学工具”外框（顶栏 / 工具栏 / 状态栏）+ 深色“代码窗口”面板
   · 主色取 Python 蓝（#3776ab → #2563eb → #4f46e5），黄色作为极小面积点缀
   · 圆角 10~16px，柔和分层阴影，克制的动效
   ========================================================================== */

/* ---------- 设计变量 ---------- */
:root {
  /* 品牌 */
  --brand-1: #3776ab;
  --brand-2: #2563eb;
  --brand-3: #4f46e5;
  --py-yellow: #ffd43b;

  /* 浅色界面 */
  --page: #eef1f8;
  --surface: #ffffff;
  --line: #e5e9f2;
  --line-strong: #d8dfec;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;

  /* 深色代码面板 */
  --code-bg: #0d1526;
  --code-bg-2: #0a111e;
  --code-title: #141e33;
  --code-line: #1b2740;
  --code-text: #cbd6e8;
  --code-muted: #8fa0ba;

  /* 语义色 */
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 9px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 14px 30px -26px rgba(15, 23, 42, .55);
  --shadow-lg: 0 24px 50px -32px rgba(15, 23, 42, .85);

  --font-sans: "Segoe UI Variable Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas,
    "Liberation Mono", Menlo, monospace;

  --ease: cubic-bezier(.2, .7, .3, 1);

  /* 底部状态栏高度（固定定位，缩放时始终贴底） */
  --statusbar-h: 42px;
}

/* ---------- 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
::selection { background: rgba(37, 99, 235, .18); }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background .16s, border-color .16s, color .16s,
              box-shadow .16s, transform .12s, filter .16s;
}
.btn:focus-visible {
  outline: 2px solid rgba(37, 99, 235, .55);
  outline-offset: 2px;
}
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn.primary {
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, var(--brand-1) 0%, var(--brand-2) 55%, var(--brand-3) 100%);
  box-shadow: 0 10px 22px -12px rgba(37, 99, 235, .85),
              inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn.primary:hover:not(:disabled) {
  filter: brightness(1.07);
  transform: translateY(-1px);
  box-shadow: 0 16px 28px -14px rgba(37, 99, 235, .9),
              inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn.primary:active:not(:disabled) { transform: translateY(0); }
.btn.primary:disabled {
  background: linear-gradient(135deg, #a7b9d6, #b3bfe0);
  box-shadow: none;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.btn.ghost {
  color: #56657c;
  background: #fff;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.btn.ghost:hover:not(:disabled) {
  color: #1e3a8a;
  background: #f7f9ff;
  border-color: #b9c6f5;
}
.btn.ghost:disabled {
  color: #b3bdd0;
  background: #fbfcfe;
  border-color: #e9eef7;
  box-shadow: none;
  cursor: not-allowed;
}

/* ==========================================================================
   登录视图
   ========================================================================== */
#loginView {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* 用 padding 垂直居中，内容过高时也不会裁掉顶部 */
  padding: max(20px, calc(50vh - 250px)) 18px 36px;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(1000px 700px at 8% -10%, rgba(56, 189, 248, .32), transparent 62%),
    radial-gradient(900px 720px at 96% 108%, rgba(124, 58, 237, .46), transparent 62%),
    linear-gradient(135deg, #07142c 0%, #0e2a63 48%, #241a6b 100%);
}
#loginView[hidden] { display: none; }

/* 淡网格纹理 */
#loginView::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: 58px 58px;
  -webkit-mask-image: radial-gradient(ellipse 75% 65% at 50% 45%, #000 25%, transparent 78%);
  mask-image: radial-gradient(ellipse 75% 65% at 50% 45%, #000 25%, transparent 78%);
}

/* 漂浮光斑 */
#loginView::after {
  content: "";
  position: absolute;
  z-index: 0;
  top: -140px;
  right: -100px;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  pointer-events: none;
  opacity: .55;
  filter: blur(80px);
  background:
    radial-gradient(circle at 32% 32%, #38bdf8, transparent 62%),
    radial-gradient(circle at 70% 68%, #a855f7, transparent 62%);
  animation: drift 20s ease-in-out infinite alternate;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 392px;
  padding: 40px 36px 30px;
  text-align: center;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, .72);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
  box-shadow:
    0 44px 90px -34px rgba(2, 8, 32, .9),
    inset 0 1px 0 rgba(255, 255, 255, .9);
  animation: cardIn .55s var(--ease) both;
}

.login-logo {
  position: relative;
  width: 62px;
  height: 62px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 19px;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.03em;
  background: linear-gradient(145deg, #4a90d9 0%, var(--brand-1) 42%, var(--brand-2) 100%);
  box-shadow: 0 16px 34px -14px rgba(37, 99, 235, .85),
              inset 0 1px 0 rgba(255, 255, 255, .38);
}
.login-logo::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 20px;
  height: 20px;
  border-radius: 7px;
  border: 3px solid #fff;
  background: linear-gradient(145deg, #ffe066, #ffc61a);
  box-shadow: 0 4px 10px rgba(250, 204, 21, .45);
}

.login-card h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .01em;
  color: #0b1a33;
}
.login-sub {
  margin: 8px 0 26px;
  font-size: 13px;
  color: var(--muted);
}

/* 带图标的输入框 */
.field { position: relative; margin-bottom: 12px; }

.field-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: #9aa8bd;
  pointer-events: none;
  transition: color .18s;
}

.field input {
  width: 100%;
  height: 46px;
  padding: 0 14px 0 43px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #f7f9fd;
  border: 1px solid #e3e9f3;
  border-radius: 12px;
  transition: background .18s, border-color .18s, box-shadow .18s;
}
.field input::placeholder { color: #9aa8bd; }
.field input:hover { border-color: #cfd9e8; }
.field input:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .13);
}
.field:focus-within .field-icon { color: var(--brand-2); }

.login-error {
  min-height: 18px;
  margin: 2px 0 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: #e11d48;
}
.login-error:not(:empty) { animation: shake .4s ease; }

.login-btn {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  font-size: 15px;
  letter-spacing: .12em;
}
.login-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 18px;
  font-size: 12px;
  color: #98a4b8;
}
.login-foot::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #c7d2e2;
}

/* ==========================================================================
   应用视图
   ========================================================================== */
#appView {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* 为固定底部的状态栏预留空间，避免内容被遮挡 */
  padding-bottom: var(--statusbar-h);
  background:
    radial-gradient(900px 420px at 18% -12%, rgba(55, 118, 171, .10), transparent 70%),
    radial-gradient(820px 420px at 88% -8%, rgba(79, 70, 229, .10), transparent 72%),
    linear-gradient(180deg, #f5f7fc 0%, #eaeef7 100%);
}
#appView[hidden] { display: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: relative;
  z-index: 20;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 22px;
  background: rgba(255, 255, 255, .84);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  backdrop-filter: blur(16px) saturate(1.5);
  border-bottom: 1px solid rgba(15, 23, 42, .07);
  box-shadow: 0 8px 28px -26px rgba(15, 23, 42, .7);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.logo {
  position: relative;
  flex: none;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.03em;
  background: linear-gradient(145deg, #4a90d9, var(--brand-1) 45%, var(--brand-2));
  box-shadow: 0 10px 22px -12px rgba(37, 99, 235, .9),
              inset 0 1px 0 rgba(255, 255, 255, .35);
}
.logo::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 12px;
  height: 12px;
  border-radius: 4px;
  border: 2px solid #fff;
  background: linear-gradient(145deg, #ffe066, #ffc61a);
}

.brand-text { min-width: 0; }
.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text p {
  margin-top: 2px;
  font-size: 11.5px;
  letter-spacing: .02em;
  color: var(--muted-2);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
}

/* Python 环境状态胶囊 */
.py-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  color: #15803d;
  background: #f0fdf4;
  border: 1px solid #cdefd9;
}
.py-status::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .16);
}
.py-status.checking {
  color: #a16207;
  background: #fffbeb;
  border-color: #fde68a;
}
.py-status.checking::before {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .16);
  animation: pulse 1.4s ease-in-out infinite;
}
.py-status.error {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}
.py-status.error::before {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .16);
}

.user-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 230px;
  min-width: 0;
  height: 30px;
  padding: 0 13px 0 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #f8fafc;
  border: 1px solid #e6eaf3;
}
.user-name::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #cbd5e1, #64748b 72%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .7);
}

.logout-btn {
  min-height: 30px;
  height: 30px;
  padding: 0 13px;
  border-radius: 9px;
  font-size: 12.5px;
}

/* 角色标签：管理员 / 教师 / 用户 */
.role-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.role-badge[hidden] { display: none; }
.role-badge.is-admin { color: #4338ca; background: #eef2ff; border-color: #dfe3ff; }
.role-badge.is-teacher { color: #1d4ed8; background: #eff6ff; border-color: #dbeafe; }
.role-badge.is-user { color: #0f766e; background: #f0fdfa; border-color: #ccfbf1; }
.role-badge.is-test { color: #b45309; background: #fffbeb; border-color: #fde68a; }

/* ---------- 工具栏 ---------- */
.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 22px 0;
  padding: 8px 9px 8px 15px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(15, 23, 42, .07);
  border-radius: 14px;
  box-shadow: var(--shadow-sm), var(--shadow-md);
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.toolbar-left .btn.ghost { min-height: 34px; padding: 0 13px; font-size: 13px; }

.example-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

select {
  height: 34px;
  min-width: 128px;
  max-width: 250px;
  padding: 0 34px 0 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background-color: #fff;
  background-image:
    linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position:
    calc(100% - 17px) calc(50% + 1px),
    calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s;
}
select:hover { border-color: #b9c6f5; }
select:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  color: var(--muted-2);
  white-space: nowrap;
}
.kbd-plus { color: #cbd5e1; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: #475569;
  background: #fff;
  border: 1px solid #dfe6f1;
  border-bottom-width: 2px;
  border-radius: 5px;
}

.run-btn {
  height: 38px;
  min-height: 38px;
  padding: 0 22px;
  border-radius: 11px;
  font-size: 14px;
  letter-spacing: .02em;
}

/* ---------- 主工作区 ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  padding: 14px 22px 10px;
}

.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--code-bg);
  border: 1px solid #172037;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, .04);
  animation: paneIn .45s var(--ease) both;
}
.output-pane { animation-delay: .07s; }

.pane-title {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--code-muted);
  background: linear-gradient(180deg, var(--code-title) 0%, #101a2d 100%);
  border-bottom: 1px solid var(--code-line);
  user-select: none;
  -webkit-user-select: none;
}
.pane-name { color: #c3cee0; }

.pane-tag {
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  color: #8ea1bd;
  background: rgba(148, 163, 184, .1);
  border: 1px solid rgba(148, 163, 184, .16);
}

.pane-dots { display: inline-flex; align-items: center; gap: 6px; margin-right: 2px; }
.pane-dots i { display: block; width: 9px; height: 9px; border-radius: 50%; }
.pane-dots i:nth-child(1) { background: #f87171; }
.pane-dots i:nth-child(2) { background: #fbbf24; }
.pane-dots i:nth-child(3) { background: #34d399; }

.pane-led {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, .15);
  animation: pulse 2.6s ease-in-out infinite;
}

/* ---------- 代码编辑器（CodeMirror 深色主题） ---------- */
/* 原生 textarea 仅作为 CodeMirror 初始化前的降级外观 */
.editor-pane textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 14px 16px;
  border: 0;
  resize: none;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: var(--code-text);
  background: transparent;
  tab-size: 4;
}
.editor-pane textarea:focus { outline: none; }

.editor-pane .CodeMirror {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: var(--code-text);
  background: transparent;
}
.editor-pane .CodeMirror-scroll { height: 100%; }
.editor-pane .CodeMirror-gutter-filler,
.editor-pane .CodeMirror-scrollbar-filler { background-color: transparent; }
.editor-pane .CodeMirror-gutters {
  background: #0b1222;
  border-right: 1px solid #182339;
}
.editor-pane .CodeMirror-linenumber {
  padding: 0 12px 0 14px;
  font-size: 12.5px;
  color: #4f5f7a;
}
.editor-pane .CodeMirror-lines { padding: 12px 0; }
.editor-pane .CodeMirror pre.CodeMirror-line,
.editor-pane .CodeMirror pre.CodeMirror-line-like { padding: 0 12px 0 10px; }

.editor-pane .CodeMirror-cursor { border-left: 2px solid #7dd3fc; }
.editor-pane .CodeMirror-secondarycursor { border-left: 1px solid #64748b; }
.editor-pane .CodeMirror-selected { background: rgba(56, 189, 248, .2); }
.editor-pane .CodeMirror-focused .CodeMirror-selected { background: rgba(56, 189, 248, .26); }
.editor-pane .CodeMirror-line::selection,
.editor-pane .CodeMirror-line > span::selection,
.editor-pane .CodeMirror-line > span > span::selection { background: rgba(56, 189, 248, .26); }
.editor-pane .CodeMirror-line::-moz-selection,
.editor-pane .CodeMirror-line > span::-moz-selection,
.editor-pane .CodeMirror-line > span > span::-moz-selection { background: rgba(56, 189, 248, .26); }

.editor-pane .CodeMirror-activeline-background { background: rgba(148, 163, 184, .055); }
.editor-pane .CodeMirror-activeline-gutter { background: #0e1727; }
.editor-pane .CodeMirror-matchingbracket {
  color: #fcd34d !important;
  background: rgba(252, 211, 77, .12);
  border-bottom: 1px solid rgba(252, 211, 77, .55);
}
.editor-pane .CodeMirror-nonmatchingbracket { color: #fb7185 !important; }

.editor-pane .CodeMirror .cm-keyword { color: #c792ea; }
.editor-pane .CodeMirror .cm-atom { color: #ffcb6b; }
.editor-pane .CodeMirror .cm-number { color: #f78c6c; }
.editor-pane .CodeMirror .cm-def { color: #82aaff; }
.editor-pane .CodeMirror .cm-builtin { color: #82aaff; }
.editor-pane .CodeMirror .cm-variable { color: #d7e0f2; }
.editor-pane .CodeMirror .cm-variable-2 { color: #bcd0f7; }
.editor-pane .CodeMirror .cm-variable-3 { color: #f07178; }
.editor-pane .CodeMirror .cm-type { color: #f07178; }
.editor-pane .CodeMirror .cm-property { color: #80cbc4; }
.editor-pane .CodeMirror .cm-operator { color: #89ddff; }
.editor-pane .CodeMirror .cm-comment { color: #6b7d99; font-style: italic; }
.editor-pane .CodeMirror .cm-string { color: #ecc48d; }
.editor-pane .CodeMirror .cm-string-2 { color: #ecc48d; }
.editor-pane .CodeMirror .cm-meta { color: #7fdbca; }
.editor-pane .CodeMirror .cm-qualifier { color: #decb6b; }
.editor-pane .CodeMirror .cm-bracket { color: #a6accd; }
.editor-pane .CodeMirror .cm-tag { color: #f07178; }
.editor-pane .CodeMirror .cm-attribute { color: #ffcb6b; }
.editor-pane .CodeMirror .cm-link { color: #82aaff; }
.editor-pane .CodeMirror .cm-error { color: #f87171; background: rgba(248, 113, 113, .12); }

/* ---------- 标准输入 ---------- */
.stdin-row {
  flex: none;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  background: #0f1a2e;
  border-bottom: 1px solid var(--code-line);
}
.stdin-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8395b1;
  white-space: nowrap;
}
.stdin-row label::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #3b82f6;
}
.stdin-row input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 11px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: #cbd5e1;
  background: #0a1322;
  border: 1px solid #22304b;
  border-radius: 8px;
  transition: background .16s, border-color .16s, box-shadow .16s;
}
.stdin-row input::placeholder { color: #667892; }
.stdin-row input:hover { border-color: #2c3d5c; }
.stdin-row input:focus {
  outline: none;
  background: #0b1526;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .18);
}

/* ---------- 输出 ---------- */
.output {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 14px 16px 22px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  color: #c8d3e6;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .015), transparent 140px),
    var(--code-bg-2);
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: #2b3a55 transparent;
}
.output:empty::before {
  content: "运行结果会显示在这里…";
  color: #667892;
  font-style: italic;
}
.output .err { color: #fda4af; }
.output .sys-msg { color: #6c7f9c; font-style: italic; }
.output .ok-mark { color: #4ade80; }
.output .warn-mark { color: #fbbf24; }

/* 深色区域滚动条 */
.editor-pane .CodeMirror-scroll::-webkit-scrollbar,
.output::-webkit-scrollbar { width: 11px; height: 11px; }
.editor-pane .CodeMirror-scroll::-webkit-scrollbar-track,
.output::-webkit-scrollbar-track { background: transparent; }
.editor-pane .CodeMirror-scroll::-webkit-scrollbar-thumb,
.output::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, .26);
  background-clip: content-box;
  border: 3px solid transparent;
  border-radius: 99px;
}
.editor-pane .CodeMirror-scroll::-webkit-scrollbar-thumb:hover,
.output::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, .42);
  background-clip: content-box;
}

/* 浅色区域滚动条 */
#loginView,
.workspace { scrollbar-width: thin; scrollbar-color: #c3ccdb transparent; }
#loginView::-webkit-scrollbar,
.workspace::-webkit-scrollbar { width: 10px; height: 10px; }
#loginView::-webkit-scrollbar-track,
.workspace::-webkit-scrollbar-track { background: transparent; }
#loginView::-webkit-scrollbar-thumb,
.workspace::-webkit-scrollbar-thumb {
  background: #c3ccdb;
  background-clip: content-box;
  border: 3px solid transparent;
  border-radius: 99px;
}

/* ---------- 状态栏 ---------- */
/* 固定在页面最底部：无论内容多长、窗口缩放多少，始终贴在视口底部 */
.statusbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: var(--statusbar-h);
  padding: 0 22px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border-top: 1px solid rgba(15, 23, 42, .07);
  box-shadow: 0 -8px 24px -22px rgba(15, 23, 42, .8);
}
#statusText {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#statusText::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .14);
}
.copyright {
  flex: none;
  text-align: center;
  font-size: 11.5px;
  color: #a2adc0;
  white-space: nowrap;
}
#runInfo {
  flex: none;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #8d9ab0;
  white-space: nowrap;
}

/* ---------- 保存预设弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: rgba(6, 12, 26, .55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.modal-mask[hidden] { display: none; }
.modal-mask:not([hidden]) { animation: fadeIn .18s ease; }

.modal {
  width: 100%;
  max-width: 420px;
  padding: 26px 28px 22px;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: 18px;
  box-shadow: 0 40px 90px -30px rgba(2, 8, 32, .8);
}
.modal-mask:not([hidden]) .modal { animation: modalIn .24s var(--ease) both; }

.modal h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16.5px;
  font-weight: 700;
  color: #0b1a33;
}
.modal h3::before {
  content: "";
  width: 4px;
  height: 17px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--brand-1), var(--brand-3));
}
.modal-tip {
  margin: 9px 0 16px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}
.modal input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #f7f9fd;
  border: 1px solid #e3e9f3;
  border-radius: 11px;
  transition: background .18s, border-color .18s, box-shadow .18s;
}
.modal input::placeholder { color: #9aa8bd; }
.modal input:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .13);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions .btn { min-height: 38px; }

/* ==========================================================================
   动效
   ========================================================================== */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(.985); }
  to { opacity: 1; transform: none; }
}
@keyframes paneIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(.975); }
  to { opacity: 1; transform: none; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  55% { transform: translateX(4px); }
  80% { transform: translateX(-2px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(-60px, 50px, 0) scale(1.12); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ==========================================================================
   响应式
   ========================================================================== */
@media (max-width: 1180px) {
  .kbd-hint { display: none; }
}

@media (max-width: 1024px) {
  .topbar { padding: 0 16px; }
  .py-status { padding: 0 10px; font-size: 11.5px; }
  .user-name { max-width: 170px; }
  .toolbar { margin: 12px 16px 0; padding-left: 12px; }
  .workspace { padding: 12px 16px 8px; gap: 12px; }
  .statusbar { padding: 0 16px; gap: 10px; }
  .run-btn { padding: 0 18px; }
}

@media (max-width: 900px) {
  .workspace {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding-bottom: 14px;
  }
  .editor-pane { flex: 0 0 auto; height: 56vh; min-height: 320px; }
  .output-pane { flex: 0 0 auto; height: 46vh; min-height: 280px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-right { margin-left: auto; }
  .toolbar-left { flex: 1 1 100%; }
  select { max-width: none; flex: 1 1 160px; }
}

@media (max-width: 640px) {
  :root { --statusbar-h: 34px; }
  .topbar { height: 58px; padding: 0 12px; gap: 10px; }
  .logo { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
  .brand-text h1 { font-size: 14.5px; }
  .brand-text p { display: none; }
  .py-status { height: 28px; padding: 0 9px; font-size: 11px; }
  .user-name { max-width: 120px; height: 28px; font-size: 12px; }
  .logout-btn { height: 28px; min-height: 28px; padding: 0 10px; }

  .toolbar { margin: 10px 12px 0; padding: 8px 9px; }
  .toolbar-left { gap: 6px; }
  .toolbar-left .btn.ghost { padding: 0 10px; font-size: 12.5px; }
  .example-label { display: none; }
  .workspace { padding: 10px 12px 8px; gap: 10px; }
  .statusbar { padding: 0 12px; font-size: 11.5px; }

  /* 移动端工具栏：示例选择占一行，按钮占一行，运行按钮整行 */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar-left { flex: none; width: 100%; }
  .toolbar-left .btn.ghost { flex: 1 1 auto; }
  .toolbar-right { margin-left: 0; width: 100%; }
  select { flex: 1 1 100%; min-width: 0; max-width: none; }
  .run-btn { width: 100%; }

  .login-card { padding: 32px 22px 24px; border-radius: 18px; }
  .login-card h1 { font-size: 18px; }
  .login-logo { width: 56px; height: 56px; font-size: 24px; margin-bottom: 16px; }
}

@media (max-width: 520px) {
  .py-status { display: none; }
}
