:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --accent: #5ae3ff;
  --accent-2: #ff7ab6;
  --ok: #47d16a;
  --bad: #ff5b5b;
  --text: #e8efff;
  --muted: #a9b6d3;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1000px 600px at 10% 0%, #15224a 0%, var(--bg) 60%);
  color: var(--text);
}

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0f1e; font-weight: 800;
}
.title { font-weight: 600; letter-spacing: 0.5px; }
.modes { display: flex; gap: 8px; }
.mode-btn {
  padding: 8px 12px; border-radius: 8px; border: 1px solid #2a365f; color: var(--text);
  background: #0f1430; cursor: pointer;
}
.mode-btn.active { border-color: var(--accent); color: var(--accent); }
.ghost { padding: 8px 12px; border-radius: 8px; background: transparent; border: 1px dashed #2a365f; color: var(--muted); cursor: pointer; }
.session-info { display: flex; align-items: center; gap: 10px; color: var(--muted); }

.game { width: 100%; max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: grid; gap: 16px; }

.question { background: var(--panel); border: 1px solid #253156; border-radius: 14px; padding: 12px; }
.question-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.zh-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.zh-text { font-size: 18px; font-weight: 600; }
.icon-btn { border: none; background: #0f1430; border: 1px solid #263459; border-radius: 8px; padding: 6px 10px; color: var(--text); cursor: pointer; }
.icon-btn.active { color: var(--accent); border-color: var(--accent); }
.answer-tools { display: flex; gap: 8px; }

/* 圆形计时器：直径与按钮高度近似（36px），60s满圈，颜色由绿到红渐变 */
.timer { --timer-deg: 0deg; --timer-color: #47d16a; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; position: relative; font-weight: 800; color: var(--timer-color); }
.timer::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(var(--timer-color) var(--timer-deg), #263459 0); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 0); mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 0); }
.timer span { font-size: 8px; position: relative; z-index: 1; }

.slots { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(36px, 60px); gap: 8px; padding: 12px; justify-content: start; }
.slot {
  width: 100%; height: 58px; border-radius: 10px; border: 2px dashed #3a4a7a; color: var(--muted);
  display: grid; place-items: center; font-size: 24px; font-weight: 700; background: #0c122a;
  transition: border-color .2s, background .2s, transform .1s;
}
.slot.filled { border-style: solid; border-color: var(--accent); color: var(--text); background: #0f1436; }
.slot.ok { border-color: var(--ok); }
.slot.bad { border-color: var(--bad); }

.letters { background: var(--panel); border: 1px solid #253156; border-radius: 14px; padding: 12px; }
.letter-bank { display: grid; grid-template-columns: repeat(13, minmax(36px, 1fr)); gap: 8px; }
.letter {
  user-select: none; -webkit-user-select: none;
  display: grid; place-items: center; height: 46px; border-radius: 12px; font-weight: 800; font-size: 20px;
  color: #0b1020; background: #e8efff; cursor: grab; box-shadow: 0 8px 18px rgba(0,0,0,.30);
}
.letter:active { cursor: grabbing; transform: scale(.98); }
.letter.used { opacity: .85; }

.drag-ghost {
  position: fixed; z-index: 9999; pointer-events: none; transform: translate(-50%, -50%);
  width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0a0f1e;
  box-shadow: 0 20px 40px rgba(0,0,0,.45);
}

.result-panel { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8,12,24,.55); z-index: 1000; }
.result-panel.hidden { display: none; }
.result-card { width: min(760px, 92vw); max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid #2a365f; border-radius: 16px; padding: 16px; position: relative; }
.result-summary { display: grid; gap: 8px; margin-top: 12px; max-height: 52vh; overflow: auto; }
.result-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: #0f1430; }
.result-item .tag { padding: 4px 8px; border-radius: 8px; font-weight: 700; }
.tag { padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.result-time { font-size: 12px; font-style: italic; padding: 2px 6px; border-radius: 6px; border: 1px solid #263459; }
.result-time.ok { color: var(--ok); border-color: rgba(71,209,106,.4); }
.result-time.bad { color: var(--bad); border-color: rgba(255,91,91,.4); }
.tag-ok { background: rgba(71,209,106,.12); color: var(--ok); border: 1px solid rgba(71,209,106,.4); margin-left: 10px; }
.tag-bad { background: rgba(255,91,91,.12); color: var(--bad); border: 1px solid rgba(255,91,91,.4); margin-left: 10px;}
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

/* 历史记录卡片项与标题分组样式（复用result-panel结构） */
.history-section-title { margin-top: 6px; color: var(--muted); font-size: 13px; }
.history-item { display: grid; gap: 6px; padding: 10px; border-radius: 10px; background: #0f1430; border: 1px solid #263459; }
.history-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.history-counts { display: flex; gap: 8px; }
.history-list { display: grid; gap: 6px; }

/* 统计面板样式 */
.stats-wrap { display: grid; gap: 16px; }
.stats-section { display: grid; gap: 8px; }
.stats-title { color: var(--muted); font-size: 13px; }
.stats-chart { width: 100%; height: 300px; background: #0f1430; border: 1px solid #263459; border-radius: 10px; }
.stats-tools { display: flex; gap: 8px; align-items: center; }
.stats-tools input, .stats-tools select { height: 36px; border-radius: 8px; border: 1px solid #2a365f; background: #0f1430; color: var(--text); padding: 6px 10px; }
.word-stats-list { display: grid; gap: 6px; }
.word-row { display: grid; grid-template-columns: 1.4fr 1fr 0.6fr 0.6fr 0.6fr; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: #0f1430; border: 1px solid #263459; }
.word-row .w-zh { color: var(--text); }
.word-row .w-en { color: var(--muted); }
.word-row .w-ok { color: var(--ok); }
.word-row .w-bad { color: var(--bad); }
.word-row .w-total { color: var(--text); }

/* 自定义题库弹窗样式 */
.custom-panel { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8,12,24,.55); z-index: 1000; }
.custom-panel.hidden { display: none; }
.custom-card { width: min(880px, 92vw); max-height: 90vh; background: var(--panel); border: 1px solid #2a365f; border-radius: 16px; padding: 16px; display: flex; flex-direction: column; }
.custom-body { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; overflow: auto; }
.custom-list { display: grid; gap: 8px; margin: 12px 0; }
.custom-tools { display: flex; gap: 8px; align-items: center; }
.custom-tools input, .custom-tools select { height: 34px; border-radius: 8px; border: 1px solid #2a365f; background: #0f1430; color: var(--text); padding: 4px 8px; }
.custom-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 8px; }
.tabs { display: flex; gap: 8px; margin-top: 6px; }
.tab-btn { padding: 6px 10px; border-radius: 8px; border: 1px solid #2a365f; background: #0f1430; color: var(--text); cursor: pointer; }
.tab-btn.active { border-color: var(--accent); color: var(--accent); }
.tab-hidden { display: none; }
.custom-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.custom-row input { width: 100%; height: 38px; border-radius: 10px; border: 1px solid #2a365f; background: #0f1430; color: var(--text); padding: 6px 10px; }
.custom-row .actions { display: flex; gap: 8px; align-items: center; }
.custom-row .toggle { height: 38px; border-radius: 10px; border: 1px solid #2a365f; background: #0f1430; color: var(--text); cursor: pointer; }
.custom-row .del { height: 38px; border-radius: 10px; border: 1px solid #2a365f; background: #201a35; color: #ff9fb6; cursor: pointer; }
.custom-actions { display: flex; justify-content: flex-end; gap: 8px; }
.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0a0f1e; border: none; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; }

/* 自定义题库 JSON 导入/导出区域 */
.json-wrap { display: grid; gap: 8px; margin-top: 8px; }
.json-area { width: 100%; min-height: 120px; border-radius: 10px; border: 1px solid #2a365f; background: #0f1430; color: var(--text); padding: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.json-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* 移动端拖拽兼容优化：禁用滚动干扰与手势冲突 */
body { overscroll-behavior: none; }
.letter, .slot, .letter-bank, .slots { touch-action: none; }
body.dragging { touch-action: none; }

/* 移动端侧边栏切换按钮（固定在右侧） */
.mobile-sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 50px;
  right: 0;
  width: 40px;
  height: 80px;
  background: var(--panel);
  border: 1px solid #2a365f;
  border-right: none;
  border-radius: 10px 0 0 10px;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  z-index: 999;
  transition: all 0.3s ease;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
}

.mobile-sidebar-toggle:active {
  background: #1a2340;
}

.mobile-sidebar-toggle .toggle-icon {
  display: block;
  transform: rotate(90deg);
}

/* 移动端侧边栏（从右侧滑出） */
.mobile-sidebar {
  display: none;
  position: fixed;
  top: 0;
  right: -200px;
  width: 200px;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid #2a365f;
  z-index: 1001;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
}

.mobile-sidebar.open {
  right: 0;
}

.mobile-sidebar-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 80px 12px 20px;
}

.mobile-menu-item {
  width: 100%;
  padding: 14px 12px;
  border: 1px solid #2a365f;
  background: #0f1430;
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  text-align: left;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-menu-item:active {
  background: #1a2340;
  border-color: var(--accent);
  transform: scale(0.98);
}

.mobile-menu-item .menu-icon {
  font-size: 18px;
}

.mobile-menu-item .menu-text {
  flex: 1;
}

/* 侧边栏遮罩层 */
.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 24, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-sidebar-overlay.show {
  opacity: 1;
}

/* 手机端适配（≤720px） */
@media (max-width: 720px) {
  /* 显示移动端侧边栏相关元素 */
  .mobile-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .mobile-sidebar {
    display: block;
  }
  
  /* 遮罩层默认不显示，只有添加 .show 类时才显示 */
  .mobile-sidebar-overlay {
    display: none;
  }
  
  .mobile-sidebar-overlay.show {
    display: block;
  }
  
  /* 隐藏桌面端元素 */
  .mobile-hide {
    display: none !important;
  }
  
  /* 调整会话计数器字体大小 */
  #sessionCounter {
    font-size: 11px;
  }
  
  /* 保持其他样式不变 */
  .letter-bank { grid-template-columns: repeat(8, 1fr); }
  .slots { grid-auto-columns: minmax(34px, 42px); }
  .slot { height: 48px; font-size: 20px; }
}

/* 平板适配（721px - 1024px）：保持原样式 */
@media (min-width: 721px) and (max-width: 1024px) {
  /* 平板保持桌面样式，不显示移动端侧边栏 */
  .mobile-sidebar-toggle,
  .mobile-sidebar,
  .mobile-sidebar-overlay {
    display: none !important;
  }
}

.card-close { position: absolute; top: 10px; right: 10px; }

/* 手写弹窗样式（复用result-panel结构） */
.handwrite-wrap { width: 100%; height: 50vh; max-height: 60vh; background: #0f1430; border: 1px solid #263459; border-radius: 10px; overflow: hidden; }
.handwrite-canvas { width: 100%; height: 100%; touch-action: none; display: block; }

@media (max-width: 720px) {
  .handwrite-wrap { height: 60vh; }
}
.time-stats-list { display: grid; gap: 6px; }
.time-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: #0f1430; border: 1px solid #263459; }
.time-row .t-time.ok { color: var(--ok); }
.time-row .t-time.bad { color: var(--bad); }
