/* Line Ride — 北欧冬日极光沉浸舞台 */

:root {
  --bg-deep: #1a1a3e;
  --bg-aurora1: #2d1b69;
  --bg-aurora2: #1a1040;
  --bg-dark: #0d1b2a;
  --wood: #8B7355;
  --wood-light: #A0845C;
  --wood-dark: #5C4033;
  --text-primary: #f0e6d3;
  --text-secondary: #ccc5b9;
  --text-dim: #888;
  --accent-blue: #4A90D9;
  --accent-orange: #E8734A;
  --accent-green: #6BC4A6;
  --accent-gold: #FFD700;
  --danger: #E84A5F;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-primary);
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-app {
  display: flex;
  flex-direction: column;
  width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--bg-deep) 0%, var(--bg-aurora2) 30%, var(--bg-dark) 100%);
}

/* ====== 顶边松木控制台 ====== */
#stage-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: linear-gradient(180deg, rgba(92,64,51,0.95), rgba(75,50,38,0.9));
  border-bottom: 2px solid rgba(160,132,92,0.5);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  min-height: 44px;
  z-index: 10;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#stage-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

#stage-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.8;
}

.stage-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.bar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid rgba(160,132,92,0.4);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(139,115,85,0.4), rgba(92,64,51,0.4));
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.bar-btn:hover {
  background: linear-gradient(180deg, rgba(160,132,92,0.5), rgba(139,115,85,0.5));
  border-color: rgba(200,180,140,0.6);
}

.bar-btn:active {
  transform: translateY(1px);
}

#back-home {
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
}

/* ====== 工具栏 ====== */
#tool-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: linear-gradient(180deg, rgba(75,50,38,0.7), rgba(60,40,30,0.7));
  border-bottom: 1px solid rgba(160,132,92,0.3);
  min-height: 42px;
  flex-shrink: 0;
}

/* 画笔组：拼图模式下收起（播放控制始终保留） */
#brush-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

#brush-group.hidden { display: none; }

.tools-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-right: 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid rgba(160,132,92,0.3);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(139,115,85,0.3), rgba(92,64,51,0.3));
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tool-btn:hover {
  background: linear-gradient(180deg, rgba(160,132,92,0.4), rgba(139,115,85,0.4));
}

.tool-btn:active {
  transform: translateY(1px);
}

.tool-btn.active {
  border-color: var(--accent-gold);
  box-shadow: 0 0 8px rgba(255,215,0,0.3);
  color: var(--accent-gold);
}

.line-swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
}

.swatch-normal { background: var(--accent-blue); }
.swatch-boost { background: var(--accent-orange); }
.swatch-slow { background: var(--accent-green); }
.swatch-scenery { background: rgba(255,255,255,0.4); border: 2px dashed rgba(255,255,255,0.4); }

#tool-eraser.active {
  border-color: var(--danger);
  color: var(--danger);
}

/* 播放控制 */
.player-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

#btn-play {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

#btn-play:hover {
  background: rgba(255,255,255,0.2);
}

/* 拼图面板 */
#puzzle-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  background: linear-gradient(180deg, rgba(75,50,38,0.7), rgba(60,40,30,0.7));
  border-bottom: 1px solid rgba(160,132,92,0.3);
  min-height: 42px;
  flex-shrink: 0;
}

#puzzle-panel.hidden { display: none; }

#puzzle-chapter {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-gold);
}

#puzzle-level {
  font-size: 14px;
  font-weight: 700;
}

#puzzle-stars {
  font-size: 14px;
}

#puzzle-ink {
  font-size: 12px;
  color: var(--accent-blue);
  margin-left: auto;
}

.nav-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(160,132,92,0.4);
  background: rgba(139,115,85,0.3);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:hover:not(:disabled) {
  background: rgba(160,132,92,0.4);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* 导出/导入/清空 */
.io-group {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

/* 模式切换 */
.mode-switch {
  display: flex;
  gap: 0;
  margin: 0 12px;
}

.mode-btn {
  padding: 4px 12px;
  border: 1px solid rgba(160,132,92,0.3);
  background: rgba(139,115,85,0.2);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn:first-child { border-radius: 4px 0 0 4px; }
.mode-btn:last-child { border-radius: 0 4px 4px 0; }

.mode-btn.active {
  background: rgba(139,115,85,0.5);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.mode-btn:hover:not(.active) {
  background: rgba(160,132,92,0.3);
}

/* ====== 主舞台 ====== */
#stage-core {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* ====== 底部提示 ====== */
#bottom-tip {
  padding: 4px 16px;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.6;
  border-top: 1px solid rgba(160,132,92,0.2);
  background: rgba(0,0,0,0.2);
}

#bottom-tip.hidden { display: none; }

/* ====== 弹出层 ====== */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  align-items: center;
  justify-content: center;
}

#overlay.show {
  display: flex;
}

.overlay-box {
  background: linear-gradient(135deg, rgba(45,27,105,0.95), rgba(26,26,62,0.95));
  border: 2px solid rgba(160,132,92,0.5);
  border-radius: 12px;
  padding: 24px 32px;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

#overlay-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--accent-gold);
}

#overlay-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

#overlay-btn {
  padding: 8px 24px;
  border: 1px solid rgba(160,132,92,0.5);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(139,115,85,0.5), rgba(92,64,51,0.5));
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

#overlay-btn:hover {
  background: linear-gradient(180deg, rgba(160,132,92,0.6), rgba(139,115,85,0.6));
}

/* Toast */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  background: rgba(0,0,0,0.75);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 60;
}

#toast.show {
  opacity: 1;
}

/* ====== Noscript ====== */
#noscript-tip {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
}

/* ====== 响应式 ====== */
@media (max-width: 768px) {
  #stage-bar {
    padding: 4px 10px;
    gap: 6px;
    min-height: 40px;
  }
  #stage-title { font-size: 13px; }
  #stage-subtitle { display: none; }
  .bar-btn { padding: 3px 7px; font-size: 10px; }
  #tool-bar {
    padding: 4px 8px;
    gap: 4px;
    min-height: 36px;
  }
  .tool-btn { padding: 3px 7px; font-size: 10px; }
  .tools-label { display: none; }
  #puzzle-panel { padding: 4px 8px; gap: 6px; }
  .mode-btn { padding: 3px 8px; font-size: 10px; }
  #game-app {
    padding-bottom: max(68px, calc(16px + env(safe-area-inset-bottom)));
  }
  #bottom-tip { display: none; }
  .overlay-box { max-width: 90%; padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}