:root {
  color-scheme: light;
  --bg-start: #f0f4f8;
  --bg-mid: #e8f0f8;
  --bg-end: #dfe8f0;
  --panel: #ffffff;
  --ink: #1a1a2e;
  --accent: #e85d4c;
  --accent-hover: #d74a3a;
  --success: #4a9c5d;
  --error: #d94e4e;
  --grid-gap: 8px;
  --cell-bg: #f8fafc;
  --cell-border: #e2e8f0;
  --cell-selected: #ffd9b8;
  --cell-selected-border: #e85d4c;
  --cell-hover: #f1f5f9;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, var(--bg-start) 0%, var(--bg-mid) 50%, var(--bg-end) 100%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header / HUD */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  gap: 20px;
}

.hud-left h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

#timer {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

#message {
  font-size: 14px;
  min-height: 20px;
  font-weight: 500;
  transition: color 0.3s ease, transform 0.2s ease;
}

#message.success {
  color: var(--success);
  transform: scale(1.02);
}

#message.error {
  color: var(--error);
  animation: shake 0.4s ease;
}

.hud-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

/* Difficulty Buttons */
.difficulty-label {
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 4px;
  text-align: right;
}

.difficulty-buttons {
  display: flex;
  gap: 8px;
  background: rgba(0, 0, 0, 0.03);
  padding: 6px;
  border-radius: 12px;
}

.difficulty-btn {
  background: transparent;
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: none;
  border: 2px solid transparent;
}

.difficulty-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.difficulty-btn:active {
  transform: translateY(0);
}

.difficulty-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(232, 93, 76, 0.3);
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button {
  border: none;
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

button:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Button Variants */
.btn-primary {
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(232, 93, 76, 0.3);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #6b7280;
}

.btn-secondary:hover {
  background: #4b5563;
}

.btn-icon {
  min-width: 44px;
  padding: 10px;
  font-size: 16px;
  background: var(--accent);
}

.btn-icon.muted {
  background: #9ca3af;
  filter: grayscale(0.3);
}

/* Main Game Section */
main {
  flex: 1;
}

#game-section {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: start;
}

#divider {
  width: 2px;
  background: linear-gradient(180deg, transparent, var(--cell-border) 20%, var(--cell-border) 80%, transparent);
  align-self: stretch;
}

/* Grid Section */
#grid-section {
  background: var(--panel);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.5s ease;
}

#grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 6), 1fr);
  gap: var(--grid-gap);
  width: min(85vw, 480px);
  padding: 0;
  margin: 0 auto;
}

.cell {
  background: var(--cell-bg);
  border: 2px solid var(--cell-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  min-width: 0;
}

.cell canvas {
  width: 100%;
  height: 100%;
  border-radius: 10px;
}

.cell:hover {
  background: var(--cell-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.cell.selected {
  background: var(--cell-selected);
  border-color: var(--cell-selected-border);
  box-shadow: inset 0 0 0 3px rgba(232, 93, 76, 0.2), var(--shadow-sm);
  animation: selectBounce 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cell.selected:hover {
  transform: translateY(-1px);
}

.cell.correct {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(74, 156, 93, 0.3);
}

.cell.wrong {
  border-color: var(--error);
  animation: wrongShake 0.5s ease;
}

.cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  z-index: 1;
}

/* Cube Section */
#cube-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#cube-wrap {
  width: min(85vw, 400px);
  aspect-ratio: 1.1 / 1;
  background: #f5f0e8;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: fadeInUp 0.5s ease 0.1s backwards;
}

/* #cube-wrap::before 和 ::after 已删除 */

.cube-hint {
  font-size: 13px;
  color: #666;
  text-align: center;
  max-width: 350px;
  line-height: 1.6;
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
}

#cube-canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#cube-canvas canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
}

#cube-canvas:active {
  cursor: grabbing;
}

/* 提示文字已删除 */

/* Particles */
#particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

.particle {
  position: absolute;
  pointer-events: none;
  animation: particleFall 1.5s ease-out forwards;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10010;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.2s ease;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 16, 0.35);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(92vw, 360px);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 18px 18px 16px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.2s ease;
}

.modal:not(.hidden) .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.modal-body {
  font-size: 14px;
  color: #3b3b3b;
  line-height: 1.6;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes selectBounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
  20%, 40%, 60%, 80% { transform: translateX(3px); }
}

@keyframes particleFall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Responsive Design */
@media (max-width: 1100px) {
  #game-section {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  #divider {
    display: none;
  }
}

@media (max-width: 720px) {
  * {
    box-sizing: border-box;
  }

  #app {
    padding: 12px 10px 24px;
    margin: 0 auto;
  }

  #hud {
    flex-direction: column;
    padding: 14px 12px;
  }

  .hud-left {
    text-align: center;
    width: 100%;
    margin-bottom: 8px;
  }

  .hud-left h1 {
    font-size: 18px;
  }

  .hud-right {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .difficulty-label {
    text-align: center;
    font-size: 12px;
    margin-bottom: 4px;
  }

  .difficulty-buttons {
    justify-content: space-between;
    width: 100%;
  }

  .difficulty-btn {
    flex: 1;
    padding: 8px 6px;
    font-size: 11px;
  }

  .action-buttons {
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
  }

  .action-buttons button {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    font-size: 13px;
  }

  #game-section {
    gap: 16px;
  }

  #grid-section {
    padding: 10px;
  }

  #grid {
    grid-template-columns: repeat(var(--grid-size, 6), 1fr);
    gap: var(--grid-gap, 5px);
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  #cube-section {
    align-items: center;
    width: 100%;
  }

  #cube-wrap {
    width: 100%;
    max-width: 360px;
  }

  .cube-hint {
    font-size: 11px;
    max-width: 100%;
    padding: 8px 10px;
    text-align: center;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print styles */
@media print {
  #hud,
  #toggle-sound {
    display: none;
  }

  #game-section {
    grid-template-columns: 1fr 1fr;
  }
}

/* ========== 参考面板样式 ========== */

/* 提示容器 */
.cube-hint-container {
  text-align: center;
}

/* 立方体按钮组 */
.cube-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.cube-hint {
  font-size: 13px;
  color: #666;
  text-align: center;
  max-width: 350px;
  line-height: 1.6;
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
}

/* 参考面板按钮 */
.btn-reference {
  margin-top: 12px;
  padding: 10px 20px;
  background: var(--panel);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.btn-reference:hover {
  background: var(--accent);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* 参考面板 */
.reference-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90vw;
  max-width: 700px;
  max-height: 85vh;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 500;
  display: flex;
  flex-direction: column;
  border: 1px solid #e2e8f0;
}

.reference-panel.hidden {
  display: none;
}

/* 面板头部 */
.reference-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}

.reference-header h3 {
  color: var(--accent);
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

.reference-close {
  width: 32px;
  height: 32px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.reference-close:hover {
  background: #e0e0e0;
  transform: scale(1.1);
}

/* 面板内容区 */
.reference-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 面板底部 */
.reference-footer {
  padding: 12px 20px;
  border-top: 1px solid #e2e8f0;
  text-align: center;
}

.reference-footer p {
  color: #666;
  font-size: 14px;
  margin: 0;
}

/* 移动端适配 */
@media (max-width: 720px) {
  .cube-hint-container {
    padding: 0 10px;
  }

  .cube-hint {
    font-size: 11px;
    padding: 8px 10px;
  }

  .btn-reference {
    flex: 1;
    min-width: 0;
    margin-top: 8px;
    font-size: 12px;
    padding: 8px 12px;
  }

  .cube-buttons {
    flex-direction: column;
  }

  .reference-panel {
    width: 95vw;
    max-height: 90vh;
  }

  .reference-header h3 {
    font-size: 16px;
  }

  .reference-content {
    padding: 12px;
  }
}
