/*
 * Oyun teması: app.js her oyunda --accent / --accent-2'yi oyunun meta.theme renkleriyle değiştirir.
 * @property kaydı sayesinde renkler (ve onları kullanan degradeler) yumuşakça geçiş yapar.
 */
@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #22e4ff;
}

@property --accent-2 {
  syntax: "<color>";
  inherits: true;
  initial-value: #ff2e88;
}

:root {
  --accent: #22e4ff;
  --accent-2: #ff2e88;
  --bg: #07070d;
  --bg-2: #0e0e1c;
  --line: #22223d;
  --text: #ecebff;
  --dim: #8b8aad;
  --cyan: #22e4ff;
  --pink: #ff2e88;
  --yellow: #ffe14d;
  --font: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", "Courier New", monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
  transition: --accent 0.5s ease, --accent-2 0.5s ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% -20%, color-mix(in srgb, var(--accent) 11%, transparent), transparent 60%),
    radial-gradient(ellipse at 100% 110%, color-mix(in srgb, var(--accent-2) 9%, transparent), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

button,
select {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Üst çubuk ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 7%, transparent), transparent 45%, color-mix(in srgb, var(--accent-2) 6%, transparent));
  box-shadow: 0 1px 18px -8px var(--accent);
}

.logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--cyan);
  text-decoration: none;
  text-shadow: 0 0 10px rgba(34, 228, 255, 0.7);
  white-space: nowrap;
}

.logo span {
  color: var(--pink);
  text-shadow: 0 0 10px rgba(255, 46, 136, 0.7);
}

.toolbar {
  display: flex;
  gap: 8px;
  min-width: 0;
}

/* Üst çubuk düğmeleri: arka planları seçili oyunun renk paletinden türetilir. */
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--accent) 20%, var(--bg-2)),
    color-mix(in srgb, var(--accent-2) 12%, var(--bg-2)));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s var(--ease-out), filter 0.15s;
}

/* [hidden] öznitelik düzeyindedir; .tool-btn display kuralı onu ezmesin (ör. iPhone'da tam ekran düğmesi). */
.tool-btn[hidden] {
  display: none;
}

.tool-btn .ico {
  line-height: 1;
}

.tool-btn:hover,
.tool-btn:focus-visible,
.tool-btn:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent);
  filter: brightness(1.12);
  outline: none;
}

.tool-btn:active {
  transform: translateY(1px);
}

.lang-pick {
  position: relative;
  padding-right: 6px;
}

.lang-pick select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  padding: 0 14px 0 0;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 5px top 55%, right 1px top 55%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}

.lang-pick select option {
  background: var(--bg-2);
  color: var(--text);
}

.tool-btn[aria-pressed="true"] {
  color: var(--dim);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
  filter: grayscale(0.6);
  border-color: var(--line);
}

/* ---------- Oyun menüsü ---------- */

.menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.menu-btn {
  --btn-accent: var(--cyan);
  --btn-accent-2: var(--pink);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, box-shadow 0.2s, background 0.2s, transform 0.2s var(--ease-out);
}

/* Her oyunun kendi renginde küçük bir gösterge noktası */
.menu-btn::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--btn-accent);
  box-shadow: 0 0 6px var(--btn-accent);
  flex: none;
}

.menu-btn:hover,
.menu-btn:focus-visible {
  color: var(--text);
  border-color: var(--btn-accent);
  transform: translateY(-1px);
  outline: none;
}

.menu-btn.active {
  color: var(--bg);
  background: linear-gradient(135deg, var(--btn-accent), var(--btn-accent-2));
  border-color: var(--btn-accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--btn-accent) 65%, transparent);
}

.menu-btn.active::before {
  background: var(--bg);
  box-shadow: none;
}

/* ---------- Mobil oyun çubuğu ve oyun seçici ---------- */

.game-bar {
  display: none;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  align-content: start;
  gap: 10px;
  padding-top: 14px;
}

.pick {
  --pa: var(--cyan);
  --pb: var(--pink);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 88px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--pa) 38%, var(--line));
  border-radius: 12px;
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--pa) 16%, var(--bg-2)),
    color-mix(in srgb, var(--pb) 7%, var(--bg-2)));
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s var(--ease-out);
}

.pick:hover,
.pick:focus-visible {
  border-color: var(--pa);
  outline: none;
}

.pick:active {
  transform: scale(0.97);
}

.pick[aria-current="page"] {
  border-color: var(--pa);
  box-shadow: 0 0 0 1px var(--pa), 0 0 16px color-mix(in srgb, var(--pa) 45%, transparent);
}

.pick-icon {
  font-size: 26px;
  line-height: 1;
}

.pick-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--pa);
}

.pick-best {
  font-size: 11px;
  color: var(--dim);
}

/* ---------- Mobil oyun modu ve ipuçları ---------- */

.play-bar,
.rotate-hint {
  display: none;
}

.play-bar {
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 8px;
}

.play-bar-icon {
  font-size: 20px;
  line-height: 1;
}

.play-bar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.rotate-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--dim);
  text-align: center;
}

/* ---------- Sahne ---------- */

.stage {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-title {
  margin: 0 0 10px;
  font-size: 20px;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
}

/* ---------- Oyun geçişi: başlık ve metinler aşağıdan belirir, canvas parlaması nabız atar ---------- */

.stage.entering .game-title {
  animation: rise-in 0.45s var(--ease-out) both;
}

.stage.entering .game-description {
  animation: rise-in 0.5s var(--ease-out) 0.06s both;
}

.stage.entering .game-controls {
  animation: rise-in 0.5s var(--ease-out) 0.12s both;
}

.stage.entering #game-canvas {
  animation: canvas-glow 0.7s ease-out;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
    filter: blur(3px);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@keyframes canvas-glow {
  from {
    box-shadow:
      0 0 0 2px var(--accent),
      0 0 50px color-mix(in srgb, var(--accent) 55%, transparent),
      0 0 90px color-mix(in srgb, var(--accent-2) 30%, transparent);
  }
}

.canvas-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

/*
 * Engine, canvas'ın mantıksal boyutunu --cw / --ch olarak yazar.
 * Genişlik: mantıksal boyut, kapsayıcı ve --avail-h yüksekliğe sığacak şekilde en küçüğü;
 * yükseklik aspect-ratio ile türetilir → oran her zaman korunur.
 * --avail-h'yi app.js ölçer (görünür yükseklik − canvas'ın üst konumu); JS'ten önce 75vh.
 */
#game-canvas {
  --cw: 600;
  --ch: 600;
  display: block;
  width: min(calc(var(--cw) * 1px), 100%, calc(var(--avail-h, 75vh) * var(--cw) / var(--ch)));
  height: auto;
  aspect-ratio: var(--cw) / var(--ch);
  max-width: 100%;
  max-height: var(--avail-h, 75vh);
  background: var(--bg);
  border-radius: 6px;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 38%, transparent),
    0 0 24px color-mix(in srgb, var(--accent) 18%, transparent),
    0 0 60px color-mix(in srgb, var(--accent-2) 9%, transparent);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}

.game-description,
.game-controls {
  max-width: 640px;
  margin: 10px 0 0;
  text-align: center;
  font-size: 13px;
}

.game-description {
  color: var(--text);
}

.game-controls {
  color: var(--dim);
}

.kbd-label {
  display: inline-block;
  margin-right: 4px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.notice {
  color: var(--yellow);
}

/* ---------- Ayar paneli (sağdan kayan çekmece; mobilde alttan açılan sayfa) ---------- */

.settings {
  position: fixed;
  inset: 0;
  z-index: 20;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 0.3s;
}

.settings.open {
  visibility: visible;
  pointer-events: auto;
  transition: visibility 0s;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 10, 0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.settings.open .settings-backdrop {
  opacity: 1;
}

.settings-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--accent) 10%, transparent), transparent 40%),
    var(--bg-2);
  border-left: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: -10px 0 40px -10px color-mix(in srgb, var(--accent) 45%, transparent);
  transform: translateX(104%);
  transition: transform 0.32s var(--ease-out);
}

.settings.open .settings-panel {
  transform: none;
}

.settings-head,
.settings-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.settings-head {
  border-bottom: 1px solid var(--line);
}

.settings-foot {
  border-top: 1px solid var(--line);
}

.settings-title {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 16px;
}

.settings-note {
  margin: 0;
  font-size: 11px;
  color: var(--dim);
}

.settings-empty {
  color: var(--dim);
}

.setting {
  margin: 14px 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.setting legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--yellow);
}

.setting legend .live {
  font-weight: 400;
  letter-spacing: 0;
  color: var(--dim);
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.opt {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 20, 40, 0.9);
  font-size: 13px;
  font-weight: 700;
  color: var(--dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.15s var(--ease-out);
}

.opt small {
  font-weight: 400;
  font-size: 11px;
  opacity: 0.8;
}

.opt:hover,
.opt:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
}

.opt:active {
  transform: scale(0.97);
}

.opt[aria-checked="true"] {
  color: var(--bg);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  border-color: var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 55%, transparent);
}

.sw {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--sw, var(--accent));
  box-shadow: 0 0 6px var(--sw, var(--accent)), inset 0 0 0 1px rgba(0, 0, 0, 0.35);
  flex: none;
}

.sw.rainbow {
  background: conic-gradient(#ff4d5e, #ffe14d, #39ff88, #22e4ff, #4d7cff, #b26bff, #ff4d5e);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
}

.footer {
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11px;
  color: var(--dim);
}

/* ---------- Mobil ---------- */

/* Dokunmatik ekranda her düğme en az 44 px (Apple HIG / Material 48 dp önerisine yakın). */
@media (pointer: coarse) {
  .tool-btn,
  .menu-btn,
  .opt {
    min-height: 44px;
  }

  .tool-btn {
    min-width: 44px;
    justify-content: center;
  }
}

@media (max-width: 640px), (max-height: 500px) and (pointer: coarse) {
  .topbar {
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }

  /* Mobil GPU'da arkada çizilmeye devam eden canvas'ın her karede bulanıklaştırılması pahalı. */
  .settings-backdrop {
    backdrop-filter: none;
    background: rgba(4, 4, 10, 0.72);
  }

  .settings-foot {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .logo {
    font-size: 18px;
  }

  .tool-btn {
    padding: 6px 8px;
    font-size: 13px;
  }

  .toolbar {
    gap: 6px;
  }

  /* Dar ekranda üst çubuk düğmeleri yalnızca simge gösterir (erişilebilir ad aria-label'da). */
  .tool-btn .lbl {
    display: none;
  }

  .settings-panel {
    top: auto;
    left: 0;
    width: 100%;
    max-height: 82vh;
    border-left: 0;
    border-top: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
    border-radius: 16px 16px 0 0;
    transform: translateY(104%);
  }

  .settings-head .tool-btn .lbl {
    display: inline;
  }

  /* Mobilde yatay kayan menü yerine tek bir "oyun çubuğu" gösterilir (gizli kalan 9 oyun fark
     edilmiyordu); başlığı da o taşır. Tüm oyunlar oyun seçicide. */
  .menu {
    display: none;
  }

  .game-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    width: calc(100% - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)));
    min-height: 48px;
    margin: 8px auto 0;
    padding: 6px 14px;
    border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--line));
    border-radius: 12px;
    background: linear-gradient(135deg,
      color-mix(in srgb, var(--accent) 16%, var(--bg-2)),
      color-mix(in srgb, var(--accent-2) 9%, var(--bg-2)));
    box-shadow: 0 0 14px -6px var(--accent);
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .game-bar:active {
    transform: scale(0.99);
  }

  .game-bar-icon {
    font-size: 22px;
    line-height: 1;
  }

  .game-bar-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--accent);
  }

  .game-bar-hint {
    flex: none;
    font-size: 12px;
    color: var(--dim);
  }

  /* Başlık oyun çubuğunda görünür; h1 ekran okuyucular için yerinde kalır. */
  .game-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* Oyun modu: oynarken yalnızca ince şerit + canvas (üst çubuk, oyun çubuğu ve metinler gizli). */
  .play-mode .topbar,
  .play-mode .game-bar,
  .play-mode .game-description,
  .play-mode .game-controls,
  .play-mode .footer,
  .play-mode .rotate-hint {
    display: none;
  }

  .play-mode .play-bar {
    display: flex;
  }

  /* Dokunma yüzeyi etkinken sahnede sayfa kaydırma/yakınlaştırma olmasın (swipe oyuna gitsin). */
  .touch-surface .stage {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Dar dikey ekranda uzun oyunları genişlik sınırlar: kenar boşluğu da küçülür. */
  .play-mode .stage {
    padding: max(8px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) 4px max(4px, env(safe-area-inset-left));
  }

  /* Yatay oyun (Pong, Life…) dikey ekranda küçük kalır: yan çevirme ipucu. */
  html[data-wide] .rotate-hint {
    display: block;
  }

  .picker-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px;
  }

  .pick {
    min-height: 84px;
    padding: 10px;
  }

  .stage {
    padding: 8px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  }

  .game-title {
    font-size: 15px;
    margin-bottom: 8px;
  }
}

@media (orientation: landscape) {
  html[data-wide] .rotate-hint {
    display: none;
  }
}

/*
 * Hareketi azalt: kayma, ölçek ve bulanıklık animasyonları kapanır; geçişler yalnızca
 * solma (opaklık) ve renk değişimi olarak kalır — ekran değişimi yine fark edilir ama hareket etmez.
 */
@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage.entering .game-title,
  .stage.entering .game-description,
  .stage.entering .game-controls {
    animation-name: fade-in;
  }

  .settings-panel {
    transform: none;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .settings.open .settings-panel {
    opacity: 1;
  }

  .menu-btn:hover,
  .menu-btn:focus-visible,
  .tool-btn:active,
  .opt:active {
    transform: none;
  }
}
