:root {
  --bg: #f7f5ef;
  --panel: #ffffff;
  --text: #222;
  --muted: #5f5f5f;
  --border: #d8d8d8;
  --yellow: #f6df6f;
  --green: #a8d48e;
  --blue: #97c6f2;
  --purple: #bda3e0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.container {
  max-width: 840px;
  margin: 0 auto;
  padding: 16px 16px 24px;
}

h1 {
  margin: 0 0 8px;
}

.subheading {
  margin: 0 0 20px;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
  background: #f3f3f3;
}

.tab,
button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  background: #fff;
  color: #111;
  border-color: var(--border);
  border-bottom-color: #fff;
  position: relative;
  top: 1px;
}

.tab {
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 12px 16px;
  background: transparent;
}

.tab:last-child {
  border-right: none;
}

.view {
  padding: 14px;
}

#play-view {
  --card-size: min(
    calc((100vw - 72px) / 4),
    max(34px, calc((100vh - 380px) / 4))
  );
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.status-banner {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fafafa;
}

.status-banner.muted {
  color: var(--muted);
}

.status-banner.success {
  background: #edf9e8;
}

.status-banner.error {
  background: #ffefef;
}

.status-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  max-width: min(520px, calc(100vw - 32px));
  width: max-content;
  background: #2e2e2e;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 999;
}

.status-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.status-toast.success {
  background: #2f7a3f;
}

.status-toast.error {
  background: #9f2d2d;
}

.solved-groups {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
  justify-content: center;
}

.solved-group {
  width: calc((4 * var(--card-size)) + 24px);
  min-height: var(--card-size);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--card-size));
  justify-content: center;
  gap: 8px;
}

.submit-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-top: 8px;
}

.card {
  border: 1px solid var(--border);
  background: #f4f4f4;
  border-radius: 10px;
  text-align: center;
  aspect-ratio: 1 / 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px;
}

.card.selectable {
  cursor: pointer;
}

.card.selected {
  background: #222;
  color: #fff;
}

.card.disabled {
  opacity: 0.45;
}

.card.shake {
  animation: shake-card 320ms ease-in-out;
}

.card.fly-up {
  animation: fly-up-card 280ms ease-in forwards;
  z-index: 2;
}

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

@keyframes fly-up-card {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(var(--fly-up-y));
    opacity: 0.25;
  }
}

.game-meta {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.game-meta p {
  margin: 0;
}

.mistake-dots {
  display: flex;
  gap: 8px;
}

.mistake-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #b7b7b7;
}

.mistake-dot.used {
  visibility: hidden;
}

.hidden {
  display: none;
}

.hint {
  color: var(--muted);
  margin-top: 0;
}

.groups-editor {
  display: grid;
  gap: 12px;
}

.group-edit {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.group-edit h3 {
  margin: 0 0 8px;
}

.group-edit label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.group-edit input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  margin-bottom: 8px;
}

.words-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 700px) {
  .game-meta {
    flex-direction: column;
    gap: 8px;
  }

  .words-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 820px) {
  .container {
    padding-top: 10px;
    padding-bottom: 12px;
  }

  .subheading {
    margin-bottom: 12px;
  }

  .panel {
    padding: 12px;
  }

  .tabs {
    margin-bottom: 10px;
  }

  .controls {
    margin-bottom: 8px;
  }
}
