/* ============================================
   海龟汤 - 在线推理游戏 样式表
   适配微信内置浏览器
   ============================================ */

/* ---------- CSS变量 ---------- */
:root {
  --primary: #07c160;
  --primary-dark: #06ad56;
  --primary-light: #e8f8ef;
  --secondary: #576b95;
  --danger: #fa5151;
  --warning: #ffc300;
  --bg: #ededed;
  --bg-white: #ffffff;
  --text: #333333;
  --text-secondary: #888888;
  --text-light: #b2b2b2;
  --border: #e5e5e5;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: 50px;

  /* 汤类型颜色 */
  --white-soup: #f0f0f0;
  --red-soup: #ffe0e0;
  --black-soup: #e0e0e0;
  --white-soup-text: #666;
  --red-soup-text: #d32f2f;
  --black-soup-text: #333;
}

/* ---------- 全局重置 ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 禁止微信下拉刷新 */
  overscroll-behavior: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* 禁止长按选择 */
img, a, button, input, textarea, select {
  -webkit-touch-callout: none;
}

a {
  text-decoration: none;
  color: var(--secondary);
}

/* ---------- 页面通用 ---------- */
.page {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.page.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ---------- 页面头部 ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 12px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.page-header h2 {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  flex: 1;
}

.header-spacer {
  width: 60px;
}

.btn-back {
  background: none;
  border: none;
  font-size: 15px;
  color: var(--secondary);
  cursor: pointer;
  padding: 8px 4px;
  width: 60px;
  text-align: left;
}

/* ---------- 页面主体 ---------- */
.page-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

/* ---------- 首页 ---------- */
#page-home {
  background: linear-gradient(180deg, #07c160 0%, #06ad56 40%, var(--bg) 100%);
}

.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 24px;
}

.logo-area {
  text-align: center;
  margin-bottom: 48px;
}

.logo-icon {
  font-size: 72px;
  margin-bottom: 12px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.logo-title {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  margin-bottom: 8px;
}

.logo-subtitle {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.85);
}

.home-actions {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-footer {
  margin-top: auto;
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  padding-bottom: var(--safe-bottom);
}

.home-footer .version {
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.5;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 10px 20px;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg-white);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:active {
  background: #f5f5f5;
}

.btn-outline {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
}

.btn-outline:active {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 16px;
  border-radius: var(--radius);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  font-size: 18px;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- 表单 ---------- */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}

.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--bg-white);
  transition: border-color 0.2s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.1);
}

.input::placeholder {
  color: var(--text-light);
}

.textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.input-with-hint {
  position: relative;
}

.input-with-hint .hint {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-light);
  pointer-events: none;
}

/* 单选组 */
.radio-group {
  display: flex;
  gap: 10px;
}

.radio-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.radio-item input[type="radio"] {
  display: none;
}

.radio-item.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 500;
}

/* ---------- 游戏页面 ---------- */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 12px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.game-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.room-id-display {
  font-size: 13px;
  color: var(--text-secondary);
}

.room-id-display span {
  font-weight: 600;
  color: var(--text);
}

.btn-copy {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

.game-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.btn-menu {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text);
}

/* 游戏菜单 */
.game-menu {
  position: absolute;
  top: var(--header-height);
  right: 8px;
  background: var(--bg-white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 20;
  overflow: hidden;
  border: 1px solid var(--border);
}

.game-menu button {
  display: block;
  width: 100%;
  padding: 12px 20px;
  border: none;
  background: none;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.game-menu button:active {
  background: #f5f5f5;
}

.game-menu button + button {
  border-top: 1px solid var(--border);
}

/* 汤面展示区 */
.puzzle-surface-area {
  background: var(--bg-white);
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.surface-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}

.surface-content {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  max-height: 120px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.type-badge {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.type-badge.white {
  background: var(--white-soup);
  color: var(--white-soup-text);
}

.type-badge.red {
  background: var(--red-soup);
  color: var(--red-soup-text);
}

.type-badge.black {
  background: var(--black-soup);
  color: var(--black-soup-text);
}

/* 问答记录区 */
.qa-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.qa-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-light);
  text-align: center;
}

.qa-empty p:first-child {
  font-size: 18px;
  margin-bottom: 8px;
}

.qa-empty .tip {
  font-size: 13px;
}

/* 单条问答 */
.qa-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qa-question {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.qa-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  color: var(--primary);
  font-weight: 600;
}

.qa-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.qa-bubble-question {
  background: var(--primary);
  color: #fff;
  border-top-left-radius: 4px;
}

.qa-bubble-answer {
  background: var(--bg-white);
  color: var(--text);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  margin-left: 40px;
}

.qa-answer-yes {
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 500;
}

.qa-answer-no {
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 500;
}

.qa-answer-irrelevant {
  border-color: var(--warning);
  color: #b8860b;
  font-weight: 500;
}

.qa-player-name {
  font-size: 11px;
  color: var(--text-light);
  margin-left: 40px;
}

/* 汤底揭晓 */
.answer-reveal {
  background: linear-gradient(135deg, #fff9e6 0%, #fff3cc 100%);
  padding: 16px;
  border-top: 2px solid var(--warning);
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.answer-label {
  font-size: 14px;
  font-weight: 600;
  color: #b8860b;
  margin-bottom: 8px;
}

.answer-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* 提问输入区 */
.question-input-area {
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-wrapper .input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
}

.btn-send {
  border-radius: 20px;
  padding: 10px 18px;
  flex-shrink: 0;
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none !important;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  width: 100%;
  max-height: 70vh;
  background: var(--bg-white);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

/* 玩家列表 */
.player-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
  padding-bottom: var(--safe-bottom);
}

.player-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}

.player-item + .player-item {
  border-top: 1px solid var(--border);
}

.player-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--primary);
  font-weight: 600;
  flex-shrink: 0;
}

.player-name {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
}

.player-role {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.player-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.player-status.offline {
  background: var(--text-light);
}

/* ---------- 题库管理 ---------- */
.library-toolbar {
  margin-bottom: 16px;
}

.library-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--bg-white);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 500;
}

.library-actions {
  display: flex;
  gap: 8px;
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-tip {
  text-align: center;
  color: var(--text-light);
  padding: 40px 0;
  font-size: 14px;
}

/* 题目卡片 */
.puzzle-card {
  background: var(--bg-white);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
}

.puzzle-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.puzzle-card-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.puzzle-card-type {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  flex-shrink: 0;
  margin-left: 8px;
}

.puzzle-card-type.white {
  background: var(--white-soup);
  color: var(--white-soup-text);
}

.puzzle-card-type.red {
  background: var(--red-soup);
  color: var(--red-soup-text);
}

.puzzle-card-type.black {
  background: var(--black-soup);
  color: var(--black-soup-text);
}

.puzzle-card-preview {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}

.puzzle-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.puzzle-card-actions button {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-white);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.puzzle-card-actions button:active {
  background: #f5f5f5;
}

.puzzle-card-actions .btn-delete {
  color: var(--danger);
  border-color: var(--danger);
}

/* 题库选择列表（创建房间用） */
.puzzle-select-list {
  max-height: 300px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.puzzle-select-item {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.puzzle-select-item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.puzzle-select-item .title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.puzzle-select-item .preview {
  font-size: 12px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Toast提示 ---------- */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 200;
  text-align: center;
  max-width: 80%;
  word-break: break-word;
  animation: fadeIn 0.2s ease;
  pointer-events: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- Loading ---------- */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 150;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---------- 滚动条美化 ---------- */
::-webkit-scrollbar {
  width: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

/* ---------- 微信环境特殊适配 ---------- */
@supports (-webkit-overflow-scrolling: touch) {
  .page-body,
  .qa-list,
  .player-list,
  .puzzle-select-list {
    -webkit-overflow-scrolling: touch;
  }
}

/* 安全区域适配（iPhone X+） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .question-input-area {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .home-footer {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .player-list {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ---------- 响应式微调 ---------- */
@media screen and (min-width: 414px) {
  .home-actions {
    max-width: 360px;
  }

  .qa-bubble {
    max-width: 65%;
  }
}

@media screen and (max-width: 320px) {
  .logo-icon {
    font-size: 56px;
  }

  .logo-title {
    font-size: 28px;
  }

  .btn-lg {
    padding: 12px 20px;
    font-size: 15px;
  }

  .radio-group {
    flex-direction: column;
  }
}

/* ---------- 题库来源标签 ---------- */
.library-item-origin {
  font-size: 11px;
  color: var(--text-light);
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
  display: inline-block;
  vertical-align: middle;
}
