:root {
  color-scheme: dark;
  --navy: #0f172a;
  --slate: #1e293b;
  --gold: #d4af37;
  --text: #f8fafc;
  --muted: #94a3b8;
  --danger: #ef4444;
  --timer-font: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
  font-family: "Cairo", system-ui, sans-serif;
}

body {
  margin: 0;
  min-height: 100dvh;
  height: 100dvh;
  background: var(--navy);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.app {
  width: min(95vw, 520px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
  justify-content: space-between;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.topbar-left,
.topbar-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 0;
}

.topbar-left {
  align-items: flex-start;
  text-align: right;
  justify-self: start;
  width: 100%;
  gap: 8px;
}

.topbar-right {
  align-items: flex-end;
  text-align: left;
  justify-self: end;
  width: 100%;
}

.header {
  text-align: center;
  min-height: 72px;
}

.header h1 {
  margin: 0;
  color: var(--gold);
  font-size: 2.6rem;
}

.header p {
  margin: 4px 0 0;
  color: var(--muted);
}

#headerSubtitle {
  white-space: pre-line;
}


.resource-item {
  font-size: 0.9rem;
}

.resource-item span {
  color: var(--gold);
  font-weight: 700;
}

.timer {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
  font-family: var(--timer-font);
  font-variant-numeric: tabular-nums;
}

.level-select select,
.language-select select {
  appearance: none;
  border: 1px solid #334155;
  background: #111827;
  color: var(--text);
  padding: 8px 28px 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  text-align: right;
  direction: rtl;
}

.level-select,
.language-select {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.level-select,
.language-select {
  display: none;
}

.level-select::after,
.language-select::after {
  content: "▾";
  position: absolute;
  right: 10px;
  color: var(--muted);
  pointer-events: none;
  font-size: 0.9rem;
}

.grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--size), 1fr);
  width: min(100%, calc(100dvw - 32px), calc(100dvh - 380px));
  margin-inline: auto;
}

.tile {
  aspect-ratio: 1 / 1;
  background: var(--slate);
  border: 1px solid #334155;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
  touch-action: none;
}

.tile.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.tile.correct-green {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  animation: pop 0.2s ease;
}

.tile.hint-blue {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.18);
  animation: pop 0.2s ease;
}

.tile.shake-red {
  border-color: var(--danger);
  animation: shake 0.35s ease;
}

.tile.locked {
  cursor: not-allowed;
  opacity: 0.75;
}

.tile--placed {
  animation: pop 0.2s ease;
}

.tile--drag-image {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.4);
  z-index: 1000;
}

#checkButton {
  border-color: #22c55e;
  color: #22c55e;
  text-shadow:
    0 1px 0 rgba(15, 23, 42, 0.9),
    0 -1px 0 rgba(15, 23, 42, 0.9),
    1px 0 0 rgba(15, 23, 42, 0.9),
    -1px 0 0 rgba(15, 23, 42, 0.9);
}

#checkButton:hover {
  background: rgba(34, 197, 94, 0.15);
}

#hintButton {
  border-color: #38bdf8;
  color: #38bdf8;
  text-shadow:
    0 1px 0 rgba(15, 23, 42, 0.9),
    0 -1px 0 rgba(15, 23, 42, 0.9),
    1px 0 0 rgba(15, 23, 42, 0.9),
    -1px 0 0 rgba(15, 23, 42, 0.9);
}

#hintButton:hover {
  background: rgba(56, 189, 248, 0.18);
}

@keyframes pop {
  0% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
  }
}

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

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-content: center;
}

.tray-button {
  background: #111827;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: clamp(6px, 1.6vw, 10px) clamp(8px, 2vw, 14px);
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
  touch-action: none;
}

.tray-button--used {
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

.tray-button:active {
  transform: translateY(1px);
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.countdown {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  font-family: var(--timer-font);
  font-variant-numeric: tabular-nums;
}

.countdown--inline {
  opacity: 0.85;
}

.control-button {
  background: var(--gold);
  color: #1f2937;
  border: none;
  padding: clamp(8px, 1.8vw, 12px) clamp(10px, 2.4vw, 16px);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: clamp(0.9rem, 2.4vw, 1rem);
  transition: background 0.2s ease;
}

.control-button:hover {
  background: #f1d782;
}

.stats-button {
  background: #111827;
  border: 1px solid #334155;
  border-radius: 12px;
  color: var(--gold);
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s ease;
}

.stats-button:hover {
  background: rgba(212, 175, 55, 0.2);
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 0;
}

.stats-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-size: 0.95rem;
}

.stats-item span:last-child {
  font-weight: 700;
}

.footer {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 6px;
}

.footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer a:hover {
  color: var(--gold);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--slate);
  padding: 24px;
  border-radius: 16px;
  text-align: center;
  width: min(90vw, 360px);
}

.modal-card h2 {
  margin-top: 0;
  color: var(--gold);
}

.modal-actions {
  margin-top: 16px;
}

.confetti-screen {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.9;
  animation: confetti-fall 1.6s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0;
  }
}

.heatmap {
  margin: 12px 0 0;
  font-size: 1.1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}

.solution {
  margin: 12px 0 0;
  font-size: 1.1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}

.solution-grid {
  margin: 12px auto 0;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  width: min(70vw, 240px);
}

.solution-tile {
  aspect-ratio: 1 / 1;
  background: #111827;
  border: 1px solid #334155;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  color: var(--text);
}

.solution-tile.correct-green {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
}

.solution-tile.hint-blue {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.18);
}

.solution-tile.warning-orange {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.18);
}

.solution-tile.wrong-red {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

.word-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.word-list__label {
  color: var(--muted);
  font-size: 0.95rem;
}

.word-list__hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.word-list__items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.word-list__items a {
  color: var(--gold);
  text-decoration: none;
  border: 1px solid rgba(212, 175, 55, 0.35);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  background: rgba(17, 24, 39, 0.85);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.word-list__items a:hover {
  background: rgba(212, 175, 55, 0.15);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.4);
  transform: translateY(-1px);
}

.word-list__items a:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
}

.countdown {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-family: var(--timer-font);
  font-variant-numeric: tabular-nums;
}

.tutorial-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  margin-top: 12px;
  font-size: 0.95rem;
}

.tutorial-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tutorial-title {
  margin: 0;
  color: var(--gold);
  font-weight: 700;
}

.tutorial-subtitle {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
}

.tutorial-resources {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
}

.tutorial-grid {
  position: relative;
  width: min(70vw, 280px);
  aspect-ratio: 1 / 1;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(var(--size), 1fr);
  background: #0b1324;
  border-radius: 14px;
  padding: 10px;
}

.tutorial-cell {
  border-radius: 10px;
  border: 1px solid #334155;
  background: rgba(15, 23, 42, 0.65);
}

.tutorial-arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.tutorial-arrows .arrow-row {
  stroke: #f59e0b;
  color: #f59e0b;
}

.tutorial-arrows .arrow-col {
  stroke: #38bdf8;
  color: #38bdf8;
}

.tutorial-arrows .arrow-diag {
  stroke: #a78bfa;
  color: #a78bfa;
}

.tutorial-arrows path,
.tutorial-arrows line {
  fill: none;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 480px) {
  .tutorial-arrows path,
  .tutorial-arrows line {
    stroke-width: 3.2;
  }
}

.tutorial-option input {
  accent-color: var(--gold);
}
