:root {
  --bg: #f7f3e8;
  --ink: #4b443c;
  --muted: #7b7167;
  --panel: #fffdf8;
  --board: #a99786;
  --cell: #c9bbad;
  --accent: #e86f3d;
  --accent2: #f4c95d;
  --shadow: 0 18px 55px rgba(61, 47, 33, 0.13);
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}
body {
  font-family: Inter, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background:
    radial-gradient(circle at 10% 0, #fff 0, transparent 34%),
    linear-gradient(145deg, var(--bg), #ede1ca);
  color: var(--ink);
  user-select: none;
}
body[data-dojo='cherry_shrine'] {
  --bg: #fff0f5;
  --accent: #d94f86;
  --accent2: #ffd0dd;
  --board: #ab7b90;
  --cell: #d9b8c6;
}
body[data-dojo='sunset_beach'] {
  --bg: #fff3d6;
  --accent: #ef704d;
  --accent2: #63c7c9;
  --board: #aa8568;
  --cell: #d9c5a8;
}
.app {
  width: min(1040px, 100%);
  margin: auto;
  padding: 22px;
}
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.back {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
  font-size: 24px;
}
.header h1 {
  margin: 0;
  font-size: clamp(32px, 6vw, 58px);
  letter-spacing: -3px;
}
.header h1 span {
  font-size: 0.3em;
  letter-spacing: 0.18em;
  color: var(--accent);
}
.header p {
  margin: 0;
  color: var(--muted);
}
.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
button,
select {
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  box-shadow: 0 5px 16px rgba(61, 47, 33, 0.1);
  cursor: pointer;
}
button:hover {
  transform: translateY(-1px);
}
button:disabled {
  opacity: 0.4;
  transform: none;
  cursor: not-allowed;
}
.stats {
  display: flex;
  gap: 10px;
  margin: 0 0 18px 60px;
}
.stats div {
  background: var(--ink);
  color: white;
  border-radius: 14px;
  padding: 9px 18px;
  min-width: 100px;
}
.stats small {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  opacity: 0.7;
}
.stats strong {
  font-size: 22px;
}
.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 570px) minmax(220px, 1fr);
  gap: 22px;
  align-items: start;
}
.board {
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 12px;
  background: var(--board);
  border-radius: 22px;
  padding: 12px;
  box-shadow: var(--shadow);
  touch-action: none;
  outline: 3px solid transparent;
  outline-offset: 4px;
}
.board:focus-visible {
  outline-color: var(--accent);
}
.cell,
.tile {
  grid-area: auto;
  border-radius: 13px;
}
.cell {
  background: var(--cell);
  opacity: 0.72;
}
.tile {
  display: grid;
  place-items: center;
  font-size: clamp(22px, 5vw, 46px);
  font-weight: 900;
  z-index: 1;
  animation: pop 0.14s ease;
}
@keyframes pop {
  from {
    transform: scale(0.82);
  }
  to {
    transform: scale(1);
  }
}
.tile-2 {
  background: #eee4da;
}
.tile-4 {
  background: #ede0c8;
}
.tile-8 {
  background: #f2b179;
  color: #fff;
}
.tile-16 {
  background: #f59563;
  color: #fff;
}
.tile-32 {
  background: #f67c5f;
  color: #fff;
}
.tile-64 {
  background: #f65e3b;
  color: #fff;
}
.tile-128 {
  background: #edcf72;
  color: #fff;
}
.tile-256 {
  background: #edcc61;
  color: #fff;
}
.tile-512 {
  background: #edc850;
  color: #fff;
}
.tile-1024 {
  background: #edc53f;
  color: #fff;
  font-size: clamp(18px, 4vw, 38px);
}
.tile-2048 {
  background: linear-gradient(135deg, #ffe47a, #e9a91a);
  color: #fff;
  box-shadow: 0 0 28px #ffcb40;
}
.tile-super {
  background: #2d3346 !important;
  color: #fff;
  font-size: clamp(17px, 3.5vw, 34px);
}
.hint {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.primary {
  background: linear-gradient(135deg, var(--accent), #d64e33);
  color: #fff;
}
.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  padding: 17px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h2 {
  font-size: 17px;
  margin: 0 0 13px;
}
.power-grid {
  display: grid;
  gap: 9px;
}
.power-grid button {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.power-grid b {
  margin-left: auto;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  min-width: 26px;
  padding: 3px 7px;
}
.micro {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.rank-list {
  padding: 0;
  margin: 0;
  list-style: none;
}
.rank-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 6px;
  padding: 9px 2px;
  border-bottom: 1px solid rgba(100, 80, 60, 0.1);
  font-size: 13px;
}
.login {
  display: block;
  color: var(--accent);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 12px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  opacity: 0;
  background: #222;
  color: white;
  border-radius: 999px;
  padding: 12px 20px;
  transition: 0.2s;
  z-index: 20;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, 0.62);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 18px;
}
.overlay[hidden] {
  display: none;
}
.dialog {
  position: relative;
  background: var(--panel);
  border-radius: 26px;
  padding: 34px;
  text-align: center;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
}
.dialog .medal {
  font-size: 64px;
}
.dialog h2 {
  font-size: 28px;
  margin: 10px;
}
.dialog > div:last-child {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.close {
  position: absolute;
  right: 12px;
  top: 12px;
  box-shadow: none;
  font-size: 22px;
  padding: 4px 10px;
}
@media (max-width: 760px) {
  .app {
    padding: 12px;
  }
  .header {
    align-items: flex-start;
  }
  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .header-actions select,
  .icon-btn {
    font-size: 12px;
    padding: 8px;
  }
  .stats {
    margin-left: 0;
  }
  .stats div {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
  }
  .game-layout {
    display: block;
  }
  .board {
    gap: 8px;
    padding: 8px;
    border-radius: 17px;
  }
  .panel {
    margin-top: 16px;
  }
  .power-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .power-grid button {
    font-size: 12px;
    display: grid;
    text-align: center;
  }
  .power-grid b {
    margin: auto;
  }
  .tile,
  .cell {
    border-radius: 9px;
  }
}
