@import url('https://fonts.googleapis.com/css2?family=Radio+Canada:ital,wght@0,300..700;1,300..700&display=swap');

:root {
  --bg: #f6f1e7;
  --bg-accent: #dfe9e8;
  --ink: #1b1b1b;
  --muted: #5c5c5c;
  --accent: #e45d3b;
  --accent-2: #1f7a73;
  --card: #ffffff;
  --shadow: rgba(15, 23, 42, 0.12);
  --gap: 6px;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Radio Canada", sans-serif;
  background:
    radial-gradient(1200px 800px at 10% 0%, #fcead0 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 0%, #d9efe8 0%, transparent 55%),
    var(--bg);
}

#app {
  min-height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(246, 241, 231, 0.9);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(8px);
}

.topbar-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  justify-content: space-between;
  padding: 10px 18px;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.title {
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 700;
  letter-spacing: 0.2px;
}

.page-footer {
  text-align: center;
  padding: 12px 18px;
  color: var(--muted);
  font-size: clamp(10px, 1.2vw, 12px);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.page-footer a {
  color: var(--accent-2);
}

#status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: clamp(12px, 1.6vw, 16px);
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

#deselect {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

#deselect:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#filter-input {
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 999px;
  padding: 8px 14px;
  min-width: min(260px, 70vw);
  font-size: clamp(12px, 1.6vw, 16px);
  background: #fff;
}

.layout {
  display: block;
  padding: 16px 18px 14px;
}

#board-wrapper {
  flex: 1 1 auto;
  background: rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 30px var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 170px);
}

#board-wrapper.shuffle-flash {
  animation: shuffleFlash 0.6s ease;
}

#board {
  padding: 14px;
}

#priority-lane {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 215px));
  gap: 12px;
  margin: 14px;
  justify-content: start;
  position: relative;
  z-index: 2;
}

.cluster-item {
  width: 100%;
  animation: dropIn 0.35s ease;
  transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
  position: relative;
  z-index: 1;
}

.cluster-item:has(.expanded),
.cluster-item.expanded {
  z-index: 1000;
}

.cluster-item .bigbut {
  width: 100%;
}

.cluster-item.recent {
  animation: recentPulse 0.8s ease;
  box-shadow: 0 0 18px rgba(31, 122, 115, 0.35);
  border-radius: 12px;
}

table#the_table {
  border-collapse: separate;
  border-spacing: var(--gap);
}

td.tile-cell {
  vertical-align: top;
  position: relative;
  z-index: 1;
}

td.tile-cell:has(.expanded),
td.tile-cell.expanded {
  z-index: 1000;
}

table#the_table tr:nth-child(odd) td:nth-child(even) button {
  background-color: rgba(0, 0, 0, 0.025);
}

table#the_table tr:nth-child(even) td:nth-child(odd) button {
  background-color: rgba(0, 0, 0, 0.025);
}

button.bigbut {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-width: clamp(90px, 8vw, 140px);
  min-height: clamp(56px, 6vw, 90px);
  max-height: 90px;
  padding: 8px 10px;
  font-size: clamp(11px, 1.4vw, 16px);
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  background: var(--card);
  border-radius: 12px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  position: relative;
  overflow: visible;
  z-index: 2;
}

button.bigbut:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
}

button.bigbut.selected {
  outline: 4px solid var(--accent);
  box-shadow: 0 0 0 5px rgba(228, 93, 59, 0.25);
  animation: selectedWiggle 0.8s ease-in-out infinite;
}

#pin-zone {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 500;
  background: rgba(246, 241, 231, 0.95);
  backdrop-filter: blur(4px);
  padding: 8px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  //display: none;
}

#pin-zone:not(:empty) {
  display: flex;
  align-items: center;
  gap: 10px;
}

#pin-zone .pin-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

#pin-zone button.bigbut {
  min-width: 140px;
  max-width: 220px;
}

.pinned-original {
  opacity: 0.3;
}

button.bigbut.hidden {
  visibility: hidden;
}

button.bigbut:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.bigbut.completed {
  opacity: 0.9;
  cursor: default;
}

button.bigbut.juice-pop {
  animation: juicePop 0.35s ease;
}

.cluster-summary {
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cluster-count {
  color: var(--accent);
  font-weight: 700;
}

.cluster-full {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
  font-size: clamp(10px, 1.2vw, 13px);
  color: var(--muted);
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
  transform: translateY(-6px);
  z-index: 10;
}

button.bigbut.expanded {
  z-index: 100;
}

button.bigbut.expanded .cluster-full {
  max-height: 180px;
  opacity: 1;
  transform: translateY(0);
  overflow: auto;
}

.matched-card {
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 10px 12px;
  background: var(--card);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.matched-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-size: clamp(13px, 1.6vw, 16px);
}

.matched-count {
  color: var(--accent-2);
  font-weight: 700;
}

.matched-words {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.35s ease;
  font-size: clamp(11px, 1.4vw, 14px);
  color: var(--muted);
}

.matched-card.expanded .matched-words {
  max-height: 520px;
  opacity: 1;
}

.shake {
  animation: shake 0.5s;
  animation-iteration-count: 1;
}

.red {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.is-hidden {
  display: none;
}

.shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  font-size: clamp(11px, 1.3vw, 14px);
  color: var(--muted);
}

.shortcut-key {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-weight: 600;
}

.shortcut-key:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.shortcut-key:active {
  background-color: rgba(0, 0, 0, 0.2);
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 6px;
  background: #1b1b1b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

@media all and (max-width: 768px) {
  .keycap {
    display: none;
  }
}

#reset-indicator {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(27, 27, 27, 0.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2000;
}

#reset-indicator.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#reset-indicator.done {
  animation: resetPulse 0.6s ease;
}

.reset-bar {
  width: 120px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
  position: relative;
}

.reset-bar::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffb347, #ff5f6d);
  border-radius: inherit;
}

#reset-indicator.holding .reset-bar::after {
  animation: holdFill 1s linear forwards;
}

.score-pop {
  animation: scorePop 0.3s ease;
}

#fireworks {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10000;
}

@media (max-width: 980px) {
  #board-wrapper {
    max-height: none;
  }
}

@keyframes shake {
  0% { transform: translateX(1px) rotate(0deg); }
  10% { transform: translateX(-1px) rotate(-1deg); }
  20% { transform: translateX(-3px) rotate(1deg); }
  30% { transform: translateX(3px) rotate(0deg); }
  40% { transform: translateX(1px) rotate(1deg); }
  50% { transform: translateX(-1px) rotate(-1deg); }
  60% { transform: translateX(-3px) rotate(0deg); }
  70% { transform: translateX(3px) rotate(-1deg); }
  80% { transform: translateX(-1px) rotate(1deg); }
  90% { transform: translateX(1px) rotate(0deg); }
  100% { transform: translateX(1px) rotate(-1deg); }
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes juicePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.08) rotate(-1deg); }
  100% { transform: scale(1); }
}

@keyframes scorePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes holdFill {
  from { width: 0%; }
  to { width: 100%; }
}

@keyframes resetPulse {
  0% { transform: translateX(-50%) scale(1); }
  40% { transform: translateX(-50%) scale(1.06); }
  100% { transform: translateX(-50%) scale(1); }
}

@keyframes shuffleFlash {
  0% { box-shadow: 0 0 0 rgba(228, 93, 59, 0); }
  40% { box-shadow: 0 0 24px rgba(228, 93, 59, 0.35); }
  100% { box-shadow: 0 0 0 rgba(228, 93, 59, 0); }
}

@keyframes recentPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(31, 122, 115, 0); }
  40% { transform: scale(1.02); box-shadow: 0 0 18px rgba(31, 122, 115, 0.35); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(31, 122, 115, 0); }
}

@keyframes selectedWiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-1.5deg); }
  75% { transform: rotate(1.5deg); }
}

@keyframes matchBurst {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(31, 122, 115, 0); }
  30% { transform: scale(1.12) rotate(-2deg); box-shadow: 0 0 20px rgba(31, 122, 115, 0.5); }
  60% { transform: scale(1.05) rotate(1deg); box-shadow: 0 0 30px rgba(31, 122, 115, 0.3); }
  100% { transform: scale(1) rotate(0); box-shadow: 0 0 0 rgba(31, 122, 115, 0); }
}

@keyframes goldPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(255, 193, 7, 0.4); }
  50% { box-shadow: 0 0 20px rgba(255, 193, 7, 0.7); }
}

/* Match burst animation */
button.bigbut.match-burst {
  animation: matchBurst 0.5s ease-out;
}

/* Progress glow - intensifies as cluster grows */
button.bigbut.glow-mild {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08), 0 0 8px rgba(255, 193, 7, 0.3);
}
button.bigbut.glow-medium {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08), 0 0 12px rgba(255, 193, 7, 0.5);
  border-color: rgba(255, 193, 7, 0.4);
}
button.bigbut.glow-strong {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08), 0 0 18px rgba(255, 193, 7, 0.7);
  border-color: rgba(255, 193, 7, 0.6);
  background: linear-gradient(135deg, #fffef5 0%, #fff9e6 100%);
}
button.bigbut.glow-intense {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08), 0 0 25px rgba(255, 193, 7, 0.85);
  border-color: rgba(255, 193, 7, 0.8);
  background: linear-gradient(135deg, #fffdf0 0%, #fff4cc 100%);
  animation: goldPulse 1.5s ease-in-out infinite;
}
