/* ==========================================================================
   EasyRenpy 基础样式：设计变量 + reset + 通用组件
   ========================================================================== */

:root {
  color-scheme: dark;

  /* 背景层次 */
  --bg: #0e1014;
  --bg-panel: #151821;
  --bg-elev: #1b1f2a;
  --bg-inset: #0a0c10;
  --bg-hover: #242a3a;
  --bg-active: #2c3346;
  --canvas-bg: #0b0d11;
  --canvas-dot: rgba(148, 163, 184, 0.13);

  /* 边框 */
  --border: #262b39;
  --border-strong: #3b4358;

  /* 文字 */
  --text: #e7eaf3;
  --text-dim: #9aa3b8;
  --text-faint: #6a7388;

  /* 品牌色 */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-weak: rgba(99, 102, 241, 0.16);
  --accent-text: #c7d2fe;

  /* 语义色 */
  --success: #22c55e;
  --success-weak: rgba(34, 197, 94, 0.14);
  --warn: #f59e0b;
  --warn-weak: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-weak: rgba(239, 68, 68, 0.14);

  /* 尺寸 */
  --topbar-h: 54px;
  --radius-xs: 4px;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 14px;
  --shadow-1: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 16px 48px rgba(0, 0, 0, 0.48);

  /* 字体 */
  --font-ui: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --font-code: "Cascadia Code", "JetBrains Mono", "Fira Code", Consolas, "Courier New", monospace;

  /* 动效 */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* 工作区宽度 */
  --sidebar-w: 232px;
  --inspector-w: 320px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
p {
  margin: 0;
}

a {
  color: var(--accent-hover);
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

::selection {
  background: var(--accent-weak);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: content-box;
  border: 3px solid transparent;
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* ==========================================================================
   按钮
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition:
    background 0.14s var(--ease),
    border-color 0.14s var(--ease),
    color 0.14s var(--ease),
    transform 0.08s var(--ease);
}
.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled,
.btn[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}
.btn svg {
  flex: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: transparent;
}

.btn-outline {
  background: transparent;
}

.btn-danger {
  background: var(--danger-weak);
  border-color: transparent;
  color: #fca5a5;
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
  gap: 4px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text-dim);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.btn-icon.btn-sm {
  width: 26px;
  height: 26px;
}
.btn-icon.active {
  background: var(--accent-weak);
  color: var(--accent-text);
}

.btn-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* ==========================================================================
   表单
   ========================================================================== */

.input,
.select,
.textarea {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition:
    border-color 0.14s var(--ease),
    box-shadow 0.14s var(--ease),
    background 0.14s var(--ease);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
  background: var(--bg-panel);
}
.textarea {
  height: auto;
  min-height: 72px;
  padding: 8px 10px;
  line-height: 1.55;
  resize: vertical;
}
.select {
  appearance: none;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa3b8' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.select option {
  background: var(--bg-elev);
  color: var(--text);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 13px;
}
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}
.field-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
}
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* 开关 */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text-dim);
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  flex: none;
  border-radius: 20px;
  background: var(--border-strong);
  transition: background 0.16s var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s var(--ease);
}
.switch input:checked + .switch-track {
  background: var(--accent);
}
.switch input:checked + .switch-track::after {
  transform: translateX(14px);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 颜色选择行 */
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-swatch {
  position: relative;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-strong);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  background:
    linear-gradient(45deg, #2a2f3d 25%, transparent 25%, transparent 75%, #2a2f3d 75%) 0 0 / 10px 10px,
    linear-gradient(45deg, #2a2f3d 25%, #1a1e28 25%, #1a1e28 75%, #2a2f3d 75%) 5px 5px / 10px 10px;
}
.color-swatch input[type="color"] {
  position: absolute;
  inset: -6px;
  width: 44px;
  height: 44px;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
}

/* ==========================================================================
   面板 / 布局
   ========================================================================== */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 12px;
  flex: none;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}
.spacer {
  flex: 1;
}

/* ==========================================================================
   徽章 / 小件
   ========================================================================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.chip-accent {
  background: var(--accent-weak);
  border-color: transparent;
  color: var(--accent-text);
}
.chip-success {
  background: var(--success-weak);
  border-color: transparent;
  color: #86efac;
}
.chip-warn {
  background: var(--warn-weak);
  border-color: transparent;
  color: #fcd34d;
}
.chip-danger {
  background: var(--danger-weak);
  border-color: transparent;
  color: #fca5a5;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--text-faint);
}
.dot-success {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-weak);
}
.dot-warn {
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-weak);
}
.dot-danger {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-weak);
}
.dot-accent {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--text-dim);
  font-family: var(--font-code);
  font-size: 10px;
  line-height: 1;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1.6;
}
.empty svg {
  opacity: 0.5;
}
.empty-title {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 13px;
}

/* 工具类 */
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.grow {
  flex: 1;
  min-width: 0;
}
.muted {
  color: var(--text-dim);
}
.faint {
  color: var(--text-faint);
}
.small {
  font-size: 12px;
}
.tiny {
  font-size: 11px;
}
.mono {
  font-family: var(--font-code);
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scroll-y {
  overflow-y: auto;
  min-height: 0;
}
.hidden {
  display: none !important;
}
.center {
  text-align: center;
}
.clickable {
  cursor: pointer;
}

/* 通用提示气泡 */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%) translateY(2px);
  padding: 5px 9px;
  border-radius: var(--radius-xs);
  background: #0a0c12;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-1);
  transition:
    opacity 0.12s var(--ease),
    transform 0.12s var(--ease);
}
[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
html[data-theme="light"] [data-tooltip]::after {
  background: #1c2333;
  color: #fff;
}

/* 拖拽中的全局状态 */
body.is-dragging,
body.is-dragging * {
  cursor: grabbing !important;
  user-select: none !important;
}

/* 代码高亮通用 token（各工作区共享） */
.tok-comment {
  color: #64748b;
  font-style: italic;
}
.tok-string {
  color: #a5d6a7;
}
.tok-keyword {
  color: #c792ea;
}
.tok-number {
  color: #fbbf24;
}
.tok-label {
  color: #7dd3fc;
}
.tok-tag {
  color: #f472b6;
}
html[data-theme="light"] .tok-comment {
  color: #7b8794;
}
html[data-theme="light"] .tok-string {
  color: #15803d;
}
html[data-theme="light"] .tok-keyword {
  color: #7c3aed;
}
html[data-theme="light"] .tok-number {
  color: #b45309;
}
html[data-theme="light"] .tok-label {
  color: #0369a1;
}
html[data-theme="light"] .tok-tag {
  color: #be185d;
}
