:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #212529;
  --muted: #6c757d;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --success-hover: #15803d;
  --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;
}

.title-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.title-actions .button:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--muted);
}

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

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

#multi-players .player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

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

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

#multi-players .empty {
  font-size: 0.875rem;
  color: var(--muted);
}

#multi-status {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
}

#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;
}

/* Reusable URL display component */
link-display {
  display: block;
}

.link-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-top: 0.75rem;
  flex-wrap: nowrap;
  overflow: hidden;
}

.link-display.compact {
  padding: 0.35rem 0.5rem;
  margin-top: 0.5rem;
  gap: 0.35rem;
}

.link-display__label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

.link-display.compact .link-display__label {
  font-size: 0.875rem;
}

.link-display__url {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.95rem;
}

.link-display.compact .link-display__url {
  font-size: 0.85rem;
}

.link-display__url:hover {
  text-decoration: underline;
}

.link-display__actions {
  display: inline-flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.link-display__actions button {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 0.375rem;
}

.link-display__qr {
  width: 100%;
  display: none;
  margin-top: 0.5rem;
}

.link-display__qr img {
  display: block;
  max-width: 180px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.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: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.game-list__info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

.game-list__thumb {
  flex: 0 0 auto;
}

.game-list__thumb img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  display: block;
}

.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;
}

.board-wrap {
  position: relative;
}

.intro-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border-radius: var(--radius);
  text-align: center;
  z-index: 20;
}

.intro-message {
  font-size: 1.25rem;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.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;
}

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

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

/* ------------------------------------------------------------------------- */
/* Mini Golf                                                                 */
/* ------------------------------------------------------------------------- */

.mg-status {
  text-align: center;
  font-weight: 600;
  color: var(--muted);
  margin: 0.5rem 0;
  min-height: 1.5rem;
}

.mg-board {
  position: relative;
  margin: 0.5rem auto;
  background: #2b3a2e;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.mg-cell {
  position: absolute;
}

.mg-cell.void {
  background: transparent;
}

.mg-cell.course {
  background: #7ec850;
}

.mg-cell.wall-n { border-top: 3px solid #5b4636; }
.mg-cell.wall-s { border-bottom: 3px solid #5b4636; }
.mg-cell.wall-e { border-right: 3px solid #5b4636; }
.mg-cell.wall-w { border-left: 3px solid #5b4636; }

.mg-tee {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.mg-hole {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #1f2937;
  border: 2px solid rgba(255, 255, 255, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.mg-ball-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.mg-ball {
  position: absolute;
  left: 0;
  top: 0;
  /* No transform transition here: position updates come from rAF at display
     refresh rate, and a CSS transition would round sharp bounce corners.
     All scale effects live on .mg-ball-inner for the same reason. */
}

.mg-ball-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.mg-ball-inner.holed {
  transform-origin: center;
  transition: transform 0.28s ease-in, opacity 0.28s ease-in;
  transform: scale(0.15);
  opacity: 0;
}

.mg-ball-inner.thump {
  animation: mg-thump 0.16s ease-out;
}

@keyframes mg-thump {
  0% { transform: scale(1); }
  40% { transform: scale(0.82); }
  100% { transform: scale(1); }
}

.mg-impact {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  pointer-events: none;
  animation: mg-ripple 0.35s ease-out forwards;
}

@keyframes mg-ripple {
  from { transform: scale(0.5); opacity: 0.9; }
  to { transform: scale(2.4); opacity: 0; }
}

.mg-aim {
  position: absolute;
  left: 0;
  top: -2px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.85);
  transform-origin: left center;
  pointer-events: none;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

/* Editor */

.mg-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.mg-editor-board {
  display: grid;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: #2b3a2e;
}

.mg-editor-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  cursor: pointer;
}

.mg-editor-cell.void {
  background: #2b3a2e;
}

.mg-editor-cell.course {
  background: #7ec850;
}

.mg-editor-cell.wall-n { border-top: 2px solid #5b4636; }
.mg-editor-cell.wall-s { border-bottom: 2px solid #5b4636; }
.mg-editor-cell.wall-e { border-right: 2px solid #5b4636; }
.mg-editor-cell.wall-w { border-left: 2px solid #5b4636; }

.mg-editor-cell.is-start,
.mg-editor-cell.is-hole {
  background: #6ab53f;
}

.mg-validation {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.mg-validation.ok {
  color: var(--success);
}

.mg-validation.ko {
  color: var(--danger);
}
