/* LO Logic — mobile-first deduction puzzle */
:root {
  --lo-blue: #4c6fff;
  --lo-blue-dark: #334ddc;
  --lo-yellow: #ffdd55;
  --lo-yellow-light: #fff3b0;
  --lo-ink: #1a1a2e;
  --lo-bg: linear-gradient(165deg, #8ee4ff 0%, #6ba8ff 45%, #5b7cff 100%);
  --lo-surface: #ffffff;
  --lo-shadow: 0 8px 0 rgba(26, 26, 46, 0.12), 0 16px 32px rgba(26, 26, 46, 0.15);
  --lo-shadow-tile: 0 5px 0 rgba(26, 26, 46, 0.18), 0 10px 20px rgba(26, 26, 46, 0.12);
  --lo-radius: 16px;
  --lo-radius-sm: 12px;
  --slot-size: min(22vw, 96px);
  --font: "Fredoka", system-ui, sans-serif;
  --red: #ff4d5a;
  --blue: #3d7bff;
  --yellow: #ffc72c;
}

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

html,
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--lo-ink);
  background: var(--lo-bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.is-hidden {
  display: none !important;
}

.lo-app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.lo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lo-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lo-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--lo-yellow);
  border: 3px solid var(--lo-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: var(--lo-ink);
}

.lo-title-block h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.lo-title-block p {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.75;
  font-weight: 600;
}

.lo-header-actions {
  display: flex;
  gap: 6px;
}

.lo-icon-btn {
  width: 40px;
  height: 40px;
  border: 3px solid var(--lo-ink);
  border-radius: 12px;
  background: var(--lo-surface);
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

.lo-icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.lo-icon-btn--on {
  background: var(--lo-yellow);
}

.lo-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lo-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.lo-diff {
  text-transform: capitalize;
  padding: 4px 10px;
  border-radius: 999px;
  border: 2px solid var(--lo-ink);
  background: var(--lo-surface);
}

.lo-diff--easy { background: #c8f7d4; }
.lo-diff--medium { background: var(--lo-yellow-light); }
.lo-diff--hard { background: #ffd0d0; }

/* Fragment clues */
.lo-fragments-wrap {
  background: var(--lo-surface);
  border: 3px solid var(--lo-ink);
  border-radius: var(--lo-radius);
  box-shadow: var(--lo-shadow);
  padding: 10px 12px;
}

.lo-fragments-title {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lo-fragments-hint {
  margin: 0 0 10px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0.72;
}

.lo-fragments {
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.lo-fragments-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.lo-fragment-card {
  position: relative;
  padding: 8px 10px 8px 28px;
  background: linear-gradient(160deg, #fafbff 0%, #eef2ff 100%);
  border: 3px solid var(--lo-ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(26, 26, 46, 0.1), 0 8px 16px rgba(26, 26, 46, 0.08);
}

.lo-fragment-num {
  position: absolute;
  top: 6px;
  left: 8px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--lo-yellow);
  border: 2px solid var(--lo-ink);
  font-size: 0.65rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.lo-fragment-grid {
  display: grid;
  grid-template-rows: repeat(var(--frag-rows), 36px);
  grid-template-columns: repeat(var(--frag-cols), 36px);
  gap: 4px;
}

.lo-frag-tile {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--lo-surface);
  border: 3px solid var(--lo-ink);
  box-shadow: 0 3px 0 rgba(26, 26, 46, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lo-frag-tile .lo-shape--circle {
  width: 44%;
  height: 44%;
}

.lo-frag-tile .lo-shape--square {
  width: 76%;
  height: 76%;
  border-radius: 3px;
}

.lo-frag-tile .lo-shape--triangle {
  width: 68%;
  height: 60%;
}

/* Color-only clue: square swatch (never a circle/triangle silhouette) */
.lo-frag-tile--color {
  position: relative;
}

.lo-frag-tile--color .lo-frag-swatch {
  width: 76%;
  height: 76%;
  border-radius: 4px;
  display: block;
  border: 3px solid var(--lo-ink);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}

.lo-frag-swatch--red { background: var(--red); }
.lo-frag-swatch--blue { background: var(--blue); }
.lo-frag-swatch--yellow { background: var(--yellow); }

.lo-frag-swatch-tag {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.45rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: rgba(26, 26, 46, 0.45);
  line-height: 1;
  pointer-events: none;
}

/* Shape-only clue: neutral silhouette */
.lo-frag-shape-only {
  background: #b8bfd4 !important;
  color: #b8bfd4;
}

.lo-frag-tile--shape .lo-shape--triangle.lo-frag-shape-only {
  background: #b8bfd4 !important;
}

.lo-frag-spacer {
  width: 36px;
  height: 36px;
  visibility: hidden;
  pointer-events: none;
}

.lo-tray--hover {
  background: rgba(255, 243, 176, 0.85);
  box-shadow: inset 0 0 0 3px var(--lo-blue);
}

/* Board */
.lo-board-wrap {
  display: flex;
  justify-content: center;
  position: relative;
}

.lo-board {
  display: grid;
  grid-template-columns: repeat(3, var(--slot-size));
  grid-template-rows: repeat(3, var(--slot-size));
  gap: 10px;
  padding: 14px;
  background: var(--lo-surface);
  border: 4px solid var(--lo-ink);
  border-radius: 20px;
  box-shadow: var(--lo-shadow);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}

.lo-slot {
  width: var(--slot-size);
  height: var(--slot-size);
  border-radius: var(--lo-radius-sm);
  background: linear-gradient(145deg, #f0f4ff 0%, #e2e8f8 100%);
  border: 3px dashed rgba(26, 26, 46, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.lo-slot--hover {
  border-color: var(--lo-blue);
  border-style: solid;
  background: #e8f0ff;
  transform: scale(1.03);
}

.lo-tile {
  width: calc(var(--slot-size) - 14px);
  height: calc(var(--slot-size) - 14px);
  border-radius: 14px;
  background: var(--lo-surface);
  border: 3px solid var(--lo-ink);
  box-shadow: var(--lo-shadow-tile);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.lo-tile:active,
.lo-tile--dragging {
  cursor: grabbing;
  transform: scale(1.08);
  z-index: 50;
  box-shadow: 0 12px 28px rgba(26, 26, 46, 0.25);
}

.lo-tile-ghost {
  position: fixed;
  transform: translate(-50%, -50%) scale(1.1);
  pointer-events: none;
  z-index: 9999;
  opacity: 0.95;
}

/* Shapes — circle small, square large, triangle via clip-path */
.lo-shape {
  display: block;
  flex-shrink: 0;
}

.lo-shape--circle {
  width: 46%;
  height: 46%;
  border-radius: 50%;
}

.lo-shape--square {
  width: 78%;
  height: 78%;
  border-radius: 4px;
}

.lo-shape--triangle {
  width: 72%;
  height: 64%;
  clip-path: polygon(50% 4%, 4% 100%, 96% 100%);
  border-radius: 0;
}

.lo-color--red { background: var(--red); color: var(--red); }
.lo-color--blue { background: var(--blue); color: var(--blue); }
.lo-color--yellow { background: var(--yellow); color: var(--yellow); }

/* Tray */
.lo-tray-wrap {
  margin-top: auto;
}

.lo-tray-label {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.lo-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid var(--lo-ink);
  border-radius: var(--lo-radius);
  min-height: 88px;
}

.lo-tray .lo-tile {
  width: 64px;
  height: 64px;
}

.lo-board--revealed {
  box-shadow: 0 0 0 4px #9ae6b0, var(--lo-shadow);
}

.lo-reveal-active .lo-tile {
  cursor: default;
  pointer-events: none;
}

.lo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.lo-btn--peek {
  flex: 1 1 100%;
  font-size: 0.82rem;
  padding: 10px 12px;
  background: #e8eeff;
}

.lo-btn--peek.is-on {
  background: #9ae6b0;
}

.lo-btn {
  flex: 1;
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 14px 12px;
  border: 3px solid var(--lo-ink);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2);
}

.lo-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.lo-btn--primary {
  background: var(--lo-yellow);
}

.lo-btn--secondary {
  background: var(--lo-surface);
}

.lo-feedback {
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  min-height: 1.2em;
  opacity: 0;
  transition: opacity 0.25s;
}

.lo-feedback--show {
  opacity: 1;
}

.lo-back {
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--lo-ink);
  text-decoration: none;
  padding: 8px;
}

.lo-back:hover {
  text-decoration: underline;
}

/* Success */
.lo-success {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  z-index: 10;
  animation: lo-pop 0.45s ease;
}

.lo-success h2 {
  margin: 0;
  font-size: 1.5rem;
}

.lo-board--success {
  animation: lo-pulse 0.6s ease;
}

.lo-board--shake {
  animation: lo-shake 0.45s ease;
}

@keyframes lo-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes lo-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); box-shadow: 0 0 0 4px var(--lo-yellow), var(--lo-shadow); }
}

@keyframes lo-pop {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Desktop */
@media (min-width: 640px) {
  .lo-app {
    max-width: 720px;
  }

  :root {
    --slot-size: 100px;
  }

  .lo-main {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 16px;
    align-items: start;
  }

  .lo-fragments {
    max-height: 360px;
  }
}
