/* ===== 移动端响应式优化 v3 ===== */
/* 设计原则：复用 main.css 的设计令牌（橙色调/跑马灯边框），仅调整布局和尺寸 */

/* ==================== 平板+手机 (≤768px) ==================== */
@media (max-width: 768px) {

  /* ---- 基础 ---- */
  html, body {
    overflow-x: hidden;
    width: 100%;
  }

  body {
    padding: 0;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
  }

  .novel-container {
    border-radius: 12px;
    min-height: 100vh;
    padding: 0;
  }

  /* 手机端跑马灯边框 */
  .novel-container::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: linear-gradient(45deg, #ff0000, #ff7300, #fffb00, #48ff00, #00ffd5, #002bff, #7a00ff, #ff00c8, #ff0000);
    background-size: 400%;
    z-index: -1;
    animation: glowing 20s linear infinite;
    border-radius: 16px;
    filter: blur(2px);
  }

  /* ---- 导航栏 ---- */
  .navbar {
    padding: 0.75rem 1rem !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    min-height: 56px;
  }

  .navbar-left {
    width: auto !important;
    justify-content: flex-start !important;
    gap: 0.5rem !important;
    display: flex !important;
    align-items: center !important;
  }

  .navbar-right {
    width: auto !important;
    justify-content: flex-end !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    flex-shrink: 0 !important;
  }

  .navbar-left .nav-link,
  .navbar-left .nav-divider,
  .navbar-left .dark-mode-toggle-btn,
  .navbar-left a[href] {
    display: none !important;
  }

  /* ---- 汉堡菜单 ---- */
  .hamburger-btn {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-around !important;
    align-items: center !important;
    width: 44px;
    height: 44px;
    padding: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 1100;
  }

  .hamburger-btn span {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
  }

  body.dark-mode .hamburger-btn span {
    background: #fff;
  }

  .hamburger-btn.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
  }
  .hamburger-btn.active span:nth-child(2) {
    opacity: 0;
  }
  .hamburger-btn.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
  }

  /* ---- 侧边栏 ---- */
  .sidebar-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: var(--bg-primary);
    box-shadow: var(--shadow-md);
    z-index: 1050;
    transition: left 0.3s ease;
    overflow-y: auto;
    padding-top: 80px;
  }

  .sidebar-menu.open { left: 0; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
  }

  .sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
  }

  .sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 16px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
  }

  .sidebar-menu a:hover,
  .sidebar-menu a:active {
    background: var(--bg-secondary);
  }

  body.dark-mode .sidebar-menu {
    background: #1a1a2e;
  }
  body.dark-mode .sidebar-menu a {
    color: #e0e0e0;
    border-bottom-color: #333;
  }
  body.dark-mode .sidebar-menu a:hover {
    background: #16213e;
  }

  /* ---- Header ---- */
  .header {
    padding: 1.25rem 1rem;
    text-align: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
  }

  .header h1 {
    font-size: 20px;
    margin-bottom: 0.5rem;
    color: white;
  }

  .header h1 svg {
    width: 24px;
    height: 24px;
  }

  .header p {
    font-size: 13px;
    color: rgba(255,255,255,0.85);
  }

  /* ---- 主内容区 ---- */
  .main-content {
    flex-direction: column;
    gap: 0;
  }

  .left-panel,
  .right-panel {
    width: 100% !important;
    max-height: none;
    border-right: none;
    padding: 1rem;
  }

  .left-panel {
    border-bottom: 1px solid var(--border-color);
  }

  /* ---- 配置区段 ---- */
  .config-section {
    border-radius: var(--radius-lg);
    margin-bottom: 0.75rem;
  }

  .config-section h2 {
    font-size: 17px;
  }

  /* ---- 表单 ---- */
  .config-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .form-group {
    margin-bottom: 1.25rem;
  }

  .form-group label,
  .form-label {
    font-size: 15px;
    margin-bottom: 0.5rem;
    display: block;
    font-weight: 500;
  }

  /* 表单内 flex 容器全部垂直排列 */
  .form-group > div[style*="display: flex"],
  .form-group > div[style*="display:flex"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }

  .form-group > div[style*="display: flex"] > input[type="text"],
  .form-group > div[style*="display:flex"] > input[type="text"],
  .form-group > div[style*="display: flex"] > textarea,
  .form-group > div[style*="display:flex"] > textarea {
    width: 100% !important;
    flex: none !important;
  }

  .form-group > div[style*="display: flex"] > button,
  .form-group > div[style*="display:flex"] > button,
  .form-group > div[style*="display: flex"] > div,
  .form-group > div[style*="display:flex"] > div {
    width: 100% !important;
  }

  .form-group > div[style*="display: flex"] > div > button,
  .form-group > div[style*="display:flex"] > div > button {
    width: 100% !important;
    justify-content: center !important;
  }

  /* 角色数量配置区域 */
  .form-group > div[style*="background"] > div[style*="display: flex"],
  .form-group > div[style*="background"] > div[style*="display:flex"] {
    flex-direction: column !important;
    gap: 0.75rem !important;
    align-items: flex-start !important;
  }

  /* ---- 输入框/下拉/文本域 ---- */
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
    padding: 0.75rem;
    min-height: 44px;
    width: 100%;
    box-sizing: border-box;
  }

  textarea {
    resize: vertical;
    min-height: 120px;
  }

  /* ---- 按钮 ---- */
  button {
    min-height: 44px;
    font-size: 16px;
    padding: 0.75rem 1.25rem;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
    margin-bottom: 0.5rem;
  }

  .action-buttons {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .action-buttons button {
    flex: 1;
    min-width: calc(50% - 0.25rem);
  }

  /* ---- 输出区域 ---- */
  .output-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .stats-bar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .stat-item {
    width: 100%;
    justify-content: space-between;
  }

  #output {
    min-height: 300px;
  }

  /* ---- 章节导航 ---- */
  .chapter-nav {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chapter-nav button {
    flex: 1;
    min-width: calc(50% - 0.25rem);
    font-size: 14px;
    padding: 0.6rem;
  }

  /* ---- 模态框 ---- */
  .modal {
    padding: 1rem;
    align-items: flex-start;
    padding-top: 5vh;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: var(--radius-lg);
  }

  .modal-footer {
    flex-direction: column;
    gap: 0.5rem;
  }

  .modal-footer button {
    width: 100%;
  }

  /* ---- Toast ---- */
  .error-message,
  .success-message,
  .toast {
    position: fixed;
    top: 80px;
    left: 1rem;
    right: 1rem;
    z-index: 3000;
    font-size: 14px;
    padding: 1rem;
  }

  /* ---- 滚动条 ---- */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  ::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
  }

  /* ---- 溢出控制 ---- */
  img, table, pre, code, video, iframe, canvas, svg {
    max-width: 100%;
  }

  img { height: auto; }

  /* ==================== 分步向导 (仅手机端) ==================== */
  .wizard-container {
    flex-direction: column;
    min-height: 100vh;
  }

  /* 步骤进度条 */
  .wizard-progress {
    display: none;
    padding: 1rem 0.75rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 56px;
    z-index: 100;
  }

  .wizard-steps {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
  }

  .wizard-step-dot {
    width: 32px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-color);
    transition: all 0.3s ease;
  }

  .wizard-step-dot.active {
    background: var(--primary-color);
    width: 40px;
  }

  .wizard-step-dot.done {
    background: rgba(255, 107, 53, 0.3);
  }

  .wizard-step-label {
    display: none;
  }

  /* 步骤面板 */
  .wizard-panel {
    display: none;
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
  }

  .wizard-panel.active {
    display: block;
  }

  .wizard-panel h2 {
    font-size: 18px;
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
  }

  .wizard-panel h2 .step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
  }

  /* 分步填入示例按钮 */
  .wizard-fill-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.85rem;
    padding: 0.35rem 0.75rem;
    font-size: 13px;
    background: rgba(255, 107, 53, 0.08);
    color: var(--primary-dark);
    border: 1px solid rgba(255, 107, 53, 0.2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    min-height: unset;
    width: auto;
  }

  .wizard-fill-btn:active {
    background: rgba(255, 107, 53, 0.15);
    transform: scale(0.97);
  }

  /* 导航按钮 */
  .wizard-nav {
    display: none;
    padding: 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    gap: 0.75rem;
    position: sticky;
    bottom: 0;
    z-index: 100;
  }

  .wizard-nav button {
    flex: 1;
    min-height: 48px;
    font-size: 16px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
  }

  .wizard-btn-prev {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color) !important;
  }

  .wizard-btn-next {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.25);
  }

  .wizard-btn-next:active {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    transform: scale(0.97);
  }

  .wizard-btn-next:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* 书籍选择器移动端适配 */
  .book-selector-row {
    flex-direction: row;
    gap: 0.5rem;
  }

  .book-selector {
    font-size: 15px;
    padding: 0.6rem 0.75rem;
  }

  .btn-icon-only {
    width: 42px;
    height: 42px;
  }

  /* 手机端启用向导模式 */
  .wizard-container {
    display: flex !important;
  }

  .wizard-progress { display: block; }
  .wizard-nav { display: flex; }

  /* 隐藏原始布局 */
  .novel-container > .header,
  .main-content {
    display: none;
  }

  /* 输出区域在最后一步的特殊处理 */
  #wizardStep4 .output-header {
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 10;
    padding-bottom: 0.75rem;
  }

  #wizardStep4 .action-buttons {
    display: flex;
  }
}

/* ==================== 小屏手机 (≤480px) ==================== */
@media (max-width: 480px) {
  .header h1 { font-size: 18px; }
  .header p { font-size: 12px; }

  .navbar-right { gap: 0.25rem; }
  .navbar-left { gap: 0.25rem; }

  input, select, textarea {
    font-size: 15px !important;
    padding: 0.6rem;
  }

  button { font-size: 15px; }

  .wizard-panel h2 { font-size: 16px; }
}

/* ==================== 触摸优化 ==================== */
@media (hover: none) and (pointer: coarse) {
  button, a, input, select, textarea {
    min-height: 44px;
    min-width: 44px;
  }

  button:active, .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  .sidebar-menu {
    -webkit-overflow-scrolling: touch;
  }

  button, .btn, .nav-btn {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}
