:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #212529;
  --muted: #6c757d;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --border: #dee2e6;
  --radius: 0.75rem;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
}

header a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
}

nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

nav a {
  font-size: 0.95rem;
  font-weight: 500;
}

main {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.title-row h1 {
  margin: 0;
  font-size: 1.75rem;
}

#mode-switch .button {
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

#mode-switch .button:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--muted);
}

#mode-selection {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  text-align: center;
}

#mode-selection p {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

h1, h2, h3 {
  margin-top: 0;
}

p {
  color: var(--muted);
}

label {
  display: block;
  margin: 1rem 0 0.35rem;
  font-weight: 500;
}

input[type='text'],
input[type='file'],
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  background: var(--surface);
}

input[type='file'] {
  padding: 0.45rem;
}

input[type='range'] {
  width: 100%;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: var(--primary-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.secondary {
  background: #e9ecef;
  color: var(--text);
}

button.danger {
  background: var(--danger);
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: #eef2ff;
}

.preview {
  margin-top: 1rem;
  text-align: center;
}

.preview img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
}

.error {
  color: var(--danger);
  margin-top: 1rem;
}

.success {
  color: #15803d;
  margin-top: 1rem;
}

.game-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.game-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.game-list a {
  color: var(--primary);
  text-decoration: none;
}

.game-list .button {
  color: white;
}

.game-list .button.secondary {
  color: var(--text);
}

#game-board {
  margin: 1.5rem auto;
  display: flex;
  justify-content: center;
}

.game-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
  text-align: left;
}

.game-type-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.1s;
}

.game-type-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.game-type-card h2 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.1rem;
}

.game-type-card > p {
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.game-type-icon {
  font-size: 2rem;
  line-height: 1;
}

.puzzle-piece {
  cursor: grab;
  touch-action: none;
}

.puzzle-piece:active {
  cursor: grabbing;
}

.puzzle-piece::after {
  content: '';
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
  transition: background 0.1s;
}

.puzzle-piece.selected {
  box-shadow: 0 0 0 3px var(--primary);
  z-index: 15;
}

.puzzle-piece.selected::after {
  background: rgba(0, 0, 0, 0.35);
}

.puzzle-piece.selection-preview {
  box-shadow: 0 0 0 3px #3b82f6;
  z-index: 16;
}

.puzzle-piece.selection-preview::after {
  background: rgba(0, 0, 0, 0.15);
}

.selection-box {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(79, 70, 229, 0.15);
  pointer-events: none;
  z-index: 30;
}

.puzzle-piece.animating {
  transition: top 0.2s ease-out, left 0.2s ease-out;
}

.target-outlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}

.target-outline {
  position: absolute;
  border: 2px dashed rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}

.puzzle-flash {
  position: absolute;
  inset: 0;
  background: rgba(34, 197, 94, 0.45);
  pointer-events: none;
  z-index: 40;
  animation: puzzle-flash 0.7s ease-out forwards;
}

@keyframes puzzle-flash {
  0% {
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.wordle-clue {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 1rem;
}

.wordle-clue p {
  margin: 0 0 0.5rem;
  width: 100%;
}

.wordle-clue img {
  display: block;
  max-width: 100%;
  max-height: 120px;
  border-radius: var(--radius);
  margin: 0 auto;
  box-shadow: var(--shadow);
}

.wordle-grid {
  display: grid;
  row-gap: var(--tile-gap, 0.4rem);
  justify-content: center;
  margin-bottom: 1.25rem;
}

.wordle-row {
  display: grid;
  grid-auto-flow: column;
  gap: var(--tile-gap, 0.4rem);
}

.wordle-tile {
  width: var(--tile-size, 3.25rem);
  height: var(--tile-size, 3.25rem);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 0.35rem;
  font-size: calc(var(--tile-size, 3.25rem) * 0.5);
  font-weight: 700;
  text-transform: uppercase;
  background: var(--surface);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.1s;
}

.wordle-tile.filled {
  border-color: var(--muted);
}

.wordle-tile.correct {
  background: #22c55e;
  border-color: #22c55e;
  color: white;
}

.wordle-tile.present {
  background: #eab308;
  border-color: #eab308;
  color: white;
}

.wordle-tile.absent {
  background: #6b7280;
  border-color: #6b7280;
  color: white;
}

.wordle-hidden-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.wordle-message {
  text-align: center;
  min-height: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

@keyframes wordle-shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.875rem;
}

#cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.cookie-banner-content {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

#cookie-banner p {
  margin: 0;
  font-size: 0.9rem;
}

.cookie-banner-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Multiplayer mode */
.player-badge {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.35rem 0.75rem;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

#multi-hud {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #f1f5f9;
  border-radius: var(--radius);
}

#multi-hud h3 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#score-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

#score-list li {
  padding: 0.2rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
}

#score-list li.me {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

#multi-players div {
  padding: 0.35rem 0;
}

.puzzle-piece.scored {
  box-shadow: inset 0 0 0 3px #22c55e;
}

.puzzle-piece.locked {
  cursor: not-allowed;
  opacity: 0.85;
}
