:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #21262D;
  --text-primary: #F0F6FC;
  --text-secondary: #8B949E;
  --text-muted: #484F58;
  --accent: #3B82F6;
  --border: #30363D;
  --btn-bg: #21262D;
  --btn-active: #30363D;
  --overlay-bg: rgba(0, 0, 0, 0.85);
  --board-bg: #0A0E14;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F6F8FA;
    --bg-tertiary: #E9ECF0;
    --text-primary: #1B1E28;
    --text-secondary: #57606A;
    --text-muted: #8C959F;
    --accent: #3182F6;
    --border: #D0D7DE;
    --btn-bg: #E9ECF0;
    --btn-active: #D0D7DE;
    --overlay-bg: rgba(255, 255, 255, 0.9);
    --board-bg: #F0F2F5;
  }
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  z-index: 100;
  padding: 32px 24px;
}

.overlay.hidden {
  display: none;
}

.overlay-title {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: -2px;
  background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 50%, #EC4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  text-align: center;
}

.overlay-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
}

.overlay-stats {
  display: flex;
  gap: 24px;
  margin: 8px 0;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 20px;
  min-width: 90px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.best-records {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.best-row .label {
  color: var(--text-secondary);
}

.best-row .value {
  font-weight: 600;
  color: var(--accent);
}

/* ---- Buttons ---- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  width: 100%;
  max-width: 280px;
  user-select: none;
  -webkit-user-select: none;
  text-align: center;
}

.btn:active {
  transform: scale(0.97);
  background: var(--btn-active);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:active {
  background: #2563EB;
}

/* ---- Game header ---- */
#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-info {
  display: flex;
  gap: 16px;
  align-items: center;
}

.info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.info-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.info-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ---- Board area ---- */
#board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--board-bg);
  padding: 12px 8px;
  overflow: hidden;
}

/* ---- Cube cross layout ---- */
#cube-layout {
  display: grid;
  /* columns: left-arrow | face-col-1 | face-col-2 | face-col-3 | right-arrow */
  /* rows: top-arrow | face-row-1 | face-row-2 | face-row-3 | bottom-arrow */
  /* The cross layout: Up face in row 0 col 1, Left col 0, Front col 1, Right col 2, Back col 3, Down col 1 */
  position: relative;
}

.cube-cross {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transform-origin: center center;
}

.cube-row {
  display: flex;
  gap: 2px;
  align-items: center;
}

/* Face wrapper with arrows */
.face-wrapper {
  position: relative;
}

.face-label {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  pointer-events: none;
}

/* 3x3 face grid */
.face {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  background: #000;
  border-radius: 4px;
  border: 2px solid #000;
}

.cell {
  border-radius: 3px;
  aspect-ratio: 1;
  transition: background-color 0.12s ease;
}

/* Face colors */
.color-W { background: #FAFAFA; }
.color-R { background: #EF4444; }
.color-B { background: #3B82F6; }
.color-O { background: #F97316; }
.color-G { background: #22C55E; }
.color-Y { background: #EAB308; }

/* Spacer (empty face slot) */
.face-spacer {
  visibility: hidden;
  pointer-events: none;
}

/* ---- Arrow buttons ---- */
.arrow-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.arrow-gap {
  /* spacer matching face width */
  flex-shrink: 0;
}

.arrow-btn {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: background 0.12s, color 0.12s, transform 0.08s;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
}

.arrow-btn:hover {
  background: var(--btn-active);
  color: var(--text-primary);
}

.arrow-btn:active {
  transform: scale(0.9);
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Column arrows (above/below faces) */
.col-arrow-row {
  display: flex;
  gap: 2px;
  justify-content: center;
}

/* ---- Bottom controls ---- */
#controls {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 8px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.08s;
  user-select: none;
  -webkit-user-select: none;
}

.ctrl-btn .ctrl-icon {
  font-size: 18px;
  line-height: 1;
}

.ctrl-btn:active {
  transform: scale(0.95);
  background: var(--btn-active);
  color: var(--text-primary);
}

.ctrl-btn.accent {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent);
}

.ctrl-btn.accent:active {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---- Animations ---- */
@keyframes solved-pulse {
  0% { opacity: 1; }
  50% { opacity: 0.7; }
  100% { opacity: 1; }
}

.solved .cell {
  animation: solved-pulse 0.8s ease 2;
}
