/* 五子棋打谱工具 — 雅木亮色主题（移动端优先） */
:root {
  --radius-btn: 10px;
  --shadow-ctrl: inset 0 1px 0 rgba(255, 255, 255, .6), 0 -1px 0 rgba(80, 55, 25, .1), 0 -4px 18px rgba(80, 55, 25, .12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #f6ecd9 0%, #efe0c2 100%);
  color: #4a3420;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
}

/* ---------- 顶部操作栏（浅色，去标题） ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 14px 10px;
  background: transparent;
  color: #5a3d24;
  z-index: 10;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.top-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(107, 74, 46, .08);
  color: #5a3d24;
  position: relative;
}

.top-btn:active {
  background: rgba(107, 74, 46, .18);
}

.top-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* 顶部导航按钮：新建/返回图标交叉过渡 */
.nav-new,
.nav-back {
  position: absolute;
  inset: 0;
  margin: auto;
  transition: opacity .18s ease, transform .18s ease;
}

.nav-back {
  opacity: 0;
}

.top-btn-primary {
  background: #d9983f;
  color: #fff;
}

.top-btn-primary:active {
  background: #c8872f;
}

/* 未保存修改：保存按钮背景加深提示 */
.top-btn-primary.dirty {
  background: #9c5c0e;
  color: #fff;
}

.top-btn-primary.dirty:active {
  background: #854f0c;
}

/* ---------- 棋盘区 ---------- */
.board-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px 10px calc(16px + env(safe-area-inset-bottom));
}

.game-name {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 700;
  color: #6b4a2e;
  text-align: center;
  max-width: 82%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-column {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 棋盘 + 控制栏居中容器（信息栏贴顶） */
.board-center {
  flex: 1 1 auto;
  min-height: 0;
  width: min(96vw, calc(100dvh - 270px));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 棋盘上方信息栏：外层容器高度自适应内容，批注过长时上限内滚动 */
.board-info-wrap {
  height: 92px;
  flex: 0 0 auto;
  width: min(96vw, calc(100dvh - 270px));
}

.board-info {
  width: 100%;
  max-height: 150px;
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(107, 74, 46, .08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7);
}

.board-coords-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.board-coords {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, "Consolas", "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
  color: #6b4a2e;
  line-height: 1.45;
  letter-spacing: .5px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.board-coords::-webkit-scrollbar {
  display: none;
}

.copy-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(107, 74, 46, .08);
  color: #5a3d24;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.copy-btn .icon {
  width: 15px;
  height: 15px;
}

.copy-btn:active {
  background: rgba(107, 74, 46, .18);
}

/* 批注显示/隐藏：max-height + opacity 过渡，带动信息栏高度平滑变化 */
.board-note {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  position: relative;
  font-size: 12px;
  color: #8a6f4a;
  line-height: 1.5;
  padding-left: 13px;
  word-break: break-all;
  transition: max-height .25s ease, opacity .25s ease;
}
/* 批注左侧小圆点，颜色随标记（JS 设 --note-dot） */
.board-note::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--note-dot, #c9984a);
}

.board-note.show {
  max-height: 120px;
  opacity: 1;
  overflow-y: auto;
}

.board-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  box-shadow: 0 6px 22px rgba(80, 55, 25, .35), inset 0 0 0 1px rgba(120, 85, 40, .3);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  touch-action: none;
}

/* ---------- 棋谱列表视图（main 内展示，1 行 n 列横向卡片） ---------- */
.games-view {
  flex: 1 1 auto;
  min-height: 0;
  display: none;
  flex-direction: column;
  width: 100%;
}

.board-area.games-mode .board-column {
  display: none;
}

.board-area.games-mode .games-view {
  display: flex;
}

/* 分类标签栏 */
.cat-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 8px;
}

.cat-tabs {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.cat-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(107, 74, 46, .08);
  color: #5a3d24;
  font-size: 13px;
}

.cat-tab.active {
  background: #d9983f;
  color: #fff;
  font-weight: 600;
}

.cat-manage {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(107, 74, 46, .08);
  color: #5a3d24;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cat-manage .icon {
  width: 18px;
  height: 18px;
}

.cat-manage:active {
  background: rgba(107, 74, 46, .18);
}

/* 分类选择 / 分类管理弹窗内容 */
.cat-pick {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-opt {
  padding: 10px 12px;
  border-radius: 10px;
  background: #f3e8d0;
  font-size: 14px;
}

.cat-opt.active {
  background: #e2d0a8;
  box-shadow: inset 0 0 0 1.5px #c9984a;
}

.cat-new {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.cat-new .name-input {
  margin-top: 0;
  flex: 1 1 auto;
}

.cat-add-btn {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  background: #d9983f;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.cat-mgr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #ece1c9;
}

.cat-mgr-row .more-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-mgr-row:last-child {
  border-bottom: none;
}

.cat-mgr-row .step-del {
  min-width: 38px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cat-mgr-row .step-del .icon {
  width: 18px;
  height: 18px;
}

.cat-mgr-row .cat-del {
  color: #a4572f;
}

.save-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.save-cat-chip {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(107, 74, 46, .08);
  color: #5a3d24;
  font-size: 13px;
}

.save-cat-chip.active {
  background: #d9983f;
  color: #fff;
  font-weight: 600;
}

.games-scroll {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 6px 2px 14px;
  scrollbar-width: none;
}

.games-scroll::-webkit-scrollbar {
  display: none;
}

.games-empty {
  flex: 0 0 auto;
  width: 100%;
  text-align: center;
  color: #b39a74;
  font-size: 14px;
  padding: 40px 0;
}

.game-card {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 250, 240, .95);
  box-shadow: 0 3px 12px rgba(80, 55, 25, .16), inset 0 1px 0 rgba(255, 255, 255, .65);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.game-card:active {
  transform: scale(.97);
  box-shadow: 0 1px 4px rgba(80, 55, 25, .14), inset 0 1px 0 rgba(255, 255, 255, .65);
}

.mini-board {
  width: 144px;
  height: 144px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #e6cda0;
}

.game-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.game-name-info {
  font-size: 14px;
  font-weight: 700;
  color: #6b4a2e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-coords {
  font-size: 11px;
  color: #8a6f4a;
  line-height: 1.5;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  word-break: break-all;
}

.game-coords::-webkit-scrollbar {
  display: none;
}

.game-acts {
  display: flex;
  gap: 6px;
}

.game-acts button {
  flex: 1 1 0;
  min-height: 34px;
  border-radius: 8px;
  background: #f0ddc4;
  color: #5a3d24;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.game-acts button .icon {
  width: 18px;
  height: 18px;
}

.game-acts button:active {
  background: #e7cdad;
}

.game-acts .act-del {
  color: #a4572f;
}

/* ---------- 底部控制栏 ---------- */
.ctrl-bar {
  flex: 0 0 auto;
  width: 100%;
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 14px;
  background: rgba(255, 250, 240, .45);
  box-shadow: 0 3px 12px rgba(80, 55, 25, .16), inset 0 1px 0 rgba(255, 255, 255, .65);
}

.ctrl-btn {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 12px;
  background: rgba(107, 74, 46, .06);
  color: #5a3d24;
}

.ctrl-btn .ctrl-icon {
  width: 22px;
  height: 22px;
}

/* 重置图标（圆弧较实）视觉偏大，调小以与线条 chevron 协调 */
#btn-reset .ctrl-icon {
  width: 19px;
  height: 19px;
}

.ctrl-btn:active {
  background: rgba(107, 74, 46, .16);
}

.ctrl-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}

/* ---------- 备注弹窗 ---------- */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(40, 25, 10, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: maskIn .18s ease;
}

.note-sheet {
  width: min(88vw, 360px);
  aspect-ratio: 1 / 1.3;
  max-height: 84dvh;
  background: #fffdf7;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(40, 25, 10, .3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn .18s ease;
}

.note-sheet-title {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 18px;
  font-weight: 700;
  color: #6b4a2e;
  padding: 14px 16px 10px;
}

.sheet-close {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(107, 74, 46, .08);
  color: #6b4a2e;
}

.sheet-close .icon {
  width: 18px;
  height: 18px;
}

.sheet-close:active {
  background: rgba(107, 74, 46, .18);
}

/* 步骤列表（5 列网格） */
.step-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  border-bottom: 1px solid #e6d7ba;
  scrollbar-width: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  align-content: start;
}

.step-list::-webkit-scrollbar {
  display: none;
}

.step-list.empty::after {
  content: "暂无落子，点击棋盘开始打谱";
  display: block;
  text-align: center;
  grid-column: 1 / -1;
  color: #7a5c38;
  font-size: 13px;
  padding: 18px 0;
}

.step-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #f3e8d0;
  font-size: 15px;
  font-weight: 700;
  color: #6b4a2e;
}

.step-cell.active {
  background: #e2d0a8;
  box-shadow: inset 0 0 0 2px #c9984a;
  color: #5a3d24;
}

.step-cell::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
}

.step-cell.good::after {
  background: #d95040;
}

.step-cell.bad::after {
  background: #3f6fb5;
}

.step-cell.question::after {
  background: #a85c10;
}

.step-note {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #6f5736;
  font-size: 12px;
}

.step-del {
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 8px;
  background: #f0ddc4;
  color: #a4572f;
  font-size: 12px;
}

.step-del:active {
  background: #e7cdad;
}

.step-del:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* 批注编辑区 */
.note-area {
  flex: 0 0 auto;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.note-head {
  font-size: 13px;
  font-weight: 600;
  color: #6b4a2e;
  flex: 1 1 auto;
}

.note-input {
  width: 100%;
  min-height: 52px;
  resize: none;
  border: 1px solid #dcc7a6;
  border-radius: 10px;
  background: #fffdf7;
  color: #4a3420;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  user-select: text;
  -webkit-user-select: text;
}

.note-input:disabled {
  background: #f1e8d4;
  color: #b39a74;
}

.mark-row {
  display: flex;
  gap: 8px;
}

.mark-btn {
  flex: 1 1 0;
  min-height: 44px;
  padding: 8px 0;
  border-radius: 10px;
  background: #f1e4ca;
  color: #5a3d24;
  font-size: 13px;
}

.mark-btn:active {
  background: #e4d2ae;
}

.mark-btn.active {
  color: #fff;
  font-weight: 600;
}

.mark-btn[data-mark="good"].active {
  background: #d95040;
}

.mark-btn[data-mark="bad"].active {
  background: #3f6fb5;
}

.mark-btn[data-mark="question"].active {
  background: #a85c10;
}

.mark-btn:disabled {
  opacity: .4;
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(40, 25, 10, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  width: 100%;
  max-width: 320px;
  background: #fffdf7;
  border-radius: 14px;
  padding: 18px 18px 12px;
  box-shadow: 0 10px 30px rgba(40, 25, 10, .3);
  max-height: 72dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: #6b4a2e;
  text-align: center;
  margin-bottom: 14px;
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  font-size: 14px;
  color: #5a3d24;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions button {
  flex: 1 1 0;
  padding: 9px 0;
  border-radius: 10px;
  background: #f1e4ca;
  color: #5a3d24;
  font-size: 14px;
}

.modal-actions button:active {
  background: #e4d2ae;
}

.modal-actions button.primary {
  background: #d9983f;
  color: #fff;
  font-weight: 600;
}

.modal-actions button.primary:active {
  background: #c8872f;
}

.modal-actions button.danger {
  background: #e2553d;
  color: #fff;
}

.modal-actions button.danger:active {
  background: #cc442e;
}

/* 更多弹窗内容 */
.more-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #ece1c9;
}

.more-row:last-child {
  border-bottom: none;
}

.more-label {
  font-size: 14px;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 13px;
  background: #d8c7a6;
  transition: background .2s;
}

.switch.on {
  background: #d9983f;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
}

.switch.on::after {
  left: 23px;
}

/* 保存名称输入 */
.save-body {
  padding: 6px 8px;
}

.name-input {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  border: 1px solid #dcc7a6;
  border-radius: 10px;
  background: #fffdf7;
  font-size: 14px;
  color: #4a3420;
}

.hidden {
  display: none !important;
}

/* ---------- 键盘焦点可见（输入控件点击聚焦不显示高亮） ---------- */
:focus-visible {
  outline: 2px solid #d9983f;
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
}

/* ---------- 弹窗进入动效 ---------- */
.modal-mask {
  animation: maskIn .18s ease;
}

.modal {
  animation: popIn .18s ease;
}

@keyframes maskIn {
  from {
    opacity: 0;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(.96) translateY(4px);
  }
}

/* ---------- 棋盘 / 棋谱列表视图切换动效 ---------- */
.board-column,
.games-view {
  animation: viewIn .18s ease;
}

.view-leave {
  animation: viewOut .18s ease forwards;
}

@keyframes viewOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 弱动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {

  .sheet-mask,
  .note-sheet {
    animation: none;
  }

  .modal-mask,
  .modal {
    animation: none;
  }

  .board-column,
  .games-view {
    animation: none !important;
  }
}

/* ---------- 移动端按压反馈 ---------- */
.top-btn,
.ctrl-btn,
.mark-btn,
.step-del,
.modal-actions button,
.game-acts button {
  transition: transform .1s ease, background-color .12s ease, opacity .2s ease;
}

.top-btn:active:not(:disabled),
.ctrl-btn:active:not(:disabled),
.mark-btn:active:not(:disabled),
.step-del:active:not(:disabled),
.modal-actions button:active:not(:disabled),
.game-acts button:active {
  transform: scale(.95);
}

.mark-btn:disabled {
  cursor: not-allowed;
  transform: none !important;
}
