* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'DynaPuff', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(170deg, #f8b84c 0%, #e88828 35%, #c06010 100%);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(92deg, transparent, transparent 30px, rgba(120,60,10,0.06) 30px, rgba(120,60,10,0.06) 32px),
    repeating-linear-gradient(0deg, transparent, transparent 40px, rgba(120,60,10,0.04) 40px, rgba(120,60,10,0.04) 42px);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 15%, rgba(255,230,160,0.30) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 85%, rgba(140,50,0,0.20) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ========== SCREEN SYSTEM ========== */
.screen {
  display: none;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 100dvh;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 10px) 12px env(safe-area-inset-bottom, 10px);
}

.screen--active {
  display: flex;
  animation: screenEnter 0.4s cubic-bezier(0.22, 0.9, 0.36, 1) both;
}

@keyframes screenEnter {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========== OVERLAYS ========== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay--active {
  display: flex;
  animation: overlayFadeIn 0.3s ease-out both;
}

.overlay--active .modal-panel {
  animation: modalPop 0.4s cubic-bezier(0.22, 0.9, 0.36, 1.15) both;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalPop {
  from {
    opacity: 0;
    transform: scale(0.75) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-panel {
  background: linear-gradient(180deg, #faecd0 0%, #e4c080 100%);
  border: 3px solid #c8a050;
  border-radius: 24px;
  padding: 24px 28px;
  box-shadow:
    0 4px 0 #a07828,
    0 12px 40px rgba(60,30,0,0.45),
    inset 0 1px 0 rgba(255,255,255,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 320px;
  width: 90%;
  color: #4a2c06;
}

.modal-panel h2 {
  font-size: 20px;
  font-weight: 700;
}

/* ========== HOME SCREEN ========== */
#screen-home {
  justify-content: flex-start;
  gap: 10px;
  padding-top: env(safe-area-inset-top, 14px);
  padding-bottom: env(safe-area-inset-bottom, 10px);
}

#home-header {
  text-align: center;
  padding: 12px 0 2px;
  flex-shrink: 0;
  position: relative;
}

#home-logo {
  font-size: 46px;
  font-weight: 700;
  color: #fff;
  text-shadow:
    0 2px 0 #d07020,
    0 4px 0 #b85a10,
    0 6px 0 #984810,
    0 8px 20px rgba(80,30,0,0.45);
  letter-spacing: 4px;
  cursor: pointer;
  transition: transform 0.1s;
  line-height: 1;
}

#home-logo:active {
  transform: scale(0.95);
}

#home-subtitle {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 3px rgba(80,30,0,0.3);
  margin-top: 3px;
  letter-spacing: 1px;
}

/* Devam Et butonu */
#btn-continue {
  flex-shrink: 0;
  width: 92%;
  max-width: 340px;
  padding: 14px 0;
  font-size: 20px;
  animation: continuePulse 2.5s ease-in-out infinite;
}

@keyframes continuePulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(180,80,10,0.4); }
  50%      { box-shadow: 0 4px 24px rgba(255,120,20,0.65), 0 0 40px rgba(255,140,30,0.2); }
}

/* Istatistikler */
#home-stats {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-shrink: 0;
  width: 92%;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(180deg, #faecd0 0%, #e4c080 100%);
  border: 2px solid #c8a050;
  border-radius: 14px;
  padding: 5px 6px;
  box-shadow: 0 2px 0 #a07828;
  flex: 1;
}

.stat-val {
  font-size: 18px;
  font-weight: 700;
  color: #4a2c06;
  line-height: 1.1;
}

.stat-lbl {
  font-size: 8px;
  font-weight: 600;
  color: #9a7030;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Gunluk Bulmaca */
#home-daily {
  flex-shrink: 0;
  width: 92%;
  background: linear-gradient(180deg, rgba(80,170,230,0.2) 0%, rgba(40,120,200,0.15) 100%);
  border: 2px solid rgba(80,150,220,0.35);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow:
    0 2px 0 rgba(30,80,150,0.12),
    inset 0 1px 0 rgba(255,255,255,0.2);
}

#daily-label {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(30,60,120,0.3);
}

#home-daily .btn-small {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Level grid (sayfa bazli) */
#home-levels {
  flex: 1;
  min-height: 0;
  width: 92%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255,240,210,0.4) 0%, rgba(230,190,120,0.3) 100%);
  border: 2.5px solid rgba(200,160,80,0.4);
  border-radius: 18px;
  padding: 10px 10px 8px;
  box-shadow:
    0 3px 0 rgba(140,90,30,0.12),
    inset 0 1px 0 rgba(255,255,255,0.3);
}

#levels-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-shrink: 0;
}

#levels-title {
  font-size: 14px;
  font-weight: 700;
  color: #5a3808;
}

#levels-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, #d0a868 0%, #b08840 100%);
  border-bottom: 3px solid #8a6828;
  box-shadow: 0 2px 6px rgba(120,80,20,0.25);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

#page-indicator {
  font-size: 13px;
  font-weight: 700;
  color: #5a3808;
  min-width: 48px;
  text-align: center;
}

#level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 0 2px;
}

.lvl-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.06s;
  position: relative;
  border: none;
  padding: 0;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.lvl-cell:active { transform: scale(0.92); }

.lvl-cell--completed {
  background: linear-gradient(180deg, #ffcc44 0%, #e87818 100%);
  border-bottom: 3px solid #c06010;
  box-shadow: 0 3px 8px rgba(180,80,10,0.3);
}

.lvl-cell--completed .lvl-moves {
  font-size: 8px;
  opacity: 0.8;
  margin-top: 1px;
}

.lvl-cell--open {
  background: linear-gradient(180deg, #6898e8 0%, #4070c8 100%);
  border-bottom: 3px solid #2850a0;
  box-shadow: 0 3px 8px rgba(40,80,160,0.3);
}

.lvl-cell--locked {
  background: linear-gradient(180deg, #8a7a60 0%, #6a5a40 100%);
  border-bottom: 3px solid #4a3a28;
  box-shadow: 0 3px 8px rgba(40,30,10,0.3);
  opacity: 0.5;
  cursor: default;
}

.lvl-cell--locked .lvl-lock {
  font-size: 12px;
}

#home-footer {
  flex-shrink: 0;
}

/* Home stagger animations */
.screen--active #home-header {
  animation: itemDrop 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.1) 0.03s both;
}

.screen--active #btn-continue {
  animation: itemDrop 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.1) 0.08s both;
}

.screen--active #home-stats {
  animation: itemDrop 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.1) 0.13s both;
}

.screen--active #home-daily {
  animation: itemDrop 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.1) 0.18s both;
}

.screen--active #home-levels {
  animation: itemDrop 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.1) 0.23s both;
}

.screen--active #home-footer {
  animation: itemDrop 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.1) 0.28s both;
}

@keyframes itemDrop {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========== GAME SCREEN ========== */
#screen-game {
  justify-content: center;
  gap: 10px;
  position: relative;
  padding-top: env(safe-area-inset-top, 8px);
  padding-bottom: env(safe-area-inset-bottom, 8px);
}

.screen--active #hud {
  animation: slideDown 0.45s cubic-bezier(0.22, 0.9, 0.36, 1) 0.08s both;
}

.screen--active #canvas-wrap {
  animation: boardEnter 0.5s cubic-bezier(0.22, 0.9, 0.36, 1.05) 0.15s both;
}

.screen--active #controls {
  animation: slideUp 0.45s cubic-bezier(0.22, 0.9, 0.36, 1) 0.25s both;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-24px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes boardEnter {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

#hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 92%;
  background: linear-gradient(180deg, #faecd0 0%, #e4c080 100%);
  border: 3px solid #c8a050;
  border-radius: 16px;
  padding: 4px 10px;
  flex-shrink: 0;
  position: relative;
  box-shadow:
    0 3px 0 #a07828,
    0 6px 14px rgba(80,40,0,0.30),
    inset 0 1px 0 rgba(255,255,255,0.55);
}

#hud::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 12px;
  background:
    repeating-linear-gradient(90deg, transparent, transparent 20px, rgba(139,90,30,0.05) 20px, rgba(139,90,30,0.05) 22px);
  pointer-events: none;
}

.hud-btn {
  background: rgba(160,120,40,0.15);
  border: 1.5px solid rgba(160,120,40,0.25);
  border-radius: 10px;
  padding: 3px 10px;
  font-size: 14px;
  color: #4a2c06;
  cursor: pointer;
  position: relative;
  z-index: 1;
  font-family: inherit;
  text-shadow: none;
  border-bottom: none;
}

.badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(160,120,40,0.10);
  border: 1.5px solid rgba(160,120,40,0.20);
  border-radius: 10px;
  padding: 2px 12px;
  font-size: 16px;
  font-weight: 700;
  color: #4a2c06;
  position: relative;
  z-index: 1;
}

.badge .lbl {
  color: #9a7030;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #5090e0 0%, #3068c0 100%);
  border: 4px solid #68a8f8;
  border-bottom-color: #2050a0;
  border-radius: 22px;
  padding: 8px;
  flex-shrink: 0;
  box-shadow:
    0 5px 0 #1c4080,
    0 10px 24px rgba(20,40,90,0.45),
    inset 0 2px 0 rgba(255,255,255,0.18),
    inset 0 -2px 4px rgba(0,0,0,0.12);
}

canvas {
  display: block;
  border-radius: 14px;
  touch-action: none;
}

#controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-shrink: 0;
}

/* ========== WIN OVERLAY ========== */
#win-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  border-radius: 0;
}

#win-overlay.overlay--active {
  animation: winBgIn 0.5s ease-out both;
}

#win-overlay.overlay--active .modal-panel {
  animation: winPanelIn 0.55s cubic-bezier(0.16, 1, 0.3, 1.15) 0.15s both;
}

#win-overlay.overlay--active #win-title {
  animation: winTitleBounce 0.6s cubic-bezier(0.22, 0.9, 0.36, 1.2) 0.35s both;
}

@keyframes winBgIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes winPanelIn {
  from {
    opacity: 0;
    transform: scale(0.5) translateY(40px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes winTitleBounce {
  0% { opacity: 0; transform: scale(0.4); }
  60% { transform: scale(1.12); }
  100% { opacity: 1; transform: scale(1); }
}

#win-title {
  font-size: 26px;
  font-weight: 700;
  color: #4a2c06;
}

#win-moves {
  font-size: 18px;
  color: #7a5a20;
}

#win-moves-val {
  font-size: 28px;
  font-weight: 700;
  color: #c06010;
}

/* ========== DEV MENU ========== */
#dev-panel {
  gap: 10px;
  max-width: 300px;
}

.dev-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  width: 100%;
  color: #4a2c06;
}

.dev-row input[type="number"] {
  width: 70px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 2px solid #c8a050;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  background: #fff8ee;
  color: #4a2c06;
  outline: none;
}

.dev-row input[type="range"] {
  flex: 1;
}

#dev-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ========== SETTINGS ========== */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 600;
  color: #4a2c06;
  cursor: pointer;
}

.toggle-row input { display: none; }

.toggle-track {
  width: 44px;
  height: 24px;
  background: #b09060;
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
}

.toggle-row input:checked + .toggle-track {
  background: #58c070;
}

.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}

.toggle-row input:checked + .toggle-track .toggle-knob {
  transform: translateX(20px);
}

/* ========== SHARED BUTTONS ========== */
button {
  border-radius: 14px;
  border: none;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.22);
  transition: transform 0.06s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

button::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  border-radius: 14px 14px 50% 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 100%);
  pointer-events: none;
}

button:active { transform: scale(0.94) translateY(2px); }

.btn-big {
  padding: 14px 40px;
  font-size: 20px;
  border-radius: 18px;
}

.btn-small {
  padding: 8px 18px;
  font-size: 13px;
}

.btn-orange {
  background: linear-gradient(180deg, #ff9736 0%, #e07818 100%);
  border-bottom: 4px solid #b85a10;
  box-shadow: 0 4px 12px rgba(180,80,10,0.4);
}

.btn-green {
  background: linear-gradient(180deg, #58c070 0%, #38a050 100%);
  border-bottom: 4px solid #288838;
  box-shadow: 0 4px 10px rgba(40,120,50,0.35);
}

.btn-blue {
  background: linear-gradient(180deg, #6898e8 0%, #4070c8 100%);
  border-bottom: 4px solid #2850a0;
  box-shadow: 0 4px 10px rgba(40,80,160,0.35);
}

.btn-purple {
  background: linear-gradient(180deg, #c878e0 0%, #a050c0 100%);
  border-bottom: 4px solid #7838a0;
  box-shadow: 0 4px 10px rgba(120,60,160,0.35);
}

.btn-wood {
  background: linear-gradient(180deg, #d0a868 0%, #b08840 100%);
  border-bottom: 4px solid #8a6828;
  box-shadow: 0 4px 10px rgba(120,80,20,0.3);
  color: #fff8e8;
}

/* ========== RANGE (shared) ========== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 8px;
  background: linear-gradient(180deg, #faecd0, #d8b878);
  border: 2px solid #c0a050;
  border-radius: 99px;
  outline: none;
  cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.12);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #fff 0%, #ffc040 50%, #e09020 100%);
  border: 3px solid #c07018;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(160,80,0,0.5);
}

input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #fff 0%, #ffc040 50%, #e09020 100%);
  border: 3px solid #c07018;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(160,80,0,0.5);
}
