/* Tile games: tiles, tray and the Connect line. Colors come from the theme file. */

@font-face {
  font-family: 'TileCJK';
  src: url('../fonts/tile-cjk.woff2') format('woff2');
  font-weight: 900;
  font-display: block;
}

.tiles {
  --tw: 56px;
  --th: 72px;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--tw);
  height: var(--th);
  transition: transform 0.34s var(--ease) var(--d, 0ms), opacity 0.3s var(--d, 0ms), scale 0.3s, rotate 0.3s, translate 0.18s;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tf {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--tw) * 0.16);
  background: var(--tile-face);
  border: max(1.5px, calc(var(--tw) * 0.035)) solid var(--tile-ink);
  box-shadow:
    calc(var(--tw) * 0.04) calc(var(--tw) * 0.055) 0 0 var(--tile-edge-1),
    calc(var(--tw) * 0.075) calc(var(--tw) * 0.11) 0 0 var(--tile-edge-2),
    calc(var(--tw) * 0.075) calc(var(--tw) * 0.11) 0 max(1.5px, calc(var(--tw) * 0.035)) var(--tile-ink),
    calc(var(--tw) * 0.12) calc(var(--tw) * 0.2) calc(var(--tw) * 0.22) rgba(74, 44, 26, 0.3);
  transition: background 0.2s, box-shadow 0.2s;
}

.tf svg {
  position: absolute;
  left: 8%;
  top: 10%;
  width: 84%;
  height: 80%;
}

.tile.blocked {
  cursor: default;
}

.tile.blocked .tf {
  background: var(--tile-blocked);
}

.tile.blocked svg {
  opacity: 0.68;
}

.tiles.flat .tile.blocked .tf {
  background: var(--tile-face);
}

.tiles.flat .tile.blocked svg {
  opacity: 1;
}

.tile:not(.blocked):hover .tf {
  background: #fffaf0;
}

.tile.sel {
  translate: 0 calc(var(--th) * -0.08);
}

.tile.sel .tf {
  background: #ffffff;
  box-shadow:
    0 0 0 calc(var(--tw) * 0.05) var(--tile-face),
    0 0 0 calc(var(--tw) * 0.1) var(--select-ring),
    calc(var(--tw) * 0.075) calc(var(--tw) * 0.16) 0 max(1.5px, calc(var(--tw) * 0.035)) var(--tile-ink),
    calc(var(--tw) * 0.16) calc(var(--tw) * 0.3) calc(var(--tw) * 0.3) rgba(74, 44, 26, 0.4);
}

.tile.hint .tf {
  animation: tile-glow 1.1s ease-in-out infinite;
}

.tile.leaving {
  opacity: 0;
  scale: 1.3;
  rotate: 10deg;
  pointer-events: none;
  transition: opacity 0.38s ease-in, scale 0.38s var(--ease), rotate 0.38s;
}

.tile.nope {
  animation: shake 0.4s ease-in-out;
}

.no-anim .tile {
  transition: none !important;
}

@keyframes tile-glow {
  0%,
  100% {
    box-shadow: 0 0 0 calc(var(--tw) * 0.05) var(--hint-ring), 0 0 0 calc(var(--tw) * 0.1) var(--glow);
  }
  50% {
    box-shadow: 0 0 0 calc(var(--tw) * 0.05) var(--hint-ring), 0 0 0 calc(var(--tw) * 0.13) var(--accent), 0 0 calc(var(--tw) * 0.5) calc(var(--tw) * 0.12) rgba(241, 196, 15, 0.8);
  }
}

/* Triple Match tray and shelf */
.tray,
.shelf {
  position: absolute;
  border-radius: calc(var(--tw) * 0.38);
  background: var(--tray-bg);
  box-shadow: inset 0 calc(var(--tw) * 0.07) 0 rgba(0, 0, 0, 0.25), 0 0 0 max(3px, calc(var(--tw) * 0.06)) var(--accent-2);
}

.shelf {
  background: transparent;
  box-shadow: none;
  border: max(2px, calc(var(--tw) * 0.04)) dashed var(--slot-border);
}

.tray i {
  position: absolute;
  border-radius: calc(var(--tw) * 0.16);
  background: var(--tray-slot);
}

.tray-note {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 800;
  font-size: 14px;
  pointer-events: none;
}

.tray.danger {
  animation: danger 0.9s ease-in-out infinite;
}

@keyframes danger {
  50% {
    box-shadow: inset 0 calc(var(--tw) * 0.07) 0 rgba(0, 0, 0, 0.25), 0 0 0 max(4px, calc(var(--tw) * 0.09)) var(--accent-3);
  }
}

.powers {
  display: flex;
  gap: 8px;
}

.tool .n {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent-3);
  color: var(--pop-ink);
  font-size: 12px;
  font-weight: 900;
  display: inline-grid;
  place-items: center;
}

/* Connect line */
.link {
  position: absolute;
  inset: 0;
  z-index: 5000;
  pointer-events: none;
  overflow: visible;
  animation: link-fade 0.7s ease-in forwards;
}

.link path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.link .under {
  stroke: var(--tile-ink);
  stroke-width: calc(var(--tw) * 0.2);
}

.link .over {
  stroke: var(--path, #c0392b);
  stroke-width: calc(var(--tw) * 0.11);
  stroke-dasharray: 2000;
  stroke-dashoffset: 2000;
  animation: link-draw 0.22s ease-out forwards;
}

@keyframes link-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes link-fade {
  0%,
  60% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.timebar {
  width: 160px;
  height: 14px;
  border-radius: 7px;
  background: var(--bar-raised);
  overflow: hidden;
}

.timebar i {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(90deg, #c0392b 0 18px, #e67e22 18px 36px, #f1c40f 36px 54px);
  transition: width 1s linear;
}

@media (max-width: 640px) {
  .timebar {
    width: 70px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile.leaving {
    transition-duration: 0.01s !important;
  }
  .tile.hint .tf,
  .tray.danger {
    animation: none;
  }
}

/* Tile pages have more buttons, so labels collapse to icons sooner. */
.tool {
  position: relative;
}

.tiles .pop {
  z-index: 200000;
}

.tiles .link {
  z-index: 150000;
}

@media (max-width: 1600px) {
  :is(.bar:has(#shuffle), .puzzles .bar) .tool .label {
    display: none;
  }
  :is(.bar:has(#shuffle), .puzzles .bar) .tool:not(.icon) {
    width: 44px;
    padding: 0;
    justify-content: center;
  }
  :is(.bar:has(#shuffle), .puzzles .bar) .tool .n {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
    box-shadow: 0 0 0 2px var(--bar-bg);
  }
}

@media (max-width: 480px) {
  :is(.bar:has(#shuffle), .puzzles .bar) .tools {
    gap: 5px;
  }
  :is(.bar:has(#shuffle), .puzzles .bar) .tool,
  :is(.bar:has(#shuffle), .puzzles .bar) .tool.icon,
  :is(.bar:has(#shuffle), .puzzles .bar) .tool:not(.icon) {
    width: 38px;
    height: 38px;
  }
  :is(.bar:has(#shuffle), .puzzles .bar) .logo {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  .hud {
    gap: 5px;
  }
  .hud .stat {
    padding: 0 9px;
    gap: 4px;
    font-size: 12px;
  }
  .hud .stat b {
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  /* Fit every header button on the logo's row: size them by how many there are. */
  .bar:has(#help) .tools {
    gap: 4px;
  }
  .bar:has(#help) .tools .tool {
    --n: 6;
    width: min(40px, calc((100vw - 84px - (var(--n) - 1) * 4px) / var(--n)));
    height: min(40px, calc((100vw - 84px - (var(--n) - 1) * 4px) / var(--n)));
  }
  .bar:has(#help) .tools:has(> .tool:nth-child(7)) .tool {
    --n: 7;
  }
  .bar:has(#help) .tools:has(> .tool:nth-child(8)) .tool {
    --n: 8;
  }
  .bar:has(#help) .tools .tool svg {
    width: 18px;
    height: 18px;
  }
}
