* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #0f0f12;
  color: #eee;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* === 顶栏 === */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; gap: 12px;
  background: linear-gradient(180deg, #1a1a22, #14141a);
  border-bottom: 1px solid #2a2a35;
  flex-shrink: 0;
}
.title { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.logo { color: #ff6ea1; font-size: 16px; }
.name { font-size: 15px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }

.stats { display: flex; gap: 12px; font-size: 12px; color: #aaa; flex: 1; justify-content: center; align-items: center; }
.stat-item b { color: #fff; margin: 0 2px; }
.quota b { color: #ff6ea1; font-size: 14px; }
.regen-timer { color: #888; font-size: 11px; font-family: ui-monospace, monospace; }

.admin-area { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn, .admin-btn {
  padding: 4px 10px; font-size: 13px;
  border: 1px solid #2a2a35; border-radius: 5px;
  background: #1a1a22; color: #ccc;
  cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.icon-btn:hover, .admin-btn:hover { background: #2a2a35; color: #fff; border-color: #ff6ea1; }
.icon-btn { font-size: 16px; padding: 2px 8px; }

/* === 工作区 === */
.workspace { flex: 1; min-height: 0; display: flex; overflow: hidden; }

/* === 画布区域 === */
.canvas-area { flex: 1; min-width: 0; min-height: 0; position: relative; overflow: hidden; background: #1a1a1a; }
.canvas-viewport {
  position: absolute; inset: 0; overflow: hidden;
  cursor: crosshair; touch-action: none;
}
#board { display: block; position: absolute; top: 0; left: 0; }

/* === 加载遮罩 === */
.loading-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(26,26,26,0.8);
  z-index: 50;
}
.loading-overlay[hidden] { display: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid #2a2a35;
  border-top-color: #ff6ea1;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 12px; font-size: 14px; color: #888; }

.canvas-controls {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 4px; z-index: 10;
}
.canvas-controls button {
  width: 34px; height: 34px;
  border: 1px solid #2a2a35; border-radius: 6px;
  background: rgba(20,20,26,0.85); color: #ccc;
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px); transition: all 0.15s;
}
.canvas-controls button:hover { background: rgba(42,42,53,0.9); color: #fff; border-color: #ff6ea1; }

.hover-info {
  position: absolute; top: 8px; right: 12px;
  font-size: 11px; color: #888;
  background: rgba(0,0,0,0.5); padding: 2px 8px; border-radius: 4px;
  pointer-events: none; font-family: ui-monospace, "Cascadia Code", monospace; z-index: 10;
}

/* === 确认栏 === */
.confirm-bar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(20,20,26,0.92); backdrop-filter: blur(12px);
  border: 1px solid #2a2a35; border-radius: 10px;
  padding: 8px 14px; z-index: 20;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  white-space: nowrap;
}
.confirm-bar[hidden] { display: none; }
.confirm-info { font-size: 13px; color: #ccc; }
.confirm-info b { color: #ff6ea1; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* === 调色板面板 === */
.palette-panel {
  flex-shrink: 0; display: flex; flex-direction: column;
  background: #14141a; overflow: hidden;
  transition: width 0.2s ease, height 0.2s ease;
}
.palette-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; cursor: pointer; flex-shrink: 0;
  border-bottom: 1px solid #2a2a35; transition: background 0.15s;
}
.palette-header:hover { background: #1a1a22; }
.palette-title { font-size: 13px; font-weight: 600; color: #ccc; }
.palette-arrow { font-size: 12px; color: #ff6ea1; }
.palette-body { flex: 1; min-height: 0; overflow: hidden; }
.palette-grid { padding: 6px; }

.swatch {
  border: 1px solid rgba(255,255,255,0.08); border-radius: 3px;
  cursor: pointer; padding: 0; transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.15); z-index: 2; position: relative; }
.swatch.selected {
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #ff6ea1, 0 0 8px rgba(255,110,161,0.5);
  transform: scale(1.1); z-index: 3; position: relative;
}

.palette-grid::-webkit-scrollbar, .modal-box::-webkit-scrollbar { width: 5px; height: 5px; }
.palette-grid::-webkit-scrollbar-thumb, .modal-box::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
.palette-grid::-webkit-scrollbar-track, .modal-box::-webkit-scrollbar-track { background: transparent; }

/* === 弹窗 === */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-box {
  position: relative; background: #1a1a22; border: 1px solid #2a2a35;
  border-radius: 10px; padding: 18px;
  max-width: 90vw; max-height: 80vh; overflow: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6); min-width: 300px;
}
.modal-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; color: #ccc; margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid #2a2a35;
}
.close-btn { background: none; border: none; color: #888; font-size: 22px; cursor: pointer; padding: 0 4px; line-height: 1; }
.close-btn:hover { color: #fff; }
.modal-warn { font-size: 12px; color: #ff9500; margin-bottom: 12px; }
.text-input {
  width: 100%; padding: 8px 12px; margin-bottom: 10px;
  background: #0f0f12; border: 1px solid #2a2a35; border-radius: 6px;
  color: #fff; font-size: 14px; outline: none; transition: border-color 0.15s;
}
.text-input:focus { border-color: #ff6ea1; }
.file-input { width: 100%; margin-bottom: 10px; font-size: 13px; color: #aaa; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.btn { padding: 7px 16px; border-radius: 6px; font-size: 13px; cursor: pointer; border: none; transition: all 0.15s; }
.btn-primary { background: #ff6ea1; color: #fff; }
.btn-primary:hover { background: #ff5590; }
.btn-secondary { background: #2a2a35; color: #ccc; }
.btn-secondary:hover { background: #353542; color: #fff; }

/* === Toast === */
.toast {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  background: #1a1a22; border: 1.5px solid #ff6ea1;
  color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 14px; z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6); animation: toastIn 0.2s ease-out;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* === 宽屏：调色盘在右侧 === */
@media (min-width: 769px) {
  .workspace { flex-direction: row; }
  .palette-panel { width: 30%; border-left: 1px solid #2a2a35; max-width: 400px; }
  .palette-panel.collapsed { width: 36px; max-width: 36px; }
  .palette-panel.collapsed .palette-title { display: none; }
  .palette-panel.collapsed .palette-body { display: none; }
  .palette-panel.collapsed .palette-header { flex-direction: column; justify-content: center; padding: 8px 0; border-bottom: none; gap: 6px; }
  .palette-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; overflow-y: auto; overflow-x: hidden; height: 100%; }
  .swatch { width: 100%; aspect-ratio: 1; }
}
/* === 窄屏：调色盘在底部 === */
@media (max-width: 768px) {
  .workspace { flex-direction: column; }
  .palette-panel { height: 30%; border-top: 1px solid #2a2a35; max-height: 280px; }
  .palette-panel.collapsed { height: 36px; max-height: 36px; }
  .palette-panel.collapsed .palette-body { display: none; }
  .palette-grid { display: flex; flex-wrap: nowrap; gap: 4px; overflow-x: auto; overflow-y: hidden; height: 100%; align-items: center; }
  .swatch { width: 36px; height: 36px; flex-shrink: 0; }
}
@media (max-width: 480px) {
  .topbar { padding: 6px 10px; gap: 6px; }
  .name { font-size: 13px; }
  .stats { font-size: 11px; gap: 6px; }
  .stat-item:not(.quota) { display: none; }
  .admin-btn { font-size: 12px; padding: 3px 8px; }
  .confirm-bar { padding: 6px 10px; gap: 6px; }
}
