:root {
  --bg-0: #070a10;
  --bg-1: #0f1725;
  --ink: #ece5d6;
  --muted: #98a1b2;
  --gold: #d9b064;
  --gold-soft: rgba(217, 176, 100, 0.3);
  --panel: rgba(15, 20, 30, 0.95);
  --line: rgba(217, 176, 100, 0.22);
  --tile-face-a: #fdf8ea;
  --tile-face-b: #eee3c9;
  --tile-side: #a9926a;
  --kanji-font: "Yu Mincho", "MS Mincho", "Yu Gothic", "Meiryo", "SimSun", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(1200px 720px at 50% -12%, #1c2739 0%, transparent 60%),
    radial-gradient(900px 600px at 12% 110%, #14202e 0%, transparent 55%),
    linear-gradient(180deg, #0a0f18 0%, #05070b 100%);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------------- HUD ---------------- */

.hud {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(217, 176, 100, 0.14);
  background: linear-gradient(180deg, rgba(12, 17, 26, 0.96), rgba(9, 13, 20, 0.82));
  backdrop-filter: blur(6px);
  flex-wrap: wrap;
}

.hud-brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.level-name {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-stats {
  display: flex;
  gap: 18px;
  margin: 0;
  margin-left: auto;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}

.stat dt {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(152, 161, 178, 0.75);
}

.stat dd {
  margin: 0;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

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

button {
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

.ghost {
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.ghost:hover:not(:disabled) {
  background: rgba(217, 176, 100, 0.13);
  border-color: var(--gold-soft);
}

.ghost:disabled {
  opacity: 0.35;
}

a.ghost-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.ghost:focus-visible,
.primary:focus-visible,
.link:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

#stage {
  flex: 1;
  min-height: 0;
  display: flex;
}

#boardWrap {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 10px;
  overflow: auto;
}

#boardWrap::before {
  content: "";
  position: absolute;
  inset: 6% 8%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(217, 176, 100, 0.09), transparent 70%);
  pointer-events: none;
}

#scaler {
  position: relative;
}

#board {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

/* ---------------- Taşlar ---------------- */

.tile {
  position: absolute;
  width: 58px;
  height: 76px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid #cbb78d;
  border-radius: 7px;
  background: linear-gradient(158deg, var(--tile-face-a) 0%, var(--tile-face-b) 58%, #e2d5b7 100%);
  box-shadow:
    inset 0 1px 0 #fffdf7,
    inset 0 -3px 0 #d6c6a4,
    0 4px 0 var(--tile-side),
    0 10px 16px rgba(0, 0, 0, 0.45);
  color: #1b2230;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 #fffdf7,
    inset 0 -3px 0 #d6c6a4,
    0 6px 0 var(--tile-side),
    0 14px 22px rgba(0, 0, 0, 0.5);
}

.tile:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.tile.is-blocked {
  filter: brightness(0.87) saturate(0.75);
}

.tile.is-blocked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: rgba(22, 30, 44, 0.16);
  pointer-events: none;
}

.tile.is-selected {
  transform: translateY(-5px);
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 18px rgba(217, 176, 100, 0.45),
    0 6px 0 var(--tile-side),
    0 14px 22px rgba(0, 0, 0, 0.5);
}

.tile.is-matching {
  animation: tile-pop 0.26s ease-out forwards;
  pointer-events: none;
}

.tile.is-nope {
  animation: tile-nope 0.32s ease-in-out;
}

.tile.is-hint {
  animation: tile-hint 0.9s ease-in-out infinite;
}

@keyframes tile-pop {
  to {
    transform: translateY(-10px) scale(0.62) rotate(7deg);
    opacity: 0;
  }
}

@keyframes tile-nope {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes tile-hint {
  0%,
  100% {
    box-shadow:
      inset 0 1px 0 #fffdf7,
      0 4px 0 var(--tile-side),
      0 0 0 0 rgba(217, 176, 100, 0);
  }
  50% {
    box-shadow:
      inset 0 1px 0 #fffdf7,
      0 4px 0 var(--tile-side),
      0 0 0 3px rgba(217, 176, 100, 0.85);
  }
}

/* Taş yüzü parçaları */

.pip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 1px;
  width: 68%;
  height: 62%;
}

.pip {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: currentColor;
  transform: scale(0.74);
  box-shadow: inset 0 -1px 1px rgba(0, 0, 0, 0.25);
}

.stick {
  width: 4px;
  height: 100%;
  border-radius: 2px;
  background: currentColor;
  justify-self: center;
  transform: scaleY(0.82);
}

.kanji {
  font-family: var(--kanji-font);
  font-size: 27px;
  line-height: 1;
  font-weight: 600;
}

.suit-mark {
  font-family: var(--kanji-font);
  font-size: 10px;
  letter-spacing: 0.22em;
  opacity: 0.72;
  margin-left: 0.22em;
}

.glyph {
  font-family: var(--kanji-font);
  font-size: 30px;
  line-height: 1;
}

.tile .suit-mark {
  margin-top: 2px;
}

.suit-dots {
  color: #1d5c8c;
}
.suit-bamboo {
  color: #1c6b46;
}
.suit-char {
  color: #8d2020;
}
.suit-wind {
  color: #2c3d6b;
}
.suit-flower {
  color: #7a3f8a;
}
.suit-season {
  color: #a3692a;
}

.tile.is-outline .glyph {
  -webkit-text-stroke: 1.2px currentColor;
  color: transparent;
}

.face-image {
  width: 76%;
  height: 72%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

/* ---------------- Erişilebilirlik ---------------- */

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

/* ---------------- Ekranlar ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(700px 480px at 50% 10%, rgba(35, 49, 70, 0.55), transparent 70%),
    rgba(4, 6, 10, 0.8);
  backdrop-filter: blur(4px);
}

.overlay.is-hidden {
  display: none;
}

.panel {
  display: none;
  width: min(620px, 100%);
  padding: 34px 36px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  animation: panel-in 0.28s ease-out;
}

.panel.is-active {
  display: block;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold);
}

.panel h1 {
  margin: 0 0 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.story-location {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.story-text {
  margin: 0 0 18px;
  padding: 16px 20px;
  border-left: 2px solid var(--gold-soft);
  border-radius: 0 10px 10px 0;
  background: rgba(217, 176, 100, 0.05);
  color: #dcd4c2;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15.5px;
  line-height: 1.72;
  white-space: pre-line;
}

.story-objective {
  margin: 0 0 22px;
  color: #c9bfa6;
  font-size: 13.5px;
}

.story-objective::before {
  content: "Hedef — ";
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.primary {
  padding: 11px 22px;
  border: 1px solid rgba(217, 176, 100, 0.5);
  border-radius: 9px;
  background: linear-gradient(180deg, #e2bd77, #c39a4e);
  color: #1b1508;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 18px rgba(217, 176, 100, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(217, 176, 100, 0.32);
}

.link {
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: rgba(152, 161, 178, 0.4);
  text-underline-offset: 3px;
}

.link:hover {
  color: var(--ink);
}

.hint-line {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  color: rgba(152, 161, 178, 0.85);
  font-size: 12px;
  line-height: 1.7;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  font-family: inherit;
  font-size: 11px;
  color: var(--ink);
}

.win-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
}

.win-stats li {
  min-width: 118px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.win-stats span {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.level-list {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.level-item {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.level-item:hover:not(:disabled) {
  border-color: var(--gold-soft);
  background: rgba(217, 176, 100, 0.08);
}

.level-item.is-locked {
  opacity: 0.45;
}

.level-id {
  color: var(--gold);
  font-family: Georgia, serif;
  font-size: 16px;
  letter-spacing: 0.08em;
}

.level-title {
  font-size: 14px;
}

.level-state {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---------------- Ana menü ---------------- */

.menu-panel {
  width: min(680px, 100%);
}

.menu-subtitle {
  margin: 0 0 24px;
  color: #cfc6b2;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.7;
}

.menu-progress {
  margin: 0 0 26px;
  padding: 14px 16px;
  border: 1px solid rgba(217, 176, 100, 0.18);
  border-radius: 11px;
  background: rgba(217, 176, 100, 0.05);
}

.menu-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.menu-progress-head b {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.menu-progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.menu-progress-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #c39a4e, #e8c98a);
  transition: width 0.35s ease;
}

.menu-actions {
  gap: 16px;
  margin-bottom: 4px;
}

.menu-actions .link {
  text-decoration-color: rgba(152, 161, 178, 0.4);
  text-decoration-line: underline;
}

.levels-progress {
  margin: -6px 0 18px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}


.error-text {
  max-height: 300px;
  margin: 0 0 20px;
  padding: 14px 16px;
  overflow: auto;
  border: 1px solid rgba(255, 120, 120, 0.22);
  border-radius: 10px;
  background: rgba(120, 30, 30, 0.14);
  color: #f0c9c0;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ---------------- Bildirim ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 6000;
  max-width: min(90vw, 460px);
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 20, 30, 0.96);
  color: var(--ink);
  font-size: 13px;
  text-align: center;
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------- NES tarzı menü ---------------- */

.nes-panel {
  width: min(700px, 100%);
  padding: 20px;
  border: 3px solid #e8c98a;
  border-radius: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px),
    #0b0b12;
  box-shadow:
    0 0 0 3px #120d08,
    0 0 0 6px #b9862c,
    0 18px 50px rgba(0, 0, 0, 0.75),
    inset 0 0 0 2px rgba(232, 201, 138, 0.12);
}

.nes-frame {
  padding: 18px 20px 14px;
  border: 2px solid rgba(232, 201, 138, 0.26);
  background: rgba(10, 12, 20, 0.5);
}

.nes-panel .eyebrow {
  letter-spacing: 0.32em;
}

.menu-logo {
  display: block;
  width: min(440px, 100%);
  margin: 4px auto 16px;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.5));
}

/* Logo varsa metin başlık yalnızca ekran okuyucular için kalır. */
.menu-panel.has-logo #menuTitle,
.menu-panel.has-logo .nes-eyebrow {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.menu-panel #menuTitle {
  font-family: "Courier New", Consolas, monospace;
  font-size: 26px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f4d27e;
  text-shadow: 0 3px 0 #241305;
}

.nes-panel .menu-subtitle {
  font-family: "Courier New", Consolas, monospace;
  font-size: 12.5px;
  letter-spacing: 0.03em;
  line-height: 1.8;
  color: #b7ab93;
}

.nes-progress {
  border: 2px solid rgba(232, 201, 138, 0.3);
  border-radius: 0;
  background: rgba(232, 201, 138, 0.05);
}

.nes-progress .menu-progress-head {
  font-family: "Courier New", Consolas, monospace;
  letter-spacing: 0.22em;
}

.nes-progress .menu-progress-head b {
  font-family: "Courier New", Consolas, monospace;
  letter-spacing: 0.14em;
  color: #f4d27e;
}

.nes-progress .menu-progress-track {
  height: 10px;
  border: 1px solid rgba(232, 201, 138, 0.24);
  border-radius: 0;
  background: #151018;
}

.nes-progress .menu-progress-track i {
  border-radius: 0;
  background: repeating-linear-gradient(90deg, #e8c98a 0 8px, #b9862c 8px 10px);
  box-shadow: 0 0 10px rgba(232, 201, 138, 0.35);
}

.press-start {
  margin: 4px 0 18px;
  text-align: center;
  font-family: "Courier New", Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.34em;
  color: #e8c98a;
  animation: nes-blink 1.1s steps(2, start) infinite;
}

@keyframes nes-blink {
  50% {
    opacity: 0;
  }
}

.menu-options {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  margin: 0 0 16px;
  padding: 6px 0;
  border-top: 1px solid rgba(232, 201, 138, 0.18);
  border-bottom: 1px solid rgba(232, 201, 138, 0.18);
}

.nes-option {
  position: relative;
  display: block;
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #a99d86;
  font-family: "Courier New", Consolas, monospace;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.08s linear, background 0.08s linear;
}

.nes-option::before {
  content: "▸";
  position: absolute;
  left: 12px;
  color: #f4d27e;
  opacity: 0;
}

.nes-option.is-active,
.nes-option:hover:not(:disabled),
.nes-option:focus-visible {
  color: #f4d27e;
  background: rgba(232, 201, 138, 0.08);
  outline: none;
}

.nes-option.is-active::before {
  opacity: 1;
  animation: nes-cursor 0.7s steps(2, start) infinite;
}

.nes-option:disabled {
  color: #5c5346;
  cursor: default;
}

@keyframes nes-cursor {
  50% {
    opacity: 0.5;
  }
}

/* Bölüm listesi de aynı çerçeveyi kullanır. */
.nes-panel .levels-progress {
  font-family: "Courier New", Consolas, monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.nes-panel .level-item {
  border: 2px solid rgba(232, 201, 138, 0.28);
  border-radius: 0;
  background: rgba(232, 201, 138, 0.03);
  font-family: "Courier New", Consolas, monospace;
}

.nes-panel .level-item:hover:not(:disabled) {
  border-color: #e8c98a;
  background: rgba(232, 201, 138, 0.1);
}

.nes-panel .level-id,
.nes-panel .level-state {
  font-family: "Courier New", Consolas, monospace;
}

.nes-panel .level-id {
  letter-spacing: 0.16em;
}

.nes-panel .level-title {
  letter-spacing: 0.04em;
}

.nes-panel .link {
  font-family: "Courier New", Consolas, monospace;
  letter-spacing: 0.1em;
}

@media (max-width: 820px) {
  .hud {
    gap: 12px;
    padding: 10px 14px;
  }
  .level-name {
    display: none;
  }
  .hud-stats {
    gap: 12px;
  }
  .panel {
    padding: 26px 22px 22px;
  }
  .panel h1 {
    font-size: 24px;
  }
}
