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

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 900px;
}

h1 {
  font-size: 1.8rem;
  letter-spacing: 0.05em;
  color: #a8d8ea;
}

#mode-picker {
  display: flex;
  gap: 0.5rem;
}

.mode-btn {
  padding: 0.4rem 1rem;
  background: #2a2a4a;
  border: 1px solid #444;
  border-radius: 6px;
  color: #aaa;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.mode-btn:hover { background: #3a3a6a; color: #ccc; }

.mode-btn.selected {
  background: #1a3a5a;
  border-color: #a8d8ea;
  color: #a8d8ea;
}

#main {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
}

/* ── Grid ── */
#grid-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

#grid-container {
  position: relative;
  border: 2px solid #444;
  border-radius: 4px;
  overflow: hidden;
}

#game-canvas {
  display: block;
}

#grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  position: absolute;
  top: 0; left: 0;
  --cell-size: 56px;
  --cols: 8;
  --rows: 8;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: transparent;
  position: relative;
}


/* ── Sidebar ── */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 200px;
}

#controls {
  display: flex;
  gap: 0.5rem;
}

#controls button {
  flex: 1;
  padding: 0.5rem 0.4rem;
  background: #2a2a4a;
  border: 1px solid #555;
  border-radius: 6px;
  color: #ccc;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#controls button:hover {
  background: #3a3a6a;
  border-color: #888;
}

#controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

#piece-tray {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#piece-tray h2 {
  font-size: 1rem;
  color: #a8d8ea;
}

#hand {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#key-hint {
  font-size: 0.75rem;
  color: #666;
  text-align: center;
}

#pieces {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.piece-card {
  background: #16213e;
  border: 2px solid #333;
  border-radius: 8px;
  padding: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.piece-card:hover {
  border-color: #666;
  transform: translateX(2px);
}

.piece-card.selected {
  border-color: #a8d8ea;
  background: #1a2a4a;
}

.piece-card.used {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.piece-preview {
  --ps: 14px;
  display: grid;
  gap: 1px;
  flex-shrink: 0;
}

.piece-preview-cell {
  width: var(--ps);
  height: var(--ps);
  border-radius: 2px;
}

.piece-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: #aaa;
  min-width: 2ch;
  text-align: right;
}

/* ── Status ── */
#btn-new-puzzle {
  padding: 0.6rem 1.6rem;
  background: #1a3a5a;
  border: 1px solid #a8d8ea;
  border-radius: 6px;
  color: #a8d8ea;
  font-size: 1rem;
  cursor: pointer;
}

#btn-new-puzzle:hover { background: #1f4a70; }

#status {
  font-size: 0.85rem;
  color: #7a9ab8;
  min-height: 1.5em;
  text-align: center;
}

/* ── Piece colors ── */
.color-I { background: #00b4d8; }
.color-O { background: #f4d03f; }
.color-T { background: #9b59b6; }
.color-S { background: #2ecc71; }
.color-Z { background: #e74c3c; }
.color-L { background: #e67e22; }
.color-J { background: #1a6fd4; }
