* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: #f7f2e7;
}

body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: linear-gradient(180deg, #fffdf8 0%, #f8f2e6 48%, #efe5d2 100%);
  color: #2b2620;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------------- 通用隐藏 ---------------- */
.hidden {
  display: none !important;
}

/* ---------------- 整体布局 ---------------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------------- 顶部信息栏 ---------------- */

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 6px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.hud-label {
  font-size: 10px;
  color: #a3947c;
  letter-spacing: 0.08em;
}

.hud-value {
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #3a332a;
}

.hud-preview {
  margin-left: auto;
  flex-direction: row;
  align-items: center;
  gap: 7px;
   flex-shrink: 0;
}

#preview {
  display: block;
  border-radius: 8px;
  background: rgba(140, 115, 75, 0.08);
}

/* ---------------- 棋盘区域 ---------------- */

#board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

#board {
  display: block;
  border-radius: 10px;
  touch-action: none;
  box-shadow: 0 12px 28px rgba(140, 105, 50, 0.18),
              0 3px 8px rgba(140, 105, 50, 0.12);
}

/* ---------------- 结束遮罩 ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(250, 246, 238, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 16px;
}

.overlay-box {
  background: #fffdf9;
  border: 1px solid rgba(165, 140, 95, 0.22);
  border-radius: 16px;
  padding: 22px 22px 20px;
  text-align: center;
  min-width: 240px;
  max-width: 340px;
  width: calc(100% - 40px);
  box-sizing: border-box;
  box-shadow: 0 14px 40px rgba(140, 110, 60, 0.18);
}

.overlay-box h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  color: #3a332a;
}

#overlay-text {
  margin: 0 0 16px;
  font-size: 13px;
  color: #8d8271;
  line-height: 1.6;
}

/* ---------------- 遮罩里的按钮 ---------------- */

.overlay-btn {
  display: block;
  width: 100%;
  padding: 11px 0;
  border: none;
  border-radius: 10px;
  background: #cf9633;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 0 rgba(150, 105, 25, 0.35);
  transition: background 0.08s, transform 0.08s;
}

.overlay-btn + .overlay-btn {
  margin-top: 8px;
}

.overlay-btn:active {
  background: #b9822a;
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(150, 105, 25, 0.35);
}

.overlay-btn:disabled {
  background: #dcd4c2;
  color: #fffdf9;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.overlay-btn:disabled:active {
  background: #dcd4c2;
  transform: none;
  box-shadow: none;
}

.overlay-btn-link {
  background: transparent;
  color: #8d8271;
  box-shadow: none;
  font-weight: 500;
  font-size: 13px;
  padding: 8px 0;
}

.overlay-btn-link:active {
  background: transparent;
  color: #6b6154;
  transform: none;
  box-shadow: none;
}

/* ---------------- 留名区 ---------------- */

.name-form {
  margin: 4px 0 12px;
}

.name-form-tip {
  margin: 0 0 10px !important;
  font-size: 13px !important;
  color: #cf9633 !important;
  font-weight: 600;
  line-height: 1.5 !important;
}

#name-input {
  display: block;
  width: 100%;
  height: 42px;
  padding: 0 12px;
  margin: 0 0 10px;
  border: 1px solid rgba(165, 140, 95, 0.4);
  border-radius: 10px;
  background: #fffdf9;
  color: #2b2620;
  font-size: 16px;
  font-family: inherit;
  text-align: center;
  letter-spacing: 0.16em;
  outline: none;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

#name-input::placeholder {
  letter-spacing: 0;
  color: #b9ad9a;
}

#name-input:focus {
  border-color: #cf9633;
  box-shadow: 0 0 0 3px rgba(207, 150, 51, 0.18);
}

.name-form-error {
  margin: 0 0 10px !important;
  font-size: 12px !important;
  color: #c6543b !important;
  line-height: 1.5 !important;
}

/* ---------------- 世界排行榜 ---------------- */

.overlay-rank-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 600;
  color: #3a332a;
}

.world-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 320px;
  overflow-y: auto;
  padding: 2px;
  margin: 0 0 14px;
  text-align: left;
}

.world-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #fffdf9;
  border: 1px solid rgba(165, 140, 95, 0.14);
  border-radius: 8px;
  font-size: 13px;
}

.world-row-me {
  background: #fbeecb;
  border-color: #cf9633;
}

.world-rank {
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #f0e3c8;
  color: #8a6a2a;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.world-row:nth-child(1) .world-rank {
  background: #f5d76e;
  color: #6a4a00;
}

.world-row:nth-child(2) .world-rank {
  background: #dcdcdc;
  color: #555;
}

.world-row:nth-child(3) .world-rank {
  background: #e4b98a;
  color: #6a3a10;
}

.world-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #3a332a;
  font-weight: 600;
}

.world-score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #3a332a;
}

/* ---------------- 底部操作按键 ---------------- */

#controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.ctrl {
  height: 54px;
  min-width: 0;
  border-radius: 12px;
  border: 1px solid rgba(165, 140, 95, 0.28);
  background: #fffdf9;
  color: #4a4238;
  font-size: 21px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.08s, transform 0.08s;
  touch-action: none;
  padding: 0;
  box-shadow: 0 2px 5px rgba(150, 120, 70, 0.10);
}

.ctrl:active {
  background: #f2ebdd;
  transform: scale(0.96);
}

.ctrl-primary {
  background: #fbeecb;
  border-color: rgba(200, 150, 60, 0.45);
  color: #8a5f13;
}

.ctrl-primary:active {
  background: #f5e2b2;
}

/* ---------------- 超窄屏微调 ---------------- */

@media (max-height: 620px) {
  .ctrl { height: 46px; font-size: 18px; }
  #hud { padding: 6px 12px 4px; }
  .hud-value { font-size: 17px; }
}

@media (max-width: 340px) {
  #controls { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .ctrl { height: 48px; font-size: 18px; border-radius: 10px; }
}