:root {
  --ink: #172033;
  --muted: #7c8496;
  --panel: rgba(247, 249, 255, 0.88);
  --primary: #5361aa;
  --primary-dark: #323b7d;
  --mint: #62c68d;
  --warning: #ffb33f;
  --danger: #ee6a91;
  font-family: "Avenir Next", "Nunito Sans", "Segoe UI", sans-serif;
}

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

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #111827;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

button,
.hud-card,
.tutorial-banner,
.task-sticky,
.skip-button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud-card,
.status-card,
.panel-button,
.dpad,
.stance-button,
.look-zone,
.draw-card,
.success-card {
  position: fixed;
  z-index: 2;
}

.hud-card {
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  width: min(360px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 22px;
  padding: 12px;
  background: rgba(246, 248, 255, 0.86);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.portrait {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--danger));
  font-weight: 950;
  font-size: 24px;
}

.hud-card strong,
.status-card strong {
  display: block;
  font-weight: 950;
}

.hud-card p {
  margin: 3px 0 0;
  color: #4f586a;
  font-size: 14px;
  line-height: 1.35;
}

.status-card {
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  min-width: 154px;
  border-radius: 20px;
  padding: 12px 14px;
  color: #fff;
  background: rgba(23, 32, 51, 0.74);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.status-card span {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 900;
}

.panel-button {
  right: max(18px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  min-width: 118px;
  min-height: 58px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font: inherit;
  font-weight: 950;
  box-shadow: 0 0 0 0 rgba(98, 198, 141, 0.55);
  opacity: 0.45;
}

.panel-button.ready {
  opacity: 1;
  animation: pulse 1.1s infinite;
}

.panel-button:disabled {
  pointer-events: none;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(98, 198, 141, 0.58);
  }
  100% {
    box-shadow: 0 0 0 18px rgba(98, 198, 141, 0);
  }
}

.dpad {
  left: max(18px, env(safe-area-inset-left));
  bottom: max(24px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 8px;
}

.dpad button,
.draw-actions button {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  color: #fff;
  background: rgba(23, 32, 51, 0.68);
  font: inherit;
  font-weight: 950;
  backdrop-filter: blur(12px);
}

.dpad button[data-move="forward"] {
  grid-column: 2;
}

.dpad button[data-move="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad button[data-move="backward"] {
  grid-column: 2;
  grid-row: 3;
}

.dpad button[data-move="right"] {
  grid-column: 3;
  grid-row: 2;
}

.stance-button {
  left: max(18px, env(safe-area-inset-left));
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 186px);
  min-width: 110px;
  min-height: 56px;
  padding: 0 22px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  color: #fff;
  background: rgba(23, 32, 51, 0.68);
  backdrop-filter: blur(12px);
  font: inherit;
  font-weight: 950;
  font-size: 15px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.stance-button:hover {
  transform: translateY(-1px);
}

.stance-button.crouched {
  color: #1d1233;
  border-color: rgba(166, 75, 255, 0.6);
  background: linear-gradient(135deg, #ede4f8, #c8b3ec);
  box-shadow: 0 12px 28px rgba(166, 75, 255, 0.32);
}

.look-zone {
  right: 0;
  top: 0;
  width: 45vw;
  height: 100vh;
  pointer-events: none;
}

.look-zone span {
  position: absolute;
  right: 20px;
  top: 50%;
  color: rgba(255, 255, 255, 0.34);
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
}

.draw-overlay,
.success-overlay {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 15, 28, 0.72);
  backdrop-filter: blur(12px);
}

.draw-overlay[hidden],
.success-overlay[hidden] {
  display: none !important;
}

.draw-card,
.success-card {
  position: static;
  width: min(760px, 100%);
  border-radius: 30px;
  padding: clamp(20px, 4vw, 34px);
  background: var(--panel);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.32);
}

.draw-card h1,
.success-card h1 {
  margin: 0 0 8px;
  font-size: clamp(38px, 8vw, 72px);
  line-height: 0.94;
  letter-spacing: -0.06em;
}

.draw-card p,
.success-card span {
  color: var(--muted);
  font-weight: 800;
}

#drawCanvas {
  display: block;
  width: 100%;
  max-height: 46vh;
  margin: 18px 0;
  border: 1px solid #d2d8e7;
  border-radius: 24px;
  background: #fff;
  touch-action: none;
}

.draw-actions {
  display: flex;
  gap: 10px;
}

.draw-actions button {
  min-height: 48px;
  padding: 0 18px;
  color: var(--ink);
  background: #fff;
}

#drawStatus.good {
  color: #1a7b45;
}

#drawStatus.bad {
  color: #b13b43;
}

.success-card {
  text-align: center;
}

.success-card p {
  margin: 0 0 10px;
  color: var(--mint);
  font-weight: 950;
  letter-spacing: 0.16em;
}

@media (max-width: 720px) {
  .status-card {
    top: auto;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(28px, env(safe-area-inset-bottom)) + 72px);
  }

  .dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
  }
}

/* Solution butonu */
.skip-button {
  position: fixed;
  top: calc(max(16px, env(safe-area-inset-top)) + 70px);
  right: max(16px, env(safe-area-inset-right));
  z-index: 3;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: #fff;
  background: rgba(23, 32, 51, 0.74);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(12px);
}
.skip-button:hover {
  background: rgba(83, 97, 170, 0.85);
}
.skip-button.disabled,
.skip-button:disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: default;
}
@media (max-width: 720px) {
  .skip-button {
    top: calc(max(16px, env(safe-area-inset-top)) + 70px);
    font-size: 12px;
  }
}
@media (max-width: 720px) and (orientation: portrait) {
  .skip-button {
    /* HUD card sağ kenarıyla çakışmasın diye sağ-alt panel-button üstüne taşı */
    top: auto;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(28px, env(safe-area-inset-bottom)) + 76px);
    font-size: 12px;
    padding: 7px 12px;
    min-height: 34px;
  }
}

/* Tutorial banner — üst, 5sn auto-hide veya manuel kapat */
.tutorial-banner {
  position: fixed;
  top: calc(max(16px, env(safe-area-inset-top)) + 64px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(480px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, rgba(94, 58, 142, 0.92), rgba(212, 83, 126, 0.88));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
  backdrop-filter: blur(10px);
}
.tutorial-banner.visible {
  opacity: 1;
  pointer-events: auto;
}
.tutorial-banner[hidden] {
  display: none;
}
.tutorial-icon {
  flex-shrink: 0;
  font-size: 18px;
}
.tutorial-text {
  flex: 1 1 auto;
}
.tutorial-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  margin-right: -6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.14);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 180ms ease;
}
.tutorial-close:hover {
  background: rgba(255, 255, 255, 0.26);
}

/* Alt sticky görev metni */
.task-sticky {
  position: fixed;
  left: 50%;
  bottom: calc(max(28px, env(safe-area-inset-bottom)) + 100px);
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.95);
  background: rgba(23, 32, 51, 0.74);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 240ms ease;
  backdrop-filter: blur(10px);
}
.task-sticky.visible {
  opacity: 1;
}
.task-sticky[hidden] {
  display: none;
}
.task-label {
  color: rgba(166, 75, 255, 0.92);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
}

/* Stance button alignment cue (alignment ≥70 ilk kez) */
@keyframes alignmentPulse {
  0% { box-shadow: 0 0 0 0 rgba(166, 75, 255, 0.55); }
  70% { box-shadow: 0 0 0 14px rgba(166, 75, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(166, 75, 255, 0); }
}
.stance-button.alignment-cue {
  animation: alignmentPulse 1s infinite;
  border-color: rgba(166, 75, 255, 0.7);
}

@media (max-width: 720px) and (orientation: portrait) {
  .tutorial-banner {
    top: calc(max(16px, env(safe-area-inset-top)) + 8px);
    width: calc(100vw - 24px);
    padding: 10px 12px;
    font-size: 13px;
  }
  .task-sticky {
    bottom: calc(max(28px, env(safe-area-inset-bottom)) + 86px);
    font-size: 12px;
    padding: 7px 12px;
  }
}

/* Transition fade */
.transition-overlay {
  position: fixed;
  inset: 0;
  z-index: 9;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.05s linear;
}
.transition-overlay[hidden] {
  display: none;
}
.loading-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10;
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.06em;
  transform: translate(-50%, -50%);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.loading-hint[hidden] {
  display: none;
}

/* Sarnıç UI */
.sarnic-ui {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
.sarnic-ui[hidden] {
  display: none;
}
.ayna-container {
  position: absolute;
  right: 24px;
  bottom: 100px;
  width: 200px;
  height: 200px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(23, 32, 51, 0.18);
  pointer-events: auto;
}
.ayna-rect {
  position: absolute;
  left: 70px;
  top: 80px;
  width: 60px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(135deg, #88ccff, #2266aa);
  box-shadow: 0 6px 18px rgba(60, 120, 255, 0.5);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
}
.ayna-rect:active {
  cursor: grabbing;
}

/* Puzzle 3 placeholder */
.puzzle3-placeholder {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(10, 14, 26, 0.65), rgba(26, 20, 48, 0.75));
  backdrop-filter: blur(10px);
}
.puzzle3-placeholder[hidden] {
  display: none;
}
.puzzle3-card {
  width: min(540px, 100%);
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  color: #fff;
  background: rgba(23, 32, 51, 0.74);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(14px);
}
.puzzle3-card h1 {
  margin: 0 0 12px;
  font-size: 28px;
  letter-spacing: -0.02em;
}
.puzzle3-card p {
  margin: 0 0 24px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 700;
}
.puzzle3-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.puzzle3-card button,
.puzzle3-card .puzzle3-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 24px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font: inherit;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
  transition: background 180ms ease, transform 180ms ease;
}
.puzzle3-card button:hover,
.puzzle3-card .puzzle3-link:hover {
  transform: translateY(-1px);
}
.puzzle3-card button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.puzzle3-card button:hover {
  background: rgba(255, 255, 255, 0.2);
}
.puzzle3-card .puzzle3-link {
  background: var(--primary);
}
.puzzle3-card .puzzle3-link:hover {
  background: #6878c0;
}
@media (max-width: 480px) {
  .puzzle3-actions {
    flex-direction: column;
  }
  .puzzle3-card button,
  .puzzle3-card .puzzle3-link {
    width: 100%;
  }
}

/* Mobile portrait UI sıkıştırma — puzzle 1 koridoru için */
@media (max-width: 720px) and (orientation: portrait) {
  .hud-card {
    padding: 10px;
    gap: 10px;
  }

  .status-card {
    /* Sağ-alt panel-button çakışmasını ortadan kaldır: sol-üst HUD altına taşı */
    top: calc(max(16px, env(safe-area-inset-top)) + 96px);
    left: max(16px, env(safe-area-inset-left));
    right: auto;
    bottom: auto;
    min-width: 0;
    padding: 8px 12px;
    color: rgba(255, 255, 255, 0.92);
    background: rgba(83, 71, 132, 0.62);
    font-size: 13px;
  }

  .status-card span {
    font-size: 11px;
  }

  .stance-button {
    bottom: calc(max(24px, env(safe-area-inset-bottom)) + 158px);
    min-width: 88px;
    min-height: 48px;
    padding: 0 16px;
    font-size: 14px;
  }

  .dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 4px;
  }
}

/* ===== Reveal cinematic overlay (Faz F — sahne arkada, DOM üstte) ===== */
.reveal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.reveal-overlay[hidden] {
  display: none;
}

/* Faz F: fade-to-black sahne swap (3.0sn) */
.reveal-fade {
  position: absolute;
  inset: 0;
  z-index: 250;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 500ms ease;
}
.reveal-fade.active {
  opacity: 1;
}

/* Diyalog overlay — 3D sahne üstünde merkez-alt */
.reveal-dialog {
  position: absolute;
  left: 50%;
  top: 72%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 22px;
  width: min(760px, calc(100vw - 48px));
  padding: 18px 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(10, 16, 30, 0.78), rgba(8, 12, 22, 0.84));
  border: 1px solid rgba(102, 204, 255, 0.22);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), 0 0 24px rgba(68, 136, 204, 0.18);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 400ms ease;
}
.reveal-dialog.visible {
  opacity: 1;
}
.reveal-dialog-avatar {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(102, 204, 255, 0.45);
  box-shadow: 0 0 12px rgba(68, 136, 204, 0.4);
  background: rgba(20, 30, 50, 0.6);
}
.reveal-dialog-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.reveal-name {
  font: 600 24px "Inter", "Avenir Next", "Nunito Sans", sans-serif;
  letter-spacing: 0.04em;
  text-shadow: 0 0 14px currentColor;
}
.reveal-name .reveal-name-suffix {
  margin-left: 8px;
  color: rgba(200, 220, 240, 0.55);
  font-style: italic;
  font-weight: 400;
  font-size: 0.7em;
  letter-spacing: 0.02em;
  text-shadow: none;
}
.reveal-line {
  font: 300 italic 30px "Inter", "Avenir Next", "Nunito Sans", sans-serif;
  color: #f0f4f8;
  line-height: 1.3;
  letter-spacing: 0.01em;
}
.reveal-line.whisper {
  font-size: 22px;
  opacity: 0.85;
  letter-spacing: 0.05em;
}

@media (max-width: 720px) and (orientation: portrait) {
  .reveal-dialog {
    top: auto;
    bottom: max(28px, env(safe-area-inset-bottom));
    transform: translate(-50%, 0);
    width: calc(100vw - 24px);
    padding: 12px 14px;
    gap: 14px;
  }
  .reveal-dialog-avatar { width: 48px; height: 48px; }
  .reveal-name { font-size: 18px; }
  .reveal-line { font-size: 22px; }
  .reveal-line.whisper { font-size: 17px; }
}

/* Body class durum yönetimi — skip-button KALDI (puzzle 2/3'te de görünür olmalı) */
body.puzzle-2-active .dpad,
body.puzzle-2-active .stance-button,
body.puzzle-2-active .panel-button,
body.puzzle-2-active .look-zone,
body.puzzle-2-active .status-card {
  display: none !important;
}
body.puzzle-1-active .sarnic-ui {
  display: none !important;
}
body.puzzle-3-active .hud-card,
body.puzzle-3-active .dpad,
body.puzzle-3-active .stance-button,
body.puzzle-3-active .panel-button,
body.puzzle-3-active .status-card,
body.puzzle-3-active .look-zone,
body.puzzle-3-active .sarnic-ui {
  display: none !important;
}

