:root {
  --bg: #032349;
  --bg-accent: #0a2d4f;
  --ink: rgba(255, 255, 255, .7);
  --muted: rgba(255, 255, 255, .5);
  --card: #0a2d4f;
  --shadow: rgba(0, 0, 0, .3);
  --gap: 3px;
  --radius: 12px;
}

body {
  height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
}

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

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

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

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

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

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

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

.stat-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
}

.stat-divider {
  width: 1px;
  height: 14px;
  background: rgba(255, 255, 255, 0.15);
}

#filter-input {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  padding: 6px 10px;
  min-width: min(160px, 40vw);
  font-size: clamp(11px, 1.3vw, 14px);
  background: #0a2d4f;
  color: var(--ink);
  margin-left: auto;
}

.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 24px 14px;
}

#board-wrapper {
  flex: 1;
  background: rgba(10, 45, 79, 0.7);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px var(--shadow);
  overflow: auto;
}

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

#board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--gap);
  padding: 10px;
  min-height: 100%;
  align-content: start;
}

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

.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(217, 119, 6, 0.35);
  border-radius: 12px;
}

#board > button.bigbut:nth-child(odd) {
  background-color: rgba(255, 255, 255, 0.025);
}

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

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

button.bigbut.selected {
  outline: 4px solid var(--accent);
  box-shadow: 0 0 0 5px rgba(217, 119, 6, 0.25);
}

#pin-zone {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 500;
  background: var(--bg);
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

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

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



.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.completed b {
  color: var(--accent);
}

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 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 5px 5px 6px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
}

.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: #0a2d4f;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: 0 12px 24px var(--shadow);
  transform: translateY(-6px);
  z-index: 10;
}

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

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

.matched-card {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 12px;
  background: var(--card);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  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);
  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 !important;
}

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

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

.shortcut-key:active {
  background-color: rgba(255, 255, 255, 0.15);
}

.shortcut-label {
  display: inline-block;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width 0.9s ease;
  vertical-align: middle;
}

.shortcut-key:hover .shortcut-label {
  max-width: 200px;
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: var(--radius);
  background: #1b1b1b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

@media all and (max-width: 768px) {
  .shortcut-label {
    display: none;
  }
  .shortcut-key {
    overflow: visible;
  }
}

@media all and (max-width: 575.98px) {
  .topbar .shortcuts .shortcut-key,
  .topbar .shortcuts .stat-card {
    display: none;
  }
  .topbar .shortcuts {
    flex-wrap: wrap;
  }
  #filter-input {
    margin-left: 0;
    width: 100%;
    min-width: 0;
  }
}

.shortcuts-mobile {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#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: var(--radius);
  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: var(--radius);
  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: var(--accent);
  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;
}



@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(217, 119, 6, 0); }
  40% { box-shadow: 0 0 24px rgba(217, 119, 6, 0.35); }
  100% { box-shadow: 0 0 0 rgba(217, 119, 6, 0); }
}

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

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

@keyframes goldPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(217, 119, 6, 0.4); }
  50% { box-shadow: 0 0 20px rgba(217, 119, 6, 0.7); }
}

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

button.bigbut.glow-mild {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25), 0 0 8px rgba(217, 119, 6, 0.3);
}
button.bigbut.glow-medium {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25), 0 0 12px rgba(217, 119, 6, 0.5);
  border-color: rgba(217, 119, 6, 0.4);
}
button.bigbut.glow-strong {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25), 0 0 18px rgba(217, 119, 6, 0.7);
  border-color: rgba(217, 119, 6, 0.6);
  background: var(--card);
}
button.bigbut.glow-intense {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25), 0 0 25px rgba(217, 119, 6, 0.85);
  border-color: rgba(217, 119, 6, 0.8);
  background: var(--card);
  animation: goldPulse 1.5s ease-in-out infinite;
}

#win-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 35, 73, 0.85);
}

.win-modal {
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 20px 60px var(--shadow);
}

.win-modal h2 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 28px;
  margin: 0 0 8px;
  color: #fff;
}

.win-modal p {
  margin: 0 0 20px;
  color: var(--muted);
}

#load-error {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: #7f1d1d;
  color: #fca5a5;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
