:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #334155;
  --secondary-hover: #475569;
  --danger: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.15), transparent 30%),
    linear-gradient(180deg, #0b1020, #111827 45%, #0f172a);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 14px 28px;
}

.top-bar {
  text-align: center;
  margin-bottom: 18px;
}

.game-title {
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: 1px;
}

.game-subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 13px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 18px;
  align-items: start;
}

.board-section {
  display: flex;
  justify-content: center;
}

.canvas-wrapper {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 1 / 2;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, #0b1220, #111827);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(180deg, #0f172a, #0b1220);
  background-size: 10% 5%;
}

.panel-section {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 1fr));
  gap: 14px;
}

.card {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.card h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.info-list {
  display: grid;
  gap: 10px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
  border-radius: 10px;
}

.info-item span {
  color: var(--muted);
  font-size: 14px;
}

.info-item strong {
  font-size: 18px;
  color: #fff;
}

.preview-box {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 120px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.08);
}

#nextCanvas {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.primary-btn,
.secondary-btn,
.ctrl-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.secondary-btn {
  background: var(--secondary);
  color: #fff;
  font-weight: 700;
}

.secondary-btn:hover {
  background: var(--secondary-hover);
}

.ctrl-btn {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-weight: 700;
  min-height: 42px;
}

.ctrl-btn:hover {
  background: rgba(255,255,255,0.14);
}

.primary-btn:active,
.secondary-btn:active,
.ctrl-btn:active {
  transform: scale(0.96);
}

.difficulty-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.difficulty-wrap label {
  color: var(--muted);
  font-size: 14px;
}

.difficulty-wrap select {
  background: rgba(255,255,255,0.06);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.touch-controls {
  display: grid;
  gap: 10px;
}

.ctrl-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tips {
  list-style: none;
  display: grid;
  gap: 8px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
  z-index: 10;
}

.overlay.show {
  display: grid;
}

.overlay-card {
  width: min(88%, 300px);
  padding: 22px 18px;
  border-radius: 18px;
  text-align: center;
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  animation: popIn 0.35s ease;
}

.overlay-card.small {
  width: min(82%, 260px);
}

.overlay-card h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

.overlay-desc {
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 12px;
  font-size: 14px;
}

.game-over-card {
  animation: gameOverBounce 0.55s ease;
}

.game-over-title {
  color: #fff;
  text-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.line-flash {
  animation: lineFlash 0.22s ease;
}

@keyframes lineFlash {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.8);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes popIn {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes gameOverBounce {
  0% {
    transform: scale(0.75);
    opacity: 0;
  }
  60% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

/* 平板 */
@media (max-width: 960px) {
  .game-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .panel-section {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .canvas-wrapper {
    width: min(62vw, 300px);
  }
}

/* 手机 */
@media (max-width: 640px) {
  .app {
    padding: 12px 10px 20px;
  }

  .top-bar {
    margin-bottom: 14px;
  }

  .game-title {
    font-size: 26px;
  }

  .game-subtitle {
    font-size: 12px;
  }

  .panel-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .canvas-wrapper {
    width: min(72vw, 260px);
    border-radius: 14px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .card h3 {
    font-size: 15px;
  }

  .info-item {
    padding: 9px 10px;
  }

  .info-item strong {
    font-size: 17px;
  }

  #nextCanvas {
    width: 84px;
    height: 84px;
  }

  .button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .primary-btn,
  .secondary-btn,
  .ctrl-btn {
    padding: 10px 12px;
    font-size: 14px;
  }

  .ctrl-btn {
    min-height: 44px;
  }

  .overlay-card {
    width: min(90%, 280px);
    padding: 18px 14px;
  }

  .overlay-card h2 {
    font-size: 22px;
  }

  .overlay-desc {
    font-size: 13px;
  }
}

/* 更小屏手机 */
@media (max-width: 390px) {
  .canvas-wrapper {
    width: min(76vw, 235px);
  }

  .game-title {
    font-size: 24px;
  }

  .button-group {
    grid-template-columns: 1fr;
  }

  .ctrl-row {
    gap: 8px;
  }

  .primary-btn,
  .secondary-btn,
  .ctrl-btn {
    font-size: 13px;
    padding: 9px 10px;
  }
}
:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #334155;
  --secondary-hover: #475569;
  --danger: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.15), transparent 30%),
    linear-gradient(180deg, #0b1020, #111827 45%, #0f172a);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 14px 28px;
}

.top-bar {
  text-align: center;
  margin-bottom: 18px;
}

.game-title {
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: 1px;
}

.game-subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 13px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 18px;
  align-items: start;
}

.board-section {
  display: flex;
  justify-content: center;
}

.canvas-wrapper {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 1 / 2;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, #0b1220, #111827);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(180deg, #0f172a, #0b1220);
  background-size: 10% 5%;
}

.panel-section {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 1fr));
  gap: 14px;
}

.card {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.card h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.info-list {
  display: grid;
  gap: 10px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
  border-radius: 10px;
}

.info-item span {
  color: var(--muted);
  font-size: 14px;
}

.info-item strong {
  font-size: 18px;
  color: #fff;
}

.preview-box {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 120px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.08);
}

#nextCanvas {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.primary-btn,
.secondary-btn,
.ctrl-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.secondary-btn {
  background: var(--secondary);
  color: #fff;
  font-weight: 700;
}

.secondary-btn:hover {
  background: var(--secondary-hover);
}

.ctrl-btn {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-weight: 700;
  min-height: 42px;
}

.ctrl-btn:hover {
  background: rgba(255,255,255,0.14);
}

.primary-btn:active,
.secondary-btn:active,
.ctrl-btn:active {
  transform: scale(0.96);
}

.difficulty-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.difficulty-wrap label {
  color: var(--muted);
  font-size: 14px;
}

.difficulty-wrap select {
  background: rgba(255,255,255,0.06);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.touch-controls {
  display: grid;
  gap: 10px;
}

.ctrl-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tips {
  list-style: none;
  display: grid;
  gap: 8px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
  z-index: 10;
}

.overlay.show {
  display: grid;
}

.overlay-card {
  width: min(88%, 300px);
  padding: 22px 18px;
  border-radius: 18px;
  text-align: center;
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  animation: popIn 0.35s ease;
}

.overlay-card.small {
  width: min(82%, 260px);
}

.overlay-card h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

.overlay-desc {
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 12px;
  font-size: 14px;
}

.game-over-card {
  animation: gameOverBounce 0.55s ease;
}

.game-over-title {
  color: #fff;
  text-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.line-flash {
  animation: lineFlash 0.22s ease;
}

@keyframes lineFlash {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.8);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes popIn {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes gameOverBounce {
  0% {
    transform: scale(0.75);
    opacity: 0;
  }
  60% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

/* 平板 */
@media (max-width: 960px) {
  .game-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .panel-section {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .canvas-wrapper {
    width: min(62vw, 300px);
  }
}

/* 手机 */
@media (max-width: 640px) {
  .app {
    padding: 12px 10px 20px;
  }

  .top-bar {
    margin-bottom: 14px;
  }

  .game-title {
    font-size: 26px;
  }

  .game-subtitle {
    font-size: 12px;
  }

  .panel-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .canvas-wrapper {
    width: min(72vw, 260px);
    border-radius: 14px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .card h3 {
    font-size: 15px;
  }

  .info-item {
    padding: 9px 10px;
  }

  .info-item strong {
    font-size: 17px;
  }

  #nextCanvas {
    width: 84px;
    height: 84px;
  }

  .button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .primary-btn,
  .secondary-btn,
  .ctrl-btn {
    padding: 10px 12px;
    font-size: 14px;
  }

  .ctrl-btn {
    min-height: 44px;
  }

  .overlay-card {
    width: min(90%, 280px);
    padding: 18px 14px;
  }

  .overlay-card h2 {
    font-size: 22px;
  }

  .overlay-desc {
    font-size: 13px;
  }
}

/* 更小屏手机 */
@media (max-width: 390px) {
  .canvas-wrapper {
    width: min(76vw, 235px);
  }

  .game-title {
    font-size: 24px;
  }

  .button-group {
    grid-template-columns: 1fr;
  }

  .ctrl-row {
    gap: 8px;
  }

  .primary-btn,
  .secondary-btn,
  .ctrl-btn {
    font-size: 13px;
    padding: 9px 10px;
  }
}
/* =========================
   手机端：把现有操作区移到画布右边
   不新增按钮，只调整布局
   ========================= */
@media (max-width: 640px) {
  .game-layout {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 118px;
    gap: 10px;
    align-items: start;
  }

  /* 让 aside 不再自己成一列，而是里面的卡片直接参与外层排版 */
  .panel-section {
    display: contents;
  }

  /* 游戏画布放左边，并纵向占两行 */
  .board-section {
    grid-column: 1;
    grid-row: 1 / span 2;
    justify-content: center;
    align-self: start;
  }

  .canvas-wrapper {
    width: min(60vw, 240px);
    border-radius: 14px;
  }

  /* 第3张卡片：游戏控制 -> 放到右上 */
  .panel-section .card:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
    padding: 10px;
    border-radius: 14px;
  }

  /* 第4张卡片：方向操作 -> 放到右下 */
  .panel-section .card:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
    padding: 10px;
    border-radius: 14px;
  }

  /* 第1张卡片：游戏信息 -> 放到底部整行 */
  .panel-section .card:nth-child(1) {
    grid-column: 1 / span 2;
    grid-row: 3;
  }

  /* 第2张卡片：下一个方块 -> 放到底部整行 */
  .panel-section .card:nth-child(2) {
    grid-column: 1 / span 2;
    grid-row: 4;
  }

  /* 第5张卡片：操作说明 -> 放到底部整行 */
  .panel-section .card:nth-child(5) {
    grid-column: 1 / span 2;
    grid-row: 5;
  }

  /* 右侧两个操作卡片更紧凑 */
  .panel-section .card:nth-child(3) h3,
  .panel-section .card:nth-child(4) h3 {
    font-size: 14px;
    margin-bottom: 8px;
    text-align: center;
  }

  .panel-section .card:nth-child(3) .button-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .panel-section .card:nth-child(3) .difficulty-wrap {
    gap: 6px;
  }

  .panel-section .card:nth-child(3) .difficulty-wrap label {
    font-size: 12px;
  }

  .panel-section .card:nth-child(3) .difficulty-wrap select {
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 10px;
  }

  .panel-section .card:nth-child(4) .touch-controls {
    gap: 8px;
  }

  .panel-section .card:nth-child(4) .ctrl-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel-section .card:nth-child(4) .ctrl-btn {
    min-height: 42px;
    padding: 10px 8px;
    font-size: 13px;
    border-radius: 10px;
  }

  .panel-section .card:nth-child(3) .primary-btn,
  .panel-section .card:nth-child(3) .secondary-btn {
    width: 100%;
    min-height: 40px;
    padding: 10px 8px;
    font-size: 13px;
    border-radius: 10px;
  }

  /* 底部信息区恢复单列，避免太挤 */
  .panel-section .card:nth-child(1),
  .panel-section .card:nth-child(2),
  .panel-section .card:nth-child(5) {
    padding: 14px;
  }

  .info-item {
    padding: 9px 10px;
  }

  .info-item span {
    font-size: 13px;
  }

  .info-item strong {
    font-size: 16px;
  }

  #nextCanvas {
    width: 82px;
    height: 82px;
  }

  .tips {
    font-size: 13px;
    gap: 6px;
  }
}

/* 更小屏手机再压缩一点 */
@media (max-width: 390px) {
  .game-layout {
    grid-template-columns: minmax(160px, 1fr) 104px;
    gap: 8px;
  }

  .canvas-wrapper {
    width: min(58vw, 220px);
  }

  .panel-section .card:nth-child(3),
  .panel-section .card:nth-child(4) {
    padding: 8px;
  }

  .panel-section .card:nth-child(3) h3,
  .panel-section .card:nth-child(4) h3 {
    font-size: 13px;
    margin-bottom: 6px;
  }

  .panel-section .card:nth-child(3) .primary-btn,
  .panel-section .card:nth-child(3) .secondary-btn,
  .panel-section .card:nth-child(4) .ctrl-btn {
    min-height: 38px;
    font-size: 12px;
    padding: 8px 6px;
  }

  .panel-section .card:nth-child(3) .difficulty-wrap select {
    font-size: 12px;
    padding: 7px 8px;
  }
}