* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --text: #e6e6e6;
  --panel-bg: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.15);
}

body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden; /* 棋盘自适应后强制一屏 */
}

/* 背景装饰 emoji */
.decor { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.decor span { position: absolute; animation: floaty 4.5s ease-in-out infinite alternate; }
@keyframes floaty { from { transform: translateY(0); } to { transform: translateY(-16px); } }

/* 横屏/宽屏：三栏布局（左栏 / 全高棋盘 / 右栏三段卡片） */
.app {
  position: relative;
  z-index: 1;
  height: 100vh;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start; /* 左/右栏靠顶，棋盘在其中居中 */
}

/* 左栏：返回 + 标题 + 皮肤（竖排，低频） */
header { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
h1 { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.back {
  font-size: 1.2rem;
  text-decoration: none;
  color: inherit;
  opacity: 0.75;
  padding: 8px 10px;
  touch-action: manipulation;
}
.back:active { opacity: 1; }

.skin-open-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}
.skin-open-btn:active { transform: scale(0.96); }

/* 中栏：棋盘居中，占满可用高度 */
main { display: flex; align-items: center; justify-content: center; min-width: 0; }
.board-wrap { position: relative; flex-shrink: 0; }
#board {
  width: 100%;
  height: auto;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 12px;
  cursor: pointer;
  padding: 16px;
}
.overlay.hidden { display: none; }
.overlay h2 { font-size: 1.5rem; }
.overlay p { opacity: 0.85; font-size: 0.85rem; }
.overlay-btn {
  margin-top: 6px;
  padding: 12px 38px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #5a3b00;
  background: linear-gradient(135deg, #ffd43b, #ff9f1c);
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(255, 159, 28, 0.4);
  cursor: pointer;
  touch-action: manipulation;
}
.overlay-btn:active { transform: scale(0.96); }

/* 右栏：三段透明卡片 */
.panel { display: flex; flex-direction: column; gap: 10px; width: 210px; }
.rail-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

/* 卡片1：只读信息（下一个一行 + 四个数字 2×2，省横屏高度） */
.card-info { display: flex; flex-direction: column; gap: 8px; }
.card-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.stat {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat .label { font-size: 0.66rem; opacity: 0.65; }
.stat > span:last-child { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.card-stats .stat { padding: 6px 8px; }
.card-stats .stat > span:last-child { font-size: 1.15rem; }
#next { background: rgba(0, 0, 0, 0.25); border-radius: 8px; width: 84px; height: 84px; }

/* 卡片2：暂停/重开 */
.card-ops { display: flex; flex-direction: column; gap: 8px; }
.ops-row { display: flex; gap: 8px; }
.panel-btn {
  flex: 1;
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.panel-btn:disabled { opacity: 0.45; }
.panel-btn:active { transform: scale(0.97); }
.hint { font-size: 0.68rem; opacity: 0.55; line-height: 1.7; text-align: center; }

/* 卡片3：高频操控（仅触屏显示） */
.card-touch { display: none; }
body.touch .card-touch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.card-touch button {
  min-height: 54px;
  font-size: 1.4rem;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  touch-action: manipulation;
}
.card-touch button:active { transform: scale(0.95); }
#btnLeft { grid-column: 1; }
#btnRight { grid-column: 3; }
#btnRotate { grid-column: 1; }
#btnDown { grid-column: 2; }
#btnDrop { grid-column: 3; }

body.touch .hint { display: none; }

/* 皮肤弹层（显隐由 JS 内联样式控制） */
.skin-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 20px;
}
.skin-modal.hidden { display: none; }
.skin-modal-card {
  background: #20242f;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  max-width: 480px;
}
.skin-modal-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 1rem;
  font-weight: 600;
}
.skin-close {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 10px;
  touch-action: manipulation;
}
.skins { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.skin-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #eee;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  font-size: 0.72rem;
  cursor: pointer;
  touch-action: manipulation;
}
.skin-btn .skin-icon { font-size: 1.7rem; line-height: 1; }
.skin-btn.active { border-color: #ffb703; background: rgba(255, 183, 3, 0.2); }
.skin-btn:active { transform: scale(0.94); }

/* 大屏（桌面）：右侧栏整体放大，基于屏幕自适应 */
@media (min-width: 1200px) {
  .panel { width: 250px; }
  h1 { font-size: 1.3rem; }
  .skin-open-btn { font-size: 1rem; padding: 10px 20px; }
  .stat > span:last-child { font-size: 1.6rem; }
  .card-stats .stat > span:last-child { font-size: 1.35rem; }
  #next { width: 104px; height: 104px; }
  .panel-btn { min-height: 58px; font-size: 1.2rem; }
  .card-touch button { min-height: 64px; font-size: 1.6rem; }
  .hint { font-size: 0.78rem; }
}

/* 窄屏（手机/平板竖屏）：单列布局，顶栏细条 */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
    min-height: 0;
    align-content: start; /* 行靠顶，不被拉伸 */
    gap: 8px;
    padding: 8px 10px;
    align-items: stretch;
  }
  header { flex-direction: row; align-items: center; gap: 10px; }
  .skin-open-btn { margin-left: auto; }
  main { padding: 0; }

  .panel { width: 100%; max-width: 340px; margin: 0 auto; gap: 4px; }
  .rail-card { padding: 6px; }
  .card-info { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .card-info .next-stat { grid-column: span 2; }
  .card-stats { display: contents; } /* 竖屏恢复旧式 4 列流式排布 */
  .card-info .stat { flex-direction: row; align-items: center; justify-content: space-between; gap: 0; padding: 5px 8px; }
  .card-info .stat .label { font-size: 0.6rem; }
  .card-info .stat > span:last-child { font-size: 0.95rem; }
  #next { width: 44px; height: 44px; }

  .card-ops { gap: 4px; }
  .ops-row { gap: 4px; }
  .panel-btn { min-height: 40px; font-size: 0.95rem; }

  body.touch .card-touch { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .card-touch button { min-height: 44px; font-size: 1.15rem; }

  .skins { grid-template-columns: repeat(4, 1fr); }
}
