/* Uzamsal Bulmacalar — iPad öncelikli arayüz */

:root {
  --bg: #f4efe6;
  --card: #fffdf9;
  --ink: #1f2731;
  --muted: #69717d;
  --line: #e3dccf;
  --accent: #d4622a;
  --accent-dark: #b44e1b;
  --accent-soft: #fbe5d6;
  --ok: #2a9152;
  --ok-soft: #e0f3e7;
  --bad: #cc3d3d;
  --bad-soft: #fbe3e3;
  --kolay: #2a9152;
  --orta: #c47a12;
  --zor: #b23b5b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(31, 39, 49, 0.06), 0 6px 18px rgba(31, 39, 49, 0.07);
  --cube-top: #ffe2b3;
  --cube-left: #f2aa62;
  --cube-right: #d4823b;
  --cube-edge: #4a2a12;
  --floor: #ece5d8;
  --floor-alt: #e5ddce;
  --floor-line: #cfc5b3;
  color-scheme: light;
}

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

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: manipulation;
}

body.is-play {
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 32px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 22px;
}

a {
  color: inherit;
}

.muted {
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

/* ---------------------------------------------------------------- düğmeler */

.btn,
.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active,
.seg-btn:active,
.fab:active,
.tile:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-dark);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.big {
  min-height: 60px;
  font-size: 19px;
  padding: 0 24px;
}

.btn.icon-only {
  width: 52px;
  padding: 0;
}

.ico {
  width: 24px;
  height: 24px;
  flex: none;
}

.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  vertical-align: middle;
}

.badge.kolay {
  background: var(--kolay);
}

.badge.orta {
  background: var(--orta);
}

.badge.zor {
  background: var(--zor);
}

/* ---------------------------------------------------------------- ana sayfa */

.home {
  max-width: 980px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom))
    calc(24px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.home-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.home-head p {
  margin: 6px 0 0;
  font-size: 19px;
}

.hero {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  align-items: center;
  padding: 22px 28px;
}

.hero-art .legend {
  width: 100%;
  height: auto;
  display: block;
}

.hero-text {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-start;
}

.hero-count {
  margin: 0;
  font-size: 20px;
}

.progress {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #ece5d8;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  background: var(--ok);
  border-radius: 999px;
}

.level-sec {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.level-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.level-head .badge {
  font-size: 18px;
  padding: 5px 16px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 12px;
}

.tile {
  position: relative;
  min-height: 76px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--card);
  border: 2px solid var(--line);
  font-size: 24px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease;
}

.tile.started {
  border-color: var(--orta);
}

.tile.solved {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.tile i {
  position: absolute;
  top: 5px;
  right: 6px;
  color: var(--ok);
}

.tile i .ico {
  width: 18px;
  height: 18px;
}

.random {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 20px 24px;
}

.random p {
  margin: 4px 0 0;
}

.home-foot {
  display: flex;
  justify-content: center;
}

/* ---------------------------------------------------------------- oyun ekranı */

.play {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(300px, 41%) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    'top top'
    'views stage'
    'tools tools';
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom))
    calc(14px + env(safe-area-inset-left));
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
}

.topbar .back {
  padding-left: 8px;
}

.topbar .title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  font-size: 21px;
  font-weight: 700;
  min-width: 0;
}

.topbar .size {
  font-size: 16px;
  font-weight: 600;
}

.views {
  grid-area: views;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.vcard {
  position: relative;
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 10px 10px 12px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.vcard figcaption {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  padding: 0 2px 6px;
  white-space: nowrap;
  overflow: hidden;
}

.vcard figcaption span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.cube-icon {
  width: 24px;
  height: 26px;
  flex: none;
}

.vcard .status {
  margin-left: auto;
  font-size: 20px;
}

.vcard.ok {
  border-color: var(--ok);
  background: #f6fbf8;
}

.vcard.ok .status {
  color: var(--ok);
}

.vcard.bad {
  border-color: var(--bad);
  background: #fff8f8;
}

.vcard.bad .status {
  color: var(--bad);
}

.vcard .drawing {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vcard .drawing svg {
  width: 100%;
  height: 100%;
  display: block;
}

.vcard .flip {
  display: none;
  flex: none;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--bad);
  background: #fff;
  color: var(--bad);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.vcard.bad .flip {
  display: inline-flex;
  align-items: center;
}

.vcard.bad .status {
  margin-left: 4px;
}

.vcard.bad .cap {
  flex: 1;
}

.vcard .mine {
  display: none;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}

.vcard .mine svg {
  width: 100%;
  height: 100%;
  display: block;
}

.vcard.show-mine .mine {
  display: flex;
}

.vcard.show-mine .drawing {
  display: none;
}

.vcard.show-mine .flip {
  background: var(--bad);
  color: #fff;
}

.legend-card {
  align-items: center;
  justify-content: center;
  background: transparent;
  border-style: dashed;
  box-shadow: none;
}

.legend-card .legend {
  width: 100%;
  height: 100%;
  max-width: 230px;
}

.views .vcard[data-view='top'] {
  order: 1;
}

.views .legend-card {
  order: 2;
}

.views .vcard[data-view='front'] {
  order: 3;
}

.views .vcard[data-view='right'] {
  order: 4;
}

.stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  min-width: 0;
  background: radial-gradient(ellipse at 50% 60%, #fffdf8 0%, #f7f1e6 75%);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.stage.remove-mode {
  box-shadow: inset 0 0 0 4px var(--bad), var(--shadow);
}

.mode-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  display: none;
  z-index: 2;
  pointer-events: none;
}

.stage.remove-mode .mode-banner {
  display: block;
}

.builder {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

.builder.turn {
  animation: turn 0.22s ease-out;
}

@keyframes turn {
  from {
    opacity: 0.45;
  }
  to {
    opacity: 1;
  }
}

.builder .floor {
  fill: var(--floor);
  stroke: var(--floor-line);
  stroke-width: 0.022;
}

.builder .floor.alt {
  fill: var(--floor-alt);
}

.builder .wire {
  stroke: #bdb4a5;
  stroke-width: 0.022;
  stroke-dasharray: 0.09 0.09;
  fill: none;
  pointer-events: none;
}

.builder .cube polygon {
  stroke: var(--cube-edge);
  stroke-width: 0.034;
  stroke-linejoin: round;
}

.builder .ft {
  fill: var(--cube-top);
}

.builder .fl {
  fill: var(--cube-left);
}

.builder .fr {
  fill: var(--cube-right);
}

.builder .cube.wrong .ft {
  fill: #ffc2c2;
}

.builder .cube.wrong .fl {
  fill: #ee7d7d;
}

.builder .cube.wrong .fr {
  fill: #cc4a4a;
}

.builder .cube.wrong polygon {
  stroke: #7d1515;
}

.builder .cube.pop {
  animation: pop 0.28s ease-out;
}

@keyframes pop {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

.builder .ghost {
  pointer-events: none;
  animation: blink 1.1s ease-in-out infinite;
}

.builder .ghost polygon {
  fill: rgba(42, 145, 82, 0.28);
  stroke: var(--ok);
  stroke-width: 0.055;
  stroke-dasharray: 0.13 0.08;
  stroke-linejoin: round;
}

@keyframes blink {
  50% {
    opacity: 0.45;
  }
}

.builder .lbl {
  font-size: 0.4px;
  font-weight: 800;
  fill: var(--muted);
  letter-spacing: 0.02px;
  pointer-events: none;
}

.builder .lbl.front {
  fill: var(--accent);
}

.fab {
  position: absolute;
  bottom: 14px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.08s ease;
}

.fab .ico {
  width: 28px;
  height: 28px;
}

.fab.left {
  left: 14px;
}

.fab.right {
  right: 14px;
}

.stage-tip {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  pointer-events: none;
  white-space: nowrap;
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -12px);
  max-width: calc(100% - 28px);
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(31, 39, 49, 0.92);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 3;
}

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

.toast.bad {
  background: rgba(204, 61, 61, 0.95);
}

.toolbar {
  grid-area: tools;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar .spacer {
  flex: 1;
}

.seg {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 17px;
  background: #e9e2d5;
}

.seg-btn {
  border: 0;
  background: transparent;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 13px;
}

.seg-btn.active {
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.seg-btn[data-act='mode-remove'].active {
  color: var(--bad);
}

/* Dikey iPad: görünüşler üstte tek sıra, kurma alanı altta */
@media (orientation: portrait) {
  .play {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 0.46fr) minmax(0, 1fr) auto;
    grid-template-areas: 'top' 'views' 'stage' 'tools';
  }

  .views {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
  }

  .legend-card {
    display: none;
  }

  .views .vcard[data-view='front'] {
    order: 2;
  }

  .views .vcard[data-view='right'] {
    order: 3;
  }
}

/* Dar ekranlar (telefon ya da bölünmüş ekran) */
@media (max-width: 760px) {
  .toolbar .btn span,
  .toolbar .seg-btn span {
    display: none;
  }

  .toolbar .btn.primary span {
    display: inline;
  }

  .topbar .back span {
    display: none;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-art {
    max-width: 200px;
  }

  h1 {
    font-size: 27px;
  }
}

@media (max-width: 760px) and (orientation: landscape) {
  .play {
    grid-template-columns: minmax(220px, 40%) minmax(0, 1fr);
  }
}

/* ---------------------------------------------------------------- pencereler */

.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(31, 39, 49, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.modal.open {
  opacity: 1;
}

.modal .sheet {
  width: min(640px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  background: var(--card);
  border-radius: 24px;
  padding: 26px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-user-select: text;
  user-select: text;
}

.modal .row {
  justify-content: flex-end;
}

.sheet.success {
  align-items: center;
  text-align: center;
  width: min(460px, 100%);
}

.sheet.success p {
  margin: 0;
}

.big-check {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.big-check .ico {
  width: 44px;
  height: 44px;
  stroke-width: 3;
}

.iso-preview {
  width: 220px;
  max-width: 70%;
}

.iso-preview svg {
  width: 100%;
  height: auto;
  display: block;
}

.sheet.success .row {
  justify-content: center;
}

.help-grid {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 18px;
  align-items: start;
}

.help-art .legend {
  width: 100%;
  height: auto;
}

.help ol {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet.confirm p {
  margin: 0;
}

@media (max-width: 600px) {
  .help-grid {
    grid-template-columns: 1fr;
  }

  .help-art {
    max-width: 160px;
  }
}
