/* 手机版布局：纵向棋盘 + 底部抽屉式棋谱面板 */

.mobile-app {
  --header-h: 2.75rem;
  --footer-h: auto;
  --mobile-side-pad: 4px;
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-top-bar {
  padding: 0.45rem 0.75rem;
}

.mobile-top-bar h1 {
  font-size: 1.05rem;
}

.mobile-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.3rem var(--mobile-side-pad) 0.45rem;
  gap: 0.3rem;
}

.mobile-game-meta {
  margin: 0;
  padding: 0 0.15rem;
  font-size: 0.78rem;
  border: none;
}

.mobile-board-stack {
  width: calc(100vw - var(--mobile-side-pad) * 2);
  max-width: calc(100vw - var(--mobile-side-pad) * 2);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
}

.mobile-board-unit {
  display: block;
  width: 100%;
}

.mobile-board-head-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 1.75rem;
  margin-bottom: 0.3rem;
  padding: 0 0.1rem;
}

.mobile-board-head-bar .move-indicator {
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.mobile-board-area {
  display: block;
  position: static;
  transform: none;
  padding: 0;
  width: 100%;
}

.mobile-board-col {
  width: 100%;
  max-width: 100%;
  align-items: center;
  padding: 0;
}

.mobile-board-size-wrap {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  margin: 0;
  flex-shrink: 0;
}

.mobile-board-size-select {
  min-width: 4.1rem;
  padding: 0.28rem 1.6rem 0.28rem 0.45rem;
  border-radius: 6px;
  border: 1px solid rgba(240, 160, 32, 0.55);
  background: rgba(10, 22, 40, 0.88) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23f0a020' d='M1 1l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 0.4rem center;
  background-size: 0.55rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.mobile-board-size-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mobile-app #goBoard {
  max-height: none;
  max-width: 100%;
  box-shadow: 0 6px 24px var(--board-shadow);
  cursor: url("../img/cursor-hand.png?v=3") 16 3, pointer;
}

.mobile-board-unit canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  max-width: 100%;
  touch-action: none;
}

.mobile-board-stack .mobile-playback,
.mobile-board-stack .mobile-board-rail {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

.mobile-board-rail {
  gap: 0.3rem;
}

.mobile-markup-tools {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
}

.mobile-markup-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.3rem;
  width: 100%;
}

.mobile-markup-row .place-btn,
.mobile-markup-row .mark-btn,
.mobile-markup-row .board-shape-wrap {
  width: 100%;
  min-width: 0;
  height: 2.35rem;
  min-height: 2.35rem;
  max-height: 2.35rem;
}

.mobile-markup-row .board-shape-wrap > .place-btn,
.mobile-markup-row .board-shape-wrap > #btnDrawShapes {
  width: 100%;
  height: 100%;
}

.mobile-markup-row2 .mark-btn-undo {
  font-size: 0.62rem;
  line-height: 2.35rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 交替：去掉文字，黑白子交叉叠放 */
.mobile-app .mobile-markup-row1 .place-btn-alt::before {
  left: 50%;
  top: 50%;
  right: auto;
  bottom: auto;
  width: 1rem;
  height: 1rem;
  transform: translate(calc(-50% - 0.2rem), calc(-50% - 0.12rem));
  z-index: 2;
}

.mobile-app .mobile-markup-row1 .place-btn-alt::after {
  left: 50%;
  top: 50%;
  right: auto;
  bottom: auto;
  width: 1rem;
  height: 1rem;
  transform: translate(calc(-50% + 0.2rem), calc(-50% + 0.12rem));
  z-index: 1;
}

.mobile-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.mobile-trial-btn {
  width: 100%;
  min-height: 2.4rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* 手顺控制：7 个按钮单行等宽 */
.mobile-app .mobile-playback.playback-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 0.2rem;
  width: 100%;
}

.mobile-app .mobile-playback.playback-grid > button {
  width: 100%;
  height: 2.15rem;
  min-width: 0;
}

.mobile-app .mobile-playback.playback-grid #btnPlay {
  grid-column: auto;
  width: 100%;
  font-size: 0.62rem;
  letter-spacing: 0;
}

.mobile-app .mobile-playback.playback-grid .btn-skip5 {
  grid-column: auto;
}

.mobile-panel-toggle {
  width: 100%;
  margin: 0.15rem 0 0;
  padding: 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #2a5080 0%, #1a3050 100%);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.mobile-side-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  width: 100%;
  max-width: 100%;
  max-height: min(72vh, 520px);
  margin: 0;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
  transform: translateY(100%);
  transition: transform 0.25s ease;
}

.mobile-side-panel.open {
  transform: translateY(0);
}

.mobile-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-bottom: 0.35rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
}

.mobile-panel-close {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.mobile-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 350;
  background: rgba(0, 0, 0, 0.5);
}

.mobile-panel-backdrop[hidden] {
  display: none;
}

.mobile-tools .tool-row {
  flex-wrap: wrap;
}

.mobile-tools .tool-row button,
.mobile-tools .file-btn {
  flex: 1 1 calc(50% - 0.25rem);
  min-width: 0;
  font-size: 0.75rem;
}

.mobile-panel-footer {
  margin-top: 0.35rem;
}

.mobile-status-bar {
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.4rem 0.65rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.72rem;
}

.mobile-status-bar > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-zoom {
  margin-left: 0;
  width: 100%;
  font-size: 0.72rem;
}

.mobile-zoom input[type='range'] {
  flex: 1;
}

.mobile-app .judge-modal {
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(300px, calc(100vw - 1.5rem));
}

.mobile-app .judge-modal.judge-modal-positioned,
.mobile-app .judge-modal.judge-modal-user-pos {
  transform: none;
}

.mobile-app .board-area > .judge-modal {
  order: unset;
}

.mobile-app .shape-tool-popover {
  bottom: 100%;
  top: auto;
  margin-bottom: 0.25rem;
}

@media (orientation: landscape) and (max-height: 500px) {
  .mobile-side-panel {
    max-height: 85vh;
  }

  .mobile-board-wrap canvas {
    max-height: calc(100dvh - 11rem);
  }
}
