/* ── style.css — IQ Puzzler Pro Visual Foundation ── */

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
  /* Sizing */
  --cell-size: 48px;
  --cell-gap: 4px;
  --tray-cell-size: 24px;
  --tray-cell-gap: 2px;
  --tray-gap: 10px;

  /* Colors — Theme */
  --bg-body: #0f0f1a;
  --bg-board: #1a1a2e;
  --bg-cell-empty: #2d2d44;
  --bg-sidebar: #16162a;
  --bg-header: #12122a;
  --text-primary: #e0e0e0;
  --text-muted: #888;
  --text-accent: #FFD700;

  /* Feedback */
  --glow-valid: rgba(0, 255, 100, 0.4);
  --glow-invalid: rgba(255, 50, 50, 0.5);

  /* Animation */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  touch-action: manipulation; /* disable double-tap zoom globally, keep pinch-zoom & scroll */
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ────────────────────────────────────────────── */
.game-header {
  text-align: center;
  padding: 16px 20px 12px;
  width: 100%;
  max-width: 1100px;
}

.game-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.game-header h1 .emoji {
  font-size: 1.5rem;
  margin-right: 8px;
}

/* ── Game Container — 2-column layout ──────────────────── */
.game-container {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  max-width: 1100px;
  width: 100%;
  padding: 0 20px 20px;
  align-items: start;
}

/* ── Board Area ────────────────────────────────────────── */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Floating Piece Preview (shows selected piece above board) ── */
.piece-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px 6px;
  margin-top: 8px;
  background: var(--bg-sidebar);
  border-radius: 12px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.1);
  touch-action: none; /* prevent touch scroll on preview area */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.piece-preview.hidden {
  display: none;
}

.piece-preview-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.preview-action-btn {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.preview-action-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.2);
}

.piece-preview-shape {
  display: grid;
  gap: var(--cell-gap);
  cursor: pointer; /* tappable for rotate, draggable to board */
  cursor: grab;
  touch-action: none; /* allow drag gesture, prevent scroll */
  -webkit-tap-highlight-color: transparent;
  padding: 4px;
  user-select: none;
  -webkit-user-select: none;
}

.piece-preview-ball {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 50%;
  position: relative;
}

.piece-preview-ball::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 18%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.5) 0%, transparent 100%);
  pointer-events: none;
}

.piece-preview-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(11, var(--cell-size));
  grid-template-rows: repeat(5, var(--cell-size));
  gap: var(--cell-gap);
  padding: 16px;
  background: var(--bg-board);
  border-radius: 16px;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.5),
    0 4px 20px rgba(0, 0, 0, 0.3);
  touch-action: none; /* prevent page scroll when touching the board */
}

/* ── Board Cell ────────────────────────────────────────── */
.board-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 50%;
  background: var(--bg-cell-empty);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  position: relative;
}

/* Occupied cell — base (background gradient set by JS) */
.board-cell.occupied {
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.3),
    inset 0 -2px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

/* Glossy highlight dot on occupied cells */
.board-cell.occupied::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 18%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.5) 0%, transparent 100%);
  pointer-events: none;
}

/* ── Board Preview States ──────────────────────────────── */
.board-cell.preview-valid {
  box-shadow:
    0 0 12px var(--glow-valid),
    inset 0 0 8px var(--glow-valid);
  background: rgba(0, 255, 100, 0.15) !important;
}

.board-cell.preview-invalid {
  box-shadow:
    0 0 8px var(--glow-invalid),
    inset 0 0 6px var(--glow-invalid);
  background: rgba(255, 50, 50, 0.15) !important;
}

/* Flash animation for invalid placement attempt */
@keyframes flash-invalid {
  0%, 100% { box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4); }
  50% { box-shadow: 0 0 16px var(--glow-invalid), inset 0 0 8px var(--glow-invalid); }
}

.board-cell.flash {
  animation: flash-invalid 300ms ease;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Piece Tray ────────────────────────────────────────── */
.piece-tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--tray-gap);
  padding: 12px;
  background: var(--bg-sidebar);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.tray-piece {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    opacity var(--transition-normal);
  touch-action: none; /* prevent scroll during drag */
}

.tray-piece:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.08);
}

.tray-piece.selected {
  box-shadow: 0 0 0 3px #fff, 0 0 20px rgba(255, 255, 255, 0.3);
  transform: scale(1.08);
  background: rgba(255, 255, 255, 0.1);
}

.tray-piece.placed {
  opacity: 0.2;
  pointer-events: none;
  transform: scale(0.9);
}

/* Tray piece shape grid */
.tray-shape {
  display: grid;
  gap: var(--tray-cell-gap);
}

.tray-ball {
  width: var(--tray-cell-size);
  height: var(--tray-cell-size);
  border-radius: 50%;
  position: relative;
}

/* Mini glossy highlight on tray balls */
.tray-ball::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 18%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, transparent 100%);
  pointer-events: none;
}

.tray-empty {
  width: var(--tray-cell-size);
  height: var(--tray-cell-size);
}

.tray-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* ── Controls ──────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  background: var(--bg-sidebar);
  border-radius: 12px;
}

.controls button {
  flex: 1;
  min-width: 80px;
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast);
}

.controls button:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.controls button:active {
  transform: translateY(0);
  background: rgba(255, 255, 255, 0.08);
}

.controls button .shortcut {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

/* ── Ghost Piece (follows cursor during drag/select) ──── */
.ghost-piece {
  position: fixed;
  left: 0;
  top: 0;
  display: grid;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.65;
  will-change: transform;
  transition: opacity var(--transition-fast);
}

.ghost-ball {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 50%;
  position: relative;
}

.ghost-ball::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 18%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, transparent 100%);
  pointer-events: none;
}

/* ── Status Bar ────────────────────────────────────────── */
.status-bar {
  width: 100%;
  max-width: 1100px;
  padding: 10px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  min-height: 40px;
}

.status-bar.success {
  color: #4ADE80;
}

.status-bar.error {
  color: #F87171;
}

/* ── Win Overlay ───────────────────────────────────────── */
.win-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  z-index: 2000;
  opacity: 0;
  animation: fade-in 500ms ease forwards;
}

@keyframes fade-in {
  to { opacity: 1; }
}

.win-message {
  font-size: 3rem;
  font-weight: 800;
  color: var(--text-accent);
  text-shadow: 0 0 40px rgba(255, 215, 0, 0.5);
  margin-bottom: 16px;
}

.win-sub {
  font-size: 1.2rem;
  color: var(--text-primary);
  margin-bottom: 24px;
}

.win-overlay button {
  padding: 12px 32px;
  border: 2px solid var(--text-accent);
  border-radius: 8px;
  background: transparent;
  color: var(--text-accent);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.win-overlay button:hover {
  background: rgba(255, 215, 0, 0.15);
}

/* Win board pulse */
@keyframes win-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

.board-grid.win .board-cell.occupied {
  animation: win-pulse 1.2s ease infinite;
}

/* ── Mode Switcher ────────────────────────────────────── */
.mode-switcher {
  display: flex;
  gap: 0;
  background: var(--bg-sidebar);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.mode-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
}

.mode-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.mode-btn.active {
  background: rgba(255, 215, 0, 0.15);
  color: var(--text-accent);
  box-shadow: 0 2px 8px rgba(255, 215, 0, 0.1);
}

/* ── Challenge Panel ──────────────────────────────────── */
.challenge-panel {
  background: var(--bg-sidebar);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

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

.challenge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.challenge-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.challenge-stars {
  font-size: 1.1rem;
  color: var(--text-accent);
  letter-spacing: 2px;
}

.challenge-nav-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast);
}

.challenge-nav-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}

.challenge-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.challenge-progress {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.challenge-progress .completed-badge {
  color: #4ADE80;
  font-weight: 600;
}

.challenge-progress .best-time {
  color: var(--text-accent);
}

/* Challenge loading spinner */
.challenge-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Challenge Actions (Hint button row) ────────────────── */
.challenge-actions {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.hint-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 8px;
  background: rgba(255, 215, 0, 0.08);
  color: var(--text-accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hint-btn:hover {
  background: rgba(255, 215, 0, 0.18);
  transform: translateY(-1px);
}

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

.hint-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.hint-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Hint Modal ─────────────────────────────────────────── */
.hint-modal {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  animation: fade-in 200ms ease forwards;
}

.hint-modal.hidden {
  display: none;
}

.hint-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.hint-modal-content {
  position: relative;
  background: #1e1e36;
  border: 1px solid rgba(255, 215, 0, 0.25);
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 215, 0, 0.08);
}

.hint-modal-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.hint-modal-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.hint-modal-body {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

.hint-modal-body p {
  margin-bottom: 8px;
}

.hint-modal-penalty {
  color: #F87171;
  font-size: 1rem;
}

.hint-modal-remaining strong {
  color: var(--text-accent);
}

.hint-modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.hint-modal-btn {
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hint-modal-cancel {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.hint-modal-cancel:hover {
  background: rgba(255, 255, 255, 0.12);
}

.hint-modal-confirm {
  border: 1px solid rgba(255, 215, 0, 0.4);
  background: rgba(255, 215, 0, 0.15);
  color: var(--text-accent);
}

.hint-modal-confirm:hover {
  background: rgba(255, 215, 0, 0.25);
}

.hint-modal-btn:active {
  transform: scale(0.95);
}

/* ── Hint Placed Piece Animation ───────────────────────── */
@keyframes hint-glow {
  0% { filter: brightness(1.8) saturate(0.5); }
  100% { filter: saturate(0.5) brightness(0.8); }
}

.board-cell.hint-placed {
  animation: hint-glow 800ms ease forwards;
}

.challenge-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--text-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Timer Display ────────────────────────────────────── */
.timer-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-sidebar);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.timer-icon {
  font-size: 1.1rem;
  opacity: 0.7;
}

.timer-value {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.05em;
  min-width: 5ch;
  text-align: center;
}

.timer-value.running {
  color: #4ADE80;
}

.timer-value.stopped {
  color: var(--text-accent);
}

/* ── Locked Pieces (Challenge mode) ───────────────────── */
.board-cell.locked {
  filter: saturate(0.5) brightness(0.8);
  cursor: not-allowed;
}

/* Lock icon overlay on locked cells */
.board-cell.locked::before {
  content: '';
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  z-index: 1;
  /* Lock icon via SVG data URI */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='rgba(255,255,255,0.6)'%3E%3Cpath d='M12 17a2 2 0 002-2 2 2 0 00-2-2 2 2 0 00-2 2 2 2 0 002 2m6-9a2 2 0 012 2v10a2 2 0 01-2 2H6a2 2 0 01-2-2V10a2 2 0 012-2h1V6a5 5 0 0110 0v2h1m-6-2v2h4V6a2 2 0 00-2-2 2 2 0 00-2 2z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.tray-piece.locked {
  filter: saturate(0.4) brightness(0.7);
  opacity: 0.5;
  pointer-events: none;
  transform: scale(0.9);
}

.tray-piece.locked .tray-label::after {
  content: ' \1F512';
  font-size: 0.6rem;
}

/* ── Win Overlay — Challenge extras ───────────────────── */
.win-time {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-accent);
  margin-bottom: 8px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.win-challenge-info {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.win-buttons {
  display: flex;
  gap: 12px;
}

.win-overlay button.secondary {
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--text-primary);
}

.win-overlay button.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ── Floating Piece Action Bar (mobile-friendly) ──── */
.piece-actions {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(20, 20, 40, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 1500;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  touch-action: none; /* prevent touch scroll on action bar */
}

.piece-actions.hidden {
  display: none;
}

.action-btn {
  padding: 10px 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 120ms ease, transform 120ms ease;
  touch-action: manipulation; /* prevent double-tap zoom */
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.2);
}

.action-btn.action-cancel {
  color: #F87171;
  border-color: rgba(248, 113, 113, 0.3);
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
  .game-container {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
    padding: 0 12px 12px;
  }

  .piece-tray {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }
}

@media (max-width: 600px) {
  :root {
    --cell-size: 30px;
    --cell-gap: 2px;
    --tray-cell-size: 16px;
    --tray-cell-gap: 1px;
    --tray-gap: 6px;
  }

  .game-header {
    padding: 8px 12px 4px;
  }

  .game-header h1 {
    font-size: 1.1rem;
  }

  .game-header h1 .emoji {
    font-size: 1rem;
    margin-right: 4px;
  }

  .game-container {
    gap: 8px;
    padding: 0 6px 70px; /* bottom padding for floating action bar */
  }

  .board-grid {
    padding: 8px;
    border-radius: 10px;
  }

  /* Sidebar: compact everything */
  .sidebar {
    gap: 8px;
    width: 100%;
  }

  .mode-switcher {
    padding: 3px;
  }

  .mode-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .challenge-panel {
    padding: 8px 12px;
  }

  .hint-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .hint-modal-content {
    padding: 20px 22px;
  }

  .timer-display {
    padding: 4px 12px;
  }

  .timer-value {
    font-size: 1.1rem;
  }

  .piece-tray {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 4px;
    padding: 6px;
  }

  .tray-piece {
    padding: 4px 2px;
    gap: 2px;
  }

  .tray-label {
    font-size: 0.6rem;
  }

  .controls {
    padding: 6px;
    gap: 6px;
  }

  .controls button {
    min-width: 50px;
    padding: 6px 8px;
    font-size: 0.75rem;
  }

  /* Hide keyboard shortcut hints on touch devices */
  .controls button .shortcut {
    display: none;
  }

  .status-bar {
    font-size: 0.75rem;
    padding: 4px 8px;
    min-height: 28px;
  }

  .piece-preview {
    padding: 8px 16px 4px;
    margin-top: 6px;
  }

  .piece-actions {
    bottom: 12px;
    padding: 8px 12px;
    gap: 10px;
  }

  .action-btn {
    width: 46px;
    height: 46px;
    font-size: 1.3rem;
  }
}

@media (max-width: 380px) {
  :root {
    --cell-size: 26px;
    --cell-gap: 2px;
    --tray-cell-size: 14px;
  }

  .game-header {
    padding: 6px 8px 2px;
  }

  .game-header h1 {
    font-size: 1rem;
  }

  .board-grid {
    padding: 6px;
    border-radius: 8px;
  }

  .piece-tray {
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  }
}
