:root {
  --ink: #4a3a5c;
  --ink-soft: #7a6a8c;
  --rose: #f2a1b4;
  --rose-deep: #d97fa6;
  --peach: #ffd9c7;
  --cream: #fff6ef;
  --glass: rgba(255, 248, 243, 0.78);
  --glass-edge: rgba(255, 255, 255, 0.7);
  --shadow: 0 18px 50px rgba(80, 40, 90, 0.28);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2b2147;
  font-family: var(--font); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
#app {
  position: fixed; inset: 0; height: 100vh; height: 100dvh; overflow: hidden;
  touch-action: none;
}
#game, #fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game { touch-action: none; cursor: pointer; }
#fx { pointer-events: none; z-index: 40; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hide { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; transition: opacity .4s ease; }
.chip {
  pointer-events: auto; position: absolute; top: calc(10px + var(--sat));
  min-height: 44px; min-width: 44px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 22px; border: 1px solid var(--glass-edge); background: rgba(255, 248, 243, 0.55);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  color: var(--ink); font: 800 13px/1 var(--font); letter-spacing: .08em; text-decoration: none; cursor: pointer;
  box-shadow: 0 4px 14px rgba(80, 40, 90, .15); transition: transform .15s ease, background .2s ease;
}
.chip:active { transform: scale(.94); }
#back { left: calc(10px + var(--sal)); }
#mute { right: calc(10px + var(--sar)); padding: 0; width: 44px; }
#mute[aria-pressed="true"] { opacity: .65; }
#scoreWrap {
  position: absolute; left: 0; right: 0; top: calc(54px + var(--sat)); text-align: center;
  transition: opacity .35s ease, transform .35s ease;
}
#score {
  font-weight: 900; font-size: clamp(56px, 17vmin, 104px); line-height: 1; color: #fff;
  text-shadow: 0 3px 0 rgba(120, 70, 130, .35), 0 8px 26px rgba(60, 30, 90, .35);
  font-variant-numeric: tabular-nums; transform-origin: 50% 60%;
}
#score.bump { animation: bump .28s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.22); } 100% { transform: scale(1); } }
#streak {
  display: inline-flex; align-items: baseline; gap: 6px; margin-top: 6px; padding: 5px 14px 5px 12px; border-radius: 20px;
  background: linear-gradient(135deg, rgba(255, 236, 170, .9), rgba(255, 190, 150, .9));
  color: #8a4a2c; font-weight: 900; box-shadow: 0 0 22px rgba(255, 210, 120, .75);
  animation: streakPulse 1s ease-in-out infinite;
}
#streak b, #streak #streakNum { font-size: 22px; }
#streak .lbl { font-size: 11px; letter-spacing: .14em; }
@keyframes streakPulse { 50% { transform: scale(1.06); } }

#app[data-state="title"] #scoreWrap, #app[data-state="over"] #scoreWrap { opacity: 0; transform: translateY(-14px); }
#app[data-state="over"] #hud .chip { opacity: .0; pointer-events: none; }

#popup, #banner {
  position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; z-index: 12; opacity: 0;
  font-weight: 900; letter-spacing: .06em; white-space: nowrap;
}
#popup { top: 40%; font-size: clamp(26px, 8vmin, 44px); color: #fff; text-shadow: 0 0 18px rgba(255, 240, 180, .95), 0 3px 0 rgba(150, 80, 120, .5); }
#popup.show { animation: popup .9s cubic-bezier(.2, .8, .2, 1) forwards; }
#popup.cut { color: #fff6; text-shadow: none; font-size: 18px; letter-spacing: .12em; }
@keyframes popup { 0% { opacity: 0; transform: translateY(14px) scale(.6); } 18% { opacity: 1; transform: translateY(0) scale(1.1); } 60% { opacity: 1; transform: translateY(-14px) scale(1); } 100% { opacity: 0; transform: translateY(-44px) scale(1); } }
#banner { top: 24%; font-size: clamp(28px, 9vmin, 52px); color: #fff; text-shadow: 0 4px 0 rgba(150, 80, 150, .45), 0 0 30px rgba(255, 200, 255, .8); }
#banner.show { animation: banner 1.5s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: scale(.5); } 15% { opacity: 1; transform: scale(1.15); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
#hint {
  position: absolute; left: 0; right: 0; bottom: calc(14% + var(--sab)); text-align: center; z-index: 9; pointer-events: none;
  color: #fff; font-weight: 800; letter-spacing: .12em; font-size: 14px; text-shadow: 0 2px 10px rgba(60, 30, 90, .55);
  animation: hintPulse 1.4s ease-in-out infinite;
}
@keyframes hintPulse { 50% { opacity: .45; } }

/* ---------- Ekranlar ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(60px + var(--sat)) calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
  opacity: 1; transform: none; transition: opacity .45s ease, transform .45s cubic-bezier(.2, .8, .2, 1);
  touch-action: manipulation;
}
.screen.hidden { opacity: 0; transform: translateY(24px) scale(.97); pointer-events: none; visibility: hidden; transition: opacity .35s ease, transform .35s ease, visibility 0s linear .4s; }
.card {
  width: 100%; max-width: 400px; max-height: 100%; overflow: hidden auto; padding: 16px 18px 16px; text-align: center;
  background: var(--glass); border: 1px solid var(--glass-edge); border-radius: 28px;
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; min-height: 0;
  scrollbar-width: none;
}
.card::-webkit-scrollbar { display: none; }
.card.small { max-width: 320px; gap: 14px; padding: 22px; }

.logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo-ico { animation: floaty 3.2s ease-in-out infinite; filter: drop-shadow(0 6px 8px rgba(120, 60, 120, .3)); flex: none; }
@keyframes floaty { 50% { transform: translateY(-6px) rotate(-3deg); } }
.logo-text { display: flex; flex-direction: column; align-items: flex-start; line-height: .92; }
.logo-text span { font-weight: 900; background: linear-gradient(120deg, #ff9fb6, #ffb98a 45%, #b79bff); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 2px 0 rgba(255, 255, 255, .6)); }
.l1 { font-size: 26px; letter-spacing: .32em; }
.l2 { font-size: 44px; letter-spacing: .04em; animation: shimmer 4s ease-in-out infinite; background-size: 200% 100%; }
@keyframes shimmer { 0%, 100% { background-position: 0 0; } 50% { background-position: 100% 0; } }

.how { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 14px; font-weight: 700; color: var(--ink-soft); text-align: left; }
.how li { padding-left: 22px; position: relative; line-height: 1.25; }
.how li::before { content: ""; position: absolute; left: 4px; top: 4px; width: 9px; height: 9px; background: var(--rose); transform: rotate(45deg); border-radius: 2px; }
.how b { color: var(--ink); }

.nick input {
  width: 100%; height: 46px; border-radius: 16px; border: 2px solid rgba(217, 127, 166, .35); background: rgba(255, 255, 255, .8);
  text-align: center; font: 800 17px var(--font); color: var(--ink); outline: none; transition: border-color .2s, box-shadow .2s;
  -webkit-user-select: text; user-select: text;
}
.nick input:focus { border-color: var(--rose-deep); box-shadow: 0 0 0 4px rgba(242, 161, 180, .3); }
.nick input.bad { animation: shake .4s; border-color: #e0566e; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.btn {
  min-height: 52px; padding: 0 22px; border-radius: 18px; border: 0; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  font: 900 18px var(--font); letter-spacing: .14em; transition: transform .15s ease, box-shadow .2s ease;
}
.btn:active { transform: scale(.96); }
.btn.primary { color: #fff; background: linear-gradient(135deg, #ff9fb6, #ff8f9f 50%, #c58bf0); box-shadow: 0 8px 22px rgba(217, 100, 150, .45), inset 0 2px 0 rgba(255, 255, 255, .45); text-shadow: 0 2px 0 rgba(150, 50, 100, .35); }
.btn.ghost { color: var(--ink); background: rgba(255, 255, 255, .65); border: 2px solid rgba(217, 127, 166, .3); font-size: 15px; }
.btn:focus-visible, .chip:focus-visible, .link:focus-visible { outline: 3px solid #7a5cff; outline-offset: 2px; }
.best { font-size: 13px; font-weight: 800; color: var(--ink-soft); min-height: 16px; letter-spacing: .06em; }
.link { background: none; border: 0; font: 800 13px var(--font); color: var(--rose-deep); text-decoration: underline; cursor: pointer; min-height: 44px; }
.msg { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); min-height: 16px; }
.msg.err { color: #c0445f; }

.board { text-align: left; min-height: 0; }
.board h2 { margin: 2px 0 4px; font-size: 12px; letter-spacing: .2em; color: var(--ink-soft); text-align: center; font-weight: 900; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.rows li { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 4px 10px; border-radius: 10px; background: rgba(255, 255, 255, .55); font-size: 13.5px; font-weight: 800; min-height: 26px; }
.rows li:nth-child(1) { background: linear-gradient(90deg, rgba(255, 224, 150, .85), rgba(255, 255, 255, .6)); }
.rows li.me { outline: 2px solid var(--rose-deep); background: rgba(255, 220, 232, .9); }
.rows .rk { color: var(--rose-deep); font-weight: 900; }
.rows .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .sc { font-variant-numeric: tabular-nums; }
.rows.empty li { color: var(--ink-soft); justify-content: center; grid-template-columns: 1fr; text-align: center; }

.over-head { font-weight: 900; letter-spacing: .24em; font-size: 14px; color: var(--ink-soft); }
.over-score { font-weight: 900; font-size: 84px; line-height: 1; color: var(--ink); display: flex; align-items: baseline; justify-content: center; gap: 8px; font-variant-numeric: tabular-nums; }
.over-score .unit { font-size: 20px; color: var(--ink-soft); letter-spacing: .1em; }
.record { margin: 0 auto; padding: 6px 16px; border-radius: 20px; background: linear-gradient(135deg, #ffe38a, #ffb27a); color: #7a3d12; font-weight: 900; letter-spacing: .16em; font-size: 13px; box-shadow: 0 0 24px rgba(255, 200, 100, .8); animation: streakPulse 1s ease-in-out infinite; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: rgba(255, 255, 255, .6); border-radius: 14px; padding: 8px 4px; display: flex; flex-direction: column; gap: 2px; }
.stats b { font-size: 24px; font-weight: 900; }
.stats span { font-size: 9.5px; letter-spacing: .1em; font-weight: 800; color: var(--ink-soft); }
.btns { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; }

#app[data-state="playing"] #title, #app[data-state="ending"] #title { pointer-events: none; }

/* ---------- Kısa ekran / yatay ---------- */
@media (max-height: 640px) {
  .screen { padding-top: calc(54px + var(--sat)); }
  .card { padding: 12px 14px; gap: 7px; }
  .l2 { font-size: 36px; } .l1 { font-size: 20px; } .logo-ico { width: 42px; height: 42px; }
  .how { font-size: 12.5px; gap: 3px; }
  .nick input { height: 42px; }
  .btn { min-height: 48px; }
  .rows li { padding: 2px 10px; min-height: 22px; font-size: 12.5px; }
  .over-score { font-size: 64px; }
  .stats b { font-size: 20px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .screen { padding-top: calc(52px + var(--sat)); }
  .card { max-width: 760px; display: grid; grid-template-columns: 1fr 1fr; align-items: start; text-align: center; column-gap: 18px; row-gap: 6px; overflow: hidden auto; }
  #title .card > .logo, #title .card > .how, #title .card > .nick, #title .card > #play, #title .card > .best { grid-column: 1; }
  #title .card > .board { grid-column: 2; grid-row: 1 / span 6; }
  #over .card > * { grid-column: 1; }
  #over .card > .board { grid-column: 2; grid-row: 1 / span 6; }
  #over .over-head { display: none; }
  .over-score { font-size: 52px; }
  .card.small { display: flex; max-width: 320px; }
  #scoreWrap { top: calc(8px + var(--sat)); }
  #score { font-size: 54px; }
  #streak { margin-top: 2px; padding: 2px 10px; }
  #popup { top: 34%; }
  #hint { bottom: 6%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
  #streak { box-shadow: none; }
  #popup.show, #banner.show { animation: none; }
}
