/* telegram theme vars with browser-mode fallbacks */
:root {
  --tg-bg: #ffffff;
  --tg-text: #222222;
  --tg-hint: #999999;
  --tg-button: #50a8eb;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f5f5f5;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.board {
  position: relative;
  /* ivory mat under tiles — same color as tile body so the cross-shaped
     gaps at 4-way junctions between rounded tiles blend in invisibly.
     width/height set inline by renderer based on viewport. */
  background: #f5f0eb;
}

.hud {
  display: flex;
  gap: 1.2rem;
  padding: 0.3rem 0.6rem;
  height: 32px;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.hud-stat {
  display: flex;
  gap: 0.3rem;
  align-items: baseline;
}

.hud-label {
  color: var(--tg-hint);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hud-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  height: 56px;
  align-items: center;
  justify-content: center;
}

.tool-btn {
  font: inherit;
  font-weight: 600;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1px solid var(--tg-hint);
  border-radius: 10px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  min-width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1.1;
  transition: opacity 120ms ease, transform 80ms ease;
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.tool-btn:not(:disabled):active {
  transform: scale(0.96);
}

.tool-btn-label {
  font-size: 0.85rem;
}

.tool-btn-count {
  font-size: 0.7rem;
  color: var(--tg-hint);
}

.tile {
  position: absolute;
  /* ivory fill matches the svg body (#f5f0eb) and the board mat so 4-way
     junction gaps under rounded corners stay invisible.
     border-radius matches the svg's native rounded body (r=30 in a 227x303
     viewbox = 13% horizontal / 10% vertical of the tile), so the tile
     outline coincides with the svg stroke — no double-rounded look.
     flex is load-bearing: .tile-face is a <span>, only respects 100%/100%
     because flex blockifies it.

     2.5d via one solid same-size shadow at (SIDE, SIDE) — draws a dark
     tan rounded rect peeking from the bottom-right. the visible L-shape
     IS the tile's physical side wall. the tight drop under it (small
     blur, close offset, strong alpha) reads as contact with the surface;
     without it the block "floats". no stepped colours — one colour reads
     as a single slab, not layered cards.
     the first `0 0 0 0 transparent` is a placeholder so `.is-selected`
     can slot its outline in without the box-shadow transition jumping. */
  background: #f5f0eb;
  border-radius: 13% / 10%;
  box-shadow:
    0 0 0 0 transparent,
    6px 6px 0 0 #8a7348,
    7px 8px 5px rgba(0, 0, 0, 0.55);
  display: flex;
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 150ms ease,
    opacity 200ms ease;
  will-change: transform, opacity;
}

.tile:active {
  transform: scale(0.97);
}

.tile-face {
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-position: center;
  /* Y_ASPECT matches the svg intrinsic aspect, so 100% 100% fills the tile
     without distortion — the svg's own rounded body sits inside. */
  background-size: 100% 100%;
  pointer-events: none;
}

.tile.is-selected {
  box-shadow:
    0 0 0 3px var(--tg-button),
    6px 6px 0 0 #8a7348,
    7px 8px 5px rgba(0, 0, 0, 0.55);
}

.tile.is-hint {
  animation: hint-pulse 1s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 0 rgba(80, 168, 235, 0.7),
      6px 6px 0 0 #8a7348,
      7px 8px 5px rgba(0, 0, 0, 0.55);
  }
  50% {
    box-shadow:
      0 0 0 8px rgba(80, 168, 235, 0.25),
      6px 6px 0 0 #8a7348,
      7px 8px 5px rgba(0, 0, 0, 0.55);
  }
}

.tile.is-mismatch {
  animation: mismatch-shake 260ms ease;
}

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

.tile.is-removing {
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}

/* modals */

#modal-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10000;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: auto;
  animation: modal-fade-in 140ms ease-out;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--tg-bg);
  color: var(--tg-text);
  border-radius: 14px;
  padding: 1.4rem 1.25rem 1.1rem;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  animation: modal-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes modal-in {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}

.modal-body {
  margin: 0 0 1rem;
  text-align: center;
  color: var(--tg-hint);
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-btn {
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: transform 80ms ease, opacity 120ms ease, background 120ms ease;
}

.modal-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.modal-btn:not(:disabled):active {
  transform: scale(0.98);
}

.modal-btn.is-primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
}

.modal-btn.is-secondary {
  background: transparent;
  color: var(--tg-button);
  border: 1px solid var(--tg-button);
}
