/* ============================================
   像素小镇 - 全局样式
   粗犷涂鸦风 (Graffiti / Hand-drawn / Bold / Colorful)
   响应式适配：320px（手机） ~ 1920px（桌面）
   ============================================ */

/* --- CSS 变量（设计令牌）--- */
:root {
  /* 主题色 - 鲜明色彩 */
  --color-red:    #E53935;
  --color-yellow: #FDD835;
  --color-blue:   #1E88E5;
  --color-green:  #43A047;
  --color-orange: #FB8C00;
  --color-pink:   #EC407A;
  --color-purple: #8E24AA;
  --color-cyan:   #00ACC1;
  --color-brown:  #6D4C41;

  /* 背景与文字 */
  --bg-primary:   #FFF9C4;    /* 暖黄背景 */
  --bg-secondary: #FFF3E0;
  --bg-dark:      #263238;
  --text-primary: #212121;
  --text-secondary: #5D4037;

  /* 涂鸦边框 - 粗线条 4-8px */
  --border-thick:  6px solid #212121;
  --border-medium: 4px solid #212121;
  --border-dashed: 4px dashed #212121;

  /* 字体 */
  --font-game: 'ZCOOL KuaiLe', 'Comic Sans MS', cursive, sans-serif;

  /* 间距 */
  --gap-xs:  4px;
  --gap-sm:  8px;
  --gap-md:  16px;
  --gap-lg:  24px;
  --gap-xl:  32px;
}

/* --- 全局重置 --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-game);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* --- 应用根容器 --- */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--gap-md);
  min-height: 100vh;
}

/* --- 涂鸦边框通用类 --- */
.graffiti-border {
  border: var(--border-thick);
  border-radius: 12px;
  box-shadow: 4px 6px 0 rgba(0,0,0,0.15);
  background: #FFFFFF;
}

.graffiti-border-dashed {
  border: var(--border-dashed);
  border-radius: 8px;
}

/* --- 按钮样式 --- */
.btn {
  display: inline-block;
  padding: 10px 24px;
  font-family: var(--font-game);
  font-size: 1rem;
  font-weight: bold;
  border: var(--border-medium);
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s ease;
  box-shadow: 3px 4px 0 rgba(0,0,0,0.2);
}
.btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 5px 0 rgba(0,0,0,0.25);
}
.btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.btn-primary   { background: var(--color-blue);   color: #FFF; }
.btn-success   { background: var(--color-green);  color: #FFF; }
.btn-danger    { background: var(--color-red);    color: #FFF; }
.btn-warning   { background: var(--color-orange); color: #FFF; }
.btn-secondary { background: var(--bg-dark);      color: var(--color-yellow); }

/* --- 表单元素 --- */
.form-input {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-game);
  font-size: 1rem;
  border: var(--border-medium);
  border-radius: 8px;
  background: #FFF;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}
.form-input:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(30,136,229,0.2);
}

.form-group {
  margin-bottom: var(--gap-md);
}
.form-label {
  display: block;
  margin-bottom: var(--gap-xs);
  font-weight: bold;
  color: var(--text-secondary);
}

/* --- 标题 --- */
.game-title {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--color-red);
  text-shadow: 3px 3px 0 rgba(0,0,0,0.15);
  text-align: center;
  margin-bottom: var(--gap-lg);
}

/* --- 卡片 --- */
.card {
  padding: var(--gap-md);
  margin-bottom: var(--gap-md);
}

/* --- 响应式 --- */
@media (max-width: 480px) {
  #app {
    padding: var(--gap-sm);
  }
  .game-title {
    font-size: 1.8rem;
  }
  .btn {
    padding: 8px 16px;
    font-size: 0.9rem;
  }
}

@media (min-width: 1200px) {
  #app {
    max-width: 1200px;
  }
}

/* --- 动画 --- */
@keyframes graffiti-pop {
  0%   { transform: scale(0.9); opacity: 0; }
  80%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}
.animate-pop {
  animation: graffiti-pop 0.3s ease forwards;
}

/* ============================================
   游戏页面 — 模拟经营 Hub 布局
   ============================================ */

.game-page {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- HUD 状态栏 --- */
.game-status-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: #FFF;
  font-size: 0.85rem;
  gap: 6px;
  flex-shrink: 0;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-stat {
  white-space: nowrap;
}

.hud-money { color: var(--color-blue); }
.hud-debt  { color: var(--color-red); }
.hud-rep   { color: var(--color-orange); }

.hud-time {
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.hud-location {
  white-space: nowrap;
  color: var(--color-green);
}

.hud-coords {
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

#hud-admin-btn {
  font-size: 0.7rem;
  padding: 3px 8px;
  text-decoration: none;
}

/* ============================================
   tick 进度 + 顾客需求 + 拖拽
   ============================================ */

.cg-tick-bar {
  height: 12px; background: #eee; border-radius: 6px; overflow: hidden;
  position: relative; margin-bottom: 6px;
}
.cg-tick-fill {
  height: 100%; background: linear-gradient(90deg, #43a047, #ffd54f, #e53935);
  border-radius: 6px; transition: width 0.3s;
}
.cg-tick-text {
  position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  font-size: 0.7rem; font-weight: bold; color: #212121;
}
.cg-cust-info { flex: 1; min-width: 0; }
.cg-cust-name { display: block; font-weight: bold; font-size: 0.8rem; }
.cg-cust-want { display: block; font-size: 0.7rem; color: var(--color-orange); margin-top: 1px; }
.cg-patience-wrap { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.cg-patience-bar { width: 55px; height: 5px; background: #eee; border-radius: 3px; overflow: hidden; }
.cg-patience-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.cg-patience-num { font-size: 0.6rem; color: var(--text-secondary); }
.cg-card[draggable="true"] { cursor: grab; }
.cg-card[draggable="true"]:active { cursor: grabbing; opacity: 0.7; }
.cg-serve-btn { flex-shrink: 0; }

/* ============================================
   卡牌游戏 — 模拟经营布局
   ============================================ */

.cardgame-layout {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 卡牌区域 */
.cg-card-area { flex: 1; min-width: 380px; display: flex; flex-direction: column; gap: 5px; }
.cg-deck-cards { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* 顾客区 */
.cg-queue { flex: 0 0 175px; }
.cg-section-title { font-weight: bold; font-size: 0.82rem; margin-bottom: 6px; }
.cg-queue-list { display: flex; flex-direction: column; gap: 3px; min-height: 80px; }
.cg-empty, .cg-empty-sm { text-align: center; color: #aaa; padding: 12px; font-size: 0.72rem; }
.cg-customer { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border: 2px dashed #ddd; border-radius: 5px; background: #fff; }
.cg-customer.first { border-color: #43a047; border-style: solid; background: #f1f8e9; }
.cg-cust-emoji { font-size: 1.1rem; flex-shrink: 0; width: 22px; text-align: center; }
.cg-cust-info { flex: 1; min-width: 0; }
.cg-cust-name { font-weight: bold; font-size: 0.7rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-cust-want { font-size: 0.62rem; color: #fb8c00; display: flex; align-items: center; gap: 2px; }
.cg-want-icon { width: 18px; height: 18px; image-rendering: pixelated; flex-shrink: 0; }
.cg-patience-wrap { display: flex; flex-direction: column; align-items: center; gap: 0; flex-shrink: 0; }
.cg-patience-bar { width: 38px; height: 4px; background: #eee; border-radius: 2px; overflow: hidden; }
.cg-patience-fill { height: 100%; border-radius: 2px; }
.cg-patience-num { font-size: 0.55rem; color: #888; }
.cg-serve-btn { flex-shrink: 0; font-size: 0.6rem !important; padding: 1px 4px !important; }

/* 卡牌 */
.cg-card {
  width: 120px; height: 160px;
  border: 3px solid #212121; border-radius: 10px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  gap: 0; cursor: pointer; user-select: none;
  background: #fff; padding: 5px 3px; overflow: visible;
}
.cg-card:hover { transform: translateY(-2px); z-index: 5; box-shadow: 0 4px 14px rgba(0,0,0,0.18); }
.cg-card.back { background: linear-gradient(135deg, #1e88e5, #1565c0); color: #fff; font-size: 2.2rem; justify-content: center; border-color: #0d47a1; }
.cg-card.front.ingredient { border-color: #8d6e63; background: #fff8e1; }
.cg-card.front.food { border-color: #e53935; background: #ffebee; }
.cg-card.front.junk { border-color: #9e9e9e; background: #f5f5f5; }
.cg-card-img { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cg-card-img img { width: 46px; height: 46px; image-rendering: pixelated; }
.cg-card-img-sm { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; }
.cg-card-img-sm img { width: 30px; height: 30px; image-rendering: pixelated; }
.cg-card.small { width: 105px; height: 140px; }
.cg-card.small .cg-card-name { font-size: 0.67rem; }
.cg-card-name { font-size: 0.73rem; font-weight: bold; text-align: center; line-height: 1.2; padding: 0 2px; }
.cg-card-level { font-size: 0.62rem; font-weight: bold; }
.cg-card-points { font-size: 0.65rem; color: #555; }
.cg-card-points.low { color: #e53935; font-weight: bold; animation: pulse 1s infinite; }
.cg-card-price { font-size: 0.62rem; color: #1e88e5; font-weight: bold; }
.cg-card[draggable="true"] { cursor: grab; }
.cg-card[draggable="true"]:active { cursor: grabbing; opacity: 0.7; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
.cg-card-btns { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; margin-top: 2px; }
.cg-card-row { display: flex; gap: 4px; flex-wrap: wrap; min-height: 40px; }

/* 合成区 */
.cg-combine { background: #e8f5e9 !important; }
#combine-list { display: flex; flex-direction: column; gap: 3px; }
.cg-footer { display: flex; flex-wrap: wrap; gap: 14px; padding: 5px 14px !important; font-size: 0.8rem; }
.cg-footer span { white-space: nowrap; }
#game-msg { text-align: center; min-height: 22px; font-size: 0.8rem; padding: 2px; }

/* 回收区 */
.cg-recycle {
  position: fixed; bottom: 12px; right: 12px;
  width: 60px; height: 60px;
  border: 3px dashed #c62828; border-radius: 12px;
  background: rgba(255,205,210,0.88);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; text-align: center; z-index: 100;
  cursor: default; color: #b71c1c; line-height: 1.2;
}

/* 强制横屏 */
@media (max-width: 768px) and (orientation: portrait) {
  #app::before {
    content: "📱 请横屏使用"; display: flex;
    align-items: center; justify-content: center;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #212121; color: #fff; z-index: 9999;
    font-size: 1.5rem; font-family: var(--font-game);
  }
}

/* ============================================
   故事回顾 — 章节选择模态框
   ============================================ */

.story-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.story-modal {
  background: #FFF;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 0;
}

.story-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: var(--border-medium);
  position: sticky;
  top: 0;
  background: #FFF;
  z-index: 1;
}

.story-modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.story-modal-close {
  background: none;
  border: 2px solid var(--text-secondary);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.story-modal-close:hover {
  background: var(--color-red);
  color: #fff;
  border-color: var(--color-red);
}

.story-modal-list {
  padding: 12px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.story-modal-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
  font-size: 0.9rem;
}

.story-chapter-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px dashed #ddd;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.story-chapter-item:hover {
  background: var(--bg-secondary);
  border-color: var(--color-blue);
}

.story-chapter-item.read {
  border-style: solid;
  border-color: #c8e6c9;
  background: #f1f8e9;
}

.story-chapter-item.read:hover {
  border-color: var(--color-green);
}

.story-chapter-icon {
  font-size: 1.5rem;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.story-chapter-info {
  flex: 1;
  min-width: 0;
}

.story-chapter-title {
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.story-chapter-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-chapter-status {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.story-chapter-item.read .story-chapter-status {
  color: var(--color-green);
}

.story-chapter-play {
  font-size: 0.78rem !important;
  padding: 6px 14px !important;
  white-space: nowrap;
}

/* ============================================
   视觉小说页面
   ============================================ */

.novel-page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

/* CG 背景层 */
.novel-cg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transition: opacity 1s ease;
  z-index: 1;
}

.novel-cg-canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.novel-cg-dark {
  width: 100%;
  height: 100%;
  background: #111;
}

/* 工具栏 */
.novel-toolbar {
  position: absolute;
  top: 12px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.novel-tool-btn {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 6px 14px;
  font-family: var(--font-game);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.novel-tool-btn:hover,
.novel-tool-btn.active {
  background: rgba(30, 136, 229, 0.7);
  border-color: rgba(255, 255, 255, 0.8);
}

/* 道具展示 */
.novel-item-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  background: rgba(0, 0, 0, 0.6);
}

.novel-item-card {
  text-align: center;
  padding: 24px 32px;
  background: rgba(255, 255, 255, 0.95);
  min-width: 200px;
}

.novel-item-icon {
  margin-bottom: 12px;
}

.novel-item-icon canvas {
  image-rendering: pixelated;
}

.novel-item-name {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--color-brown);
  margin-bottom: 6px;
}

.novel-item-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 260px;
  line-height: 1.5;
}

/* 底部文本框 */
.novel-textbox {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(transparent, rgba(0,0,0,0.85) 30%);
  padding: 40px 32px 24px;
  z-index: 5;
  min-height: 160px;
}

.novel-speaker {
  color: var(--color-yellow);
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 8px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.novel-dialogue-text {
  color: #fff;
  font-size: 1.05rem;
  line-height: 1.8;
  min-height: 48px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
}

.novel-cursor {
  display: inline-block;
  animation: blink 0.8s infinite;
  color: var(--color-yellow);
  font-weight: bold;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.novel-continue-hint {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.75rem;
  margin-top: 12px;
  animation: bounce 1.5s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

/* 选择框 */
.novel-choices-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
  background: rgba(0, 0, 0, 0.4);
}

.novel-choices-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
  max-width: 400px;
}

.novel-choices-prompt {
  color: #fff;
  text-align: center;
  font-size: 1rem;
  margin-bottom: 8px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.novel-choice-btn {
  width: 100%;
  font-size: 1rem !important;
  padding: 14px 24px !important;
}

/* NPC 对话气泡（保留，后续剧情可能复用） */
.dialog-bubble {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 450px;
  width: 90%;
  padding: 14px 18px;
  background: var(--bg-primary);
  z-index: 1000;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.dialog-name {
  font-weight: bold;
  color: var(--color-blue);
  font-size: 0.9rem;
}

.dialog-close {
  background: none;
  border: 2px solid var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.dialog-close:hover {
  background: var(--color-red);
  color: #fff;
  border-color: var(--color-red);
}

.dialog-text {
  line-height: 1.6;
  color: var(--text-primary);
}

/* --- 响应式 --- */
@media (max-width: 600px) {
  .game-page {
    gap: 4px;
  }

  .game-status-bar {
    padding: 4px 8px;
    font-size: 0.75rem;
    gap: 4px;
  }

  .hud-left,
  .hud-right {
    gap: 6px;
  }

  .shop-hub {
    flex-direction: column;
  }

  .dialog-bubble {
    bottom: 120px;
  }

  .novel-textbox {
    padding: 30px 16px 16px;
    min-height: 140px;
  }

  .novel-dialogue-text {
    font-size: 0.95rem;
  }

  .novel-toolbar {
    top: 8px;
    right: 8px;
    gap: 4px;
  }

  .novel-tool-btn {
    padding: 4px 10px;
    font-size: 0.7rem;
  }
}

@media (min-width: 1200px) {
  .shop-hub {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
  }
}
