:root {
  --bg-1: #0d1233;
  --bg-2: #1c2560;
  --ink: #1d2340;
  --paper: #fff8ea;
  --paper-2: #f1e2c3;
  --paper-edge: #cdb68a;
  --accent: #ffb648;
  --accent-2: #ff8a3d;
  --green: #3ddc97;
  --green-2: #1fb87a;
  --red: #ff6b6b;
  --text: #eef0ff;
  --muted: #a9b0d6;
  --glass: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.12);
  --font-ui: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #3b2a8a 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #7a2d6b 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: inherit;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 18px;
  animation: screenIn 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.screen.active {
  display: flex;
}

@keyframes screenIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Ana ekran ---------- */

.logo {
  text-align: center;
  margin-top: 28px;
}

.logo-tiles {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 14px;
}

.logo-tiles span {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  font-weight: 800;
  font-size: 26px;
  color: var(--ink);
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: 0 4px 0 var(--paper-edge), 0 10px 20px rgba(0, 0, 0, 0.3);
  animation: logoBob 3.2s ease-in-out infinite;
}

.logo-tiles span:nth-child(2) { animation-delay: 0.15s; }
.logo-tiles span:nth-child(3) { animation-delay: 0.3s; }
.logo-tiles span:nth-child(4) {
  animation-delay: 0.45s;
  background: linear-gradient(180deg, #ffd27a, var(--accent));
  box-shadow: 0 4px 0 #c97f1f, 0 10px 20px rgba(0, 0, 0, 0.3);
}

@keyframes logoBob {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-6px) rotate(-3deg); }
}

.logo h1 {
  font-family: var(--font-serif);
  font-weight: 800;
  font-size: 44px;
  letter-spacing: -0.5px;
  margin: 0;
}

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.level-list {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.level-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 16px 18px;
  text-align: left;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  transition: transform 0.2s, background 0.2s, border-color 0.2s;
}

.level-card:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 182, 72, 0.5);
}

.level-card:active:not(:disabled) {
  transform: scale(0.98);
}

.level-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-num {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffd27a, var(--accent));
  box-shadow: 0 4px 0 #c97f1f;
}

.level-card:disabled .level-num {
  background: linear-gradient(180deg, #8d93b8, #6b7199);
  box-shadow: 0 4px 0 #4b5078;
}

.level-info {
  flex: 1;
  min-width: 0;
}

.level-info strong {
  display: block;
  font-size: 17px;
  margin-bottom: 3px;
}

.level-info span {
  color: var(--muted);
  font-size: 14px;
}

.level-stars {
  display: flex;
  gap: 2px;
}

.star {
  width: 20px;
  height: 20px;
  fill: rgba(255, 255, 255, 0.15);
  stroke: none;
}

.star.on {
  fill: var(--accent);
  filter: drop-shadow(0 0 6px rgba(255, 182, 72, 0.6));
}

.how {
  margin-top: 6px;
  padding: 18px 20px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--glass-border);
}

.how h2 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 20px;
}

.how ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
}

.how b {
  color: var(--text);
}

/* ---------- Oyun ekranı ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  transition: background 0.2s, transform 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.13);
}

.icon-btn:active {
  transform: scale(0.92);
}

#soundBtn .sound-off { display: none; }
#soundBtn.muted .sound-on { display: none; }
#soundBtn.muted .sound-off { display: block; }

.level-title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}

.clue-card {
  position: relative;
  padding: 18px 20px 16px;
  border-radius: 20px;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(29, 35, 64, 0.06) 27px 28px),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: 0 6px 0 var(--paper-edge), 0 18px 36px rgba(0, 0, 0, 0.35);
  transform: rotate(-0.6deg);
}

.clue-card::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 80px;
  height: 20px;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(255, 182, 72, 0.75);
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.clue-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2.5px;
  color: #b0693a;
}

.clue-text {
  margin-top: 6px;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 22px;
  line-height: 1.3;
}

.clue-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  font-weight: 700;
  color: #7a6a4f;
}

.answer-slots {
  display: flex;
  gap: 4px;
}

.answer-slots span {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: #fff;
}

.answer-slots.solved span {
  background: var(--green);
  border-color: var(--green-2);
  animation: slotPop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
}

@keyframes slotPop {
  from { transform: scale(0.3); }
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.moves {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  transition: background 0.3s, border-color 0.3s;
}

.moves-num {
  font-weight: 800;
  font-size: 28px;
  line-height: 1;
  min-width: 1.2ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.moves-num.bump {
  animation: bump 0.3s ease;
}

@keyframes bump {
  40% { transform: scale(1.3); }
}

.moves-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.moves.warn {
  background: rgba(255, 107, 107, 0.16);
  border-color: rgba(255, 107, 107, 0.55);
}

.moves.warn .moves-num {
  color: var(--red);
}

.stars-preview {
  display: flex;
  gap: 3px;
}

.stars-preview .star {
  width: 24px;
  height: 24px;
  transition: fill 0.3s, filter 0.3s, transform 0.3s;
}

.stars-preview .star.lost {
  transform: scale(0.8);
}

/* ---------- Tahta ---------- */

.board-wrap {
  display: flex;
  justify-content: center;
}

.board {
  --n: 5;
  --gap: 8px;
  --pad: 12px;
  --size: min(calc(100vw - 36px), 440px);
  --tile: calc((var(--size) - 2 * var(--pad) - (var(--n) - 1) * var(--gap)) / var(--n));
  position: relative;
  width: var(--size);
  height: var(--size);
  border-radius: 24px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 2px 20px rgba(0, 0, 0, 0.35), 0 20px 40px rgba(0, 0, 0, 0.25);
  touch-action: none;
}

.board.shake {
  animation: shake 0.4s ease;
}

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

.cell-bg {
  position: absolute;
  left: var(--pad);
  top: var(--pad);
  width: var(--tile);
  height: var(--tile);
  border-radius: calc(var(--tile) * 0.22);
  background: rgba(255, 255, 255, 0.04);
  transform: translate(calc(var(--c) * (var(--tile) + var(--gap))), calc(var(--r) * (var(--tile) + var(--gap))));
}

.tile {
  position: absolute;
  left: var(--pad);
  top: var(--pad);
  width: var(--tile);
  height: var(--tile);
  transform: translate(calc(var(--c) * (var(--tile) + var(--gap))), calc(var(--r) * (var(--tile) + var(--gap))));
  transition: transform 0.24s cubic-bezier(0.25, 0.9, 0.3, 1.15);
  z-index: 1;
  cursor: grab;
}

.tile.moving {
  z-index: 3;
}

.tile.entering {
  transition: none;
}

.face {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: calc(var(--tile) * 0.22);
  font-weight: 800;
  font-size: calc(var(--tile) * 0.48);
  color: var(--ink);
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: 0 4px 0 var(--paper-edge), 0 8px 14px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s cubic-bezier(0.3, 1.5, 0.5, 1), box-shadow 0.18s, background 0.3s, color 0.3s, opacity 0.4s;
}

.tile.entering .face {
  animation: tileIn 0.45s cubic-bezier(0.3, 1.4, 0.5, 1) backwards;
  animation-delay: var(--delay, 0s);
}

@keyframes tileIn {
  from {
    opacity: 0;
    transform: scale(0.4) rotate(-10deg);
  }
}

.tile:hover .face {
  transform: translateY(-2px);
}

.tile.selected {
  z-index: 2;
}

.tile.selected .face {
  transform: translateY(-5px) scale(1.06);
  background: linear-gradient(180deg, #ffe2a6, var(--accent));
  box-shadow: 0 5px 0 #c97f1f, 0 0 0 3px rgba(255, 255, 255, 0.85), 0 14px 26px rgba(255, 160, 50, 0.45);
}

.tile.hint .face {
  box-shadow: 0 4px 0 var(--paper-edge), 0 0 0 3px rgba(255, 182, 72, 0.7), 0 8px 14px rgba(0, 0, 0, 0.28);
}

.tile.solved .face {
  color: #06311f;
  background: linear-gradient(180deg, #7ff0bf, var(--green));
  box-shadow: 0 4px 0 var(--green-2), 0 0 24px rgba(61, 220, 151, 0.65);
  animation: solvedPop 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
  animation-delay: var(--delay, 0s);
}

@keyframes solvedPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22) translateY(-8px); }
  100% { transform: scale(1); }
}

.board.done .tile:not(.solved) .face {
  opacity: 0.35;
  transform: scale(0.92);
}

.board.done .tile {
  cursor: default;
}

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}

.ctrl-btn svg {
  width: 18px;
  height: 18px;
}

.ctrl-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.13);
}

.ctrl-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ---------- Pencere ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 10, 30, 0.6);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

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

.modal-card {
  width: min(380px, 100%);
  padding: 28px 24px 22px;
  text-align: center;
  border-radius: 28px;
  background: linear-gradient(180deg, #2a3378, #1b2258);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(30px) scale(0.92);
  transition: transform 0.45s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.modal.open .modal-card {
  transform: none;
}

.modal-stars {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 6px;
  min-height: 10px;
}

.modal-stars .star {
  width: 46px;
  height: 46px;
}

.modal-stars .star:nth-child(2) {
  width: 60px;
  height: 60px;
  margin-bottom: 8px;
}

.modal.open .modal-stars .star.on {
  animation: starIn 0.6s cubic-bezier(0.3, 1.7, 0.5, 1) backwards;
}

.modal.open .modal-stars .star:nth-child(1) { animation-delay: 0.25s; }
.modal.open .modal-stars .star:nth-child(2) { animation-delay: 0.45s; }
.modal.open .modal-stars .star:nth-child(3) { animation-delay: 0.65s; }

@keyframes starIn {
  from {
    transform: scale(0) rotate(-90deg);
    opacity: 0;
  }
}

.modal-card h2 {
  margin: 12px 0 6px;
  font-family: var(--font-serif);
  font-size: 30px;
}

.modal-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal-word {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 18px 0 4px;
}

.modal-word:empty {
  display: none;
}

.modal-word span {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-weight: 800;
  font-size: 20px;
  color: #06311f;
  background: linear-gradient(180deg, #7ff0bf, var(--green));
  box-shadow: 0 3px 0 var(--green-2);
}

.modal-word.reveal span {
  color: var(--ink);
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: 0 3px 0 var(--paper-edge);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.btn {
  flex: 1;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 800;
  transition: transform 0.15s, filter 0.2s;
}

.btn:active {
  transform: scale(0.96);
}

.btn.primary {
  color: var(--ink);
  background: linear-gradient(180deg, #ffd27a, var(--accent));
  box-shadow: 0 4px 0 #c97f1f;
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
}

.btn[hidden] {
  display: none;
}

@media (max-height: 720px) {
  .screen { gap: 12px; }
  .clue-text { font-size: 19px; }
  .board { --size: min(calc(100vw - 36px), 380px); }
}
