:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1b1f27;
  --accent: #0f7bff;
  --line: #d6dce8;
  --tile-size: min(120px, calc((100vw - 84px) / 4));
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #ffffff 0%, var(--bg) 70%);
  min-height: 100vh;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

h1, h2 { margin-top: 0; }

.upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  margin-bottom: 10px;
}

.hint { margin: 0 0 14px; }
.error { color: #b10000; margin: 8px 0; }

button {
  border: 0;
  background: var(--accent);
  color: white;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: default; }

.game-wrap {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  justify-content: center;
  gap: 16px;
  align-items: start;
}

.board {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 5px;
  width: fit-content;
  display: grid;
  grid-template-columns: repeat(4, var(--tile-size));
  grid-template-rows: repeat(4, var(--tile-size));
  gap: 5px;
  justify-content: center;
  justify-self: center;
}

.slot {
  border: 1px dashed #b7c3d8;
  border-radius: 8px;
  background: #f4f7fd;
  padding: 6px;
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.slot.matched {
  border-style: solid;
  border-color: #4f8dff;
  background: #eaf2ff;
}

.slot.wrong { outline: 2px solid #ef7676; }

.question {
  margin: 0;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.15;
}

.slot-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.2;
  color: #607095;
}

.slot-smiley {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #1f8b42;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.slot-smiley.visible {
  opacity: 1;
  transform: scale(1);
}

.thumbs-panel {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 10px;
  justify-self: center;
  width: fit-content;
}

.pieces {
  display: grid;
  grid-template-columns: repeat(4, var(--tile-size));
  gap: 5px;
  align-content: start;
  justify-content: center;
}

.piece {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 6px;
  border: 1px solid #90a7cf;
  cursor: grab;
  position: relative;
  overflow: hidden;
  background: #d8e0ef;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.piece img {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  -webkit-user-drag: none;
  pointer-events: none;
}

.thumb-answer {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(14, 22, 38, 0.82);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 6px;
}

.piece.locked {
  cursor: default;
  border-color: #4f8dff;
}

.hidden { display: none; }

.result {
  margin-top: 16px;
  border: 2px solid #a9c9ff;
  background: #eff6ff;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.result img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
  border: 1px solid #c8dbff;
}

@media (max-width: 980px) {
  :root { --tile-size: min(96px, calc((100vw - 60px) / 4)); }
  .game-wrap {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }
  .pieces { grid-template-columns: repeat(4, var(--tile-size)); }
}

@media (max-width: 560px) {
  .page {
    padding: 14px 8px 28px;
  }

  .board {
    padding: 6px;
  }

  .thumbs-panel {
    padding: 8px;
  }

  .question {
    font-size: 13px;
  }

  .slot-hint {
    font-size: 10px;
  }

  .thumb-answer {
    left: 4px;
    bottom: 4px;
    font-size: 12px;
    padding: 4px 6px;
  }
}
