/* =========================================================================
   KARAKTER OLUŞTURMA EKRANI (3D) — head2.png üzerine binen kod tabanlı arayüz
   Sol: Metin2 orijinal "Karakter Oluştur" penceresi (istemci görselleri + uiscript koordinatları)
   Orta: three.js kanvas (şeffaf; parşömen arkada görünür) + kamera araç çubuğu
   Animasyon/kamera koddan belirlenir (characters.base.json > scene/camera, window.M2CharSel)
   Boyutlar konteyner genişliğine (cqw) göre ölçeklenir; 900px görselde 1:1'dir.
   ========================================================================= */
.m2-cs {
  position: relative;
  margin: 0;
  --cs-top: 13.2%;      /* head2.png: başlık bandının bittiği yer */
  --cs-height: 74%;     /* parşömen boş alanın yüksekliği */
  --cs-zoom: 1;         /* pencere ölçeği; charsel.js sütun genişliğine göre günceller */
  --cs-board-dim: 0.3;  /* pano iç karartması (0 = orijinal %45 siyah) */
}
.m2-cs__bg { display: block; width: 100%; height: auto; }
.m2-cs__ui {
  position: absolute;
  left: 4%;
  right: 4%;
  top: var(--cs-top);
  height: var(--cs-height);
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr;
  gap: 2%;
  font-family: Tahoma, "Readex Pro", system-ui, sans-serif;
  container-type: inline-size;
}

/* =========================================================================
   PENCERE — Metin2 orijinal "CreateCharacterWindow" (locale/common/ui/createcharacterwindow.py)
   Tüm ölçüler oyunun 800x600 arayüz pikselidir; blok `zoom` ile ölçeklenir (JS: --cs-zoom).
   Görseller: assets/img/ui/charsel/*.webp  (tools/3d/extract_ui.py istemciden çıkarır)
     name_<sınıf>  256x146  locale/<dil>/ui/select/name_*.sub      (kanji + sınıf adı)
     thinboard     48x48    ui/pattern/thinboard_*.tga  9 dilim   (ui.py > ThinBoard, orta %45 siyah)
     btn_small/middle/large_01|02|03  43|61|88 x 21   ui/public/*_button_*.sub (normal|üzerinde|basılı)
     slot_name     115x18   ui/public/parameter_slot_04.sub
     gauge_slot    48x8     ui/pattern/gauge_slot_{left,center,right}.tga   gauge_<renk> 16x8
   Yazı: Tahoma 12 (locale_game.txt > UI_DEF_FONT), renk 0.78 gri (CTextLine varsayılanı)
   ========================================================================= */
.m2-cs__win {
  grid-row: 1 / span 2;
  align-self: start;
  justify-self: start;
  position: relative;
  width: 256px;                                /* sınıf adı görseli genişliği */
  height: 478px;                               /* 149 (ad) + 329 (pano) */
  zoom: var(--cs-zoom, 1);
  font: 12px/14px Tahoma, Verdana, "Segoe UI", sans-serif;
  color: #c7c7c7;
  user-select: none;
}
/* sınıf adı görselleri: name_x at (BOARD_X-27, BOARD_Y-149); alfa geçişi orijinaldeki gibi yumuşak */
.m2-cs__names { position: absolute; left: 0; top: 0; width: 256px; height: 146px; pointer-events: none; }
.m2-cs__names img { position: absolute; inset: 0; width: 256px; height: 146px; opacity: 0; transition: opacity 0.35s ease; }
.m2-cs__names img.is-on { opacity: 1; }

/* character_board: thinboard 208x329 at (27,149) */
.m2-cs__board { position: absolute; left: 27px; top: 149px; width: 208px; height: 329px; }
.m2-cs__board::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 16px solid transparent;
  border-image: url("../img/ui/charsel/thinboard.webp") 16 fill / 16px / 0 repeat;
  pointer-events: none;
}
/* Oyunda pano koyu sahne üzerinde durur; parşömen açık olduğundan iç alan ek olarak karartılır.
   Orijinal %45 siyah için --cs-board-dim: 0 verin. */
.m2-cs__board::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 6px;
  background: rgba(0, 0, 0, var(--cs-board-dim, 0.3));
  pointer-events: none;
}
.m2-cs__board > * { position: absolute; z-index: 1; }
.m2-cs__board > [data-cs-stats] { position: static; }
/* text_board: bar 189x122 at (8,10); çizgiler sol/üst 0x2A2521, sağ/alt 0xAAA6A1 */
.m2-cs__text {
  position: absolute;
  left: 8px; top: 10px; width: 189px; height: 122px;
  box-sizing: border-box;
  background: #000;
  border: 1px solid;
  border-color: #2a2521 #aaa6a1 #aaa6a1 #2a2521;
}
.m2-cs__desc {                               /* event metni: (x+7, y+7), 5 görünür satır, beyaz */
  position: absolute;
  left: 6px; top: 6px; width: 175px; height: 80px;
  margin: 0;
  overflow: hidden;
  color: #fff;
  white-space: pre;
  line-height: 16px;
}
.m2-cs__desc .m2-cs__weapon { color: #ffd76a; }

/* butonlar: görsel 3 durumlu (01 normal, 02 üzerinde, 03 basılı/seçili), metin ortalı */
.m2-cs__btn {
  position: absolute;
  height: 21px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: url("../img/ui/charsel/btn_middle_01.webp") no-repeat 0 0;
  color: #c7c7c7;
  font: inherit;
  line-height: 21px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: none;
  transition: none;
}
.m2-cs__btn:hover { filter: none; }
.m2-cs__btn:active, .m2-cs__btn.is-on { transform: none; }
.m2-cs__btn--small  { width: 43px; background-image: url("../img/ui/charsel/btn_small_01.webp"); }
.m2-cs__btn--small:hover  { background-image: url("../img/ui/charsel/btn_small_02.webp"); }
.m2-cs__btn--small:active { background-image: url("../img/ui/charsel/btn_small_03.webp"); }
.m2-cs__btn--middle { width: 61px; background-image: url("../img/ui/charsel/btn_middle_01.webp"); }
.m2-cs__btn--middle:hover  { background-image: url("../img/ui/charsel/btn_middle_02.webp"); }
.m2-cs__btn--middle:active, .m2-cs__btn--middle.is-on { background-image: url("../img/ui/charsel/btn_middle_03.webp"); color: #fff; }
.m2-cs__btn--large  { width: 88px; background-image: url("../img/ui/charsel/btn_large_01.webp"); }
.m2-cs__btn--large:hover  { background-image: url("../img/ui/charsel/btn_large_02.webp"); }
.m2-cs__btn--large:active { background-image: url("../img/ui/charsel/btn_large_03.webp"); }
.m2-cs__btn:disabled { opacity: 0.5; cursor: default; }
.m2-cs__btn:focus-visible { outline: 1px dotted #fff; outline-offset: -3px; }
/* text_board içi: Önceki (95,95) / Sonraki (140,95) */
.m2-cs__prev { left: 95px; top: 95px; }
.m2-cs__next { left: 140px; top: 95px; }

/* istatistik satırları: y = 138 + 19*i  (hth/int/str/dex) */
.m2-cs__stat { position: absolute; left: 0; top: calc(138px + 19px * var(--i, 0)); width: 208px; height: 19px; }
.m2-cs__stat-l { position: absolute; left: 15px; top: -1px; }
/* gauge 120x8 at (15+30, y+4): yuva 3 dilim (16px uçlar), dolgu x=12'den başlar, en fazla 96px */
.m2-cs__gauge {
  position: absolute;
  left: 45px; top: 4px; width: 120px; height: 8px;
  box-sizing: border-box;
  border: 0 solid transparent;
  border-width: 0 16px;
  border-image: url("../img/ui/charsel/gauge_slot.webp") 0 16 fill / 0 16px / 0 stretch;
}
.m2-cs__gauge > i {
  position: absolute;
  left: -4px; top: 0;                          /* 12 - 16 (kenarlık) */
  height: 8px;
  width: calc(96px * var(--pct, 0));
  background: url("../img/ui/charsel/gauge_red.webp") repeat-x 0 0;
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.m2-cs__gauge[data-color="pink"]   > i { background-image: url("../img/ui/charsel/gauge_pink.webp"); }
.m2-cs__gauge[data-color="purple"] > i { background-image: url("../img/ui/charsel/gauge_purple.webp"); }
.m2-cs__gauge[data-color="blue"]   > i { background-image: url("../img/ui/charsel/gauge_blue.webp"); }
/* slotbar (Bar3D) 24x16 at (15+157, y-1): orta siyah, sol/üst 0.2 gri, sağ/alt 0.7 gri */
.m2-cs__val {
  position: absolute;
  left: 172px; top: -1px; width: 24px; height: 16px;
  box-sizing: border-box;
  background: #000;
  box-shadow: inset 1px 1px 0 #333, inset -1px -1px 0 #b3b3b3;
  border: 0;
  border-radius: 0;
  color: #c7c7c7;
  line-height: 15px;
  text-align: center;
  font-weight: 400;
  padding: 0;
}

/* satır etiketleri: metin x=43'e ortalanır (text_horizontal_align center) */
.m2-cs__lbl { position: absolute; left: 43px; transform: translateX(-50%); white-space: nowrap; }
.m2-cs__lbl--name   { top: 217px; }
.m2-cs__lbl--gender { top: 246px; }
.m2-cs__lbl--shape  { top: 269px; }
/* character_name_slot 115x18 at (82,216); editline 90x20 at (85,218) */
.m2-cs__slot { position: absolute; left: 82px; top: 216px; width: 115px; height: 18px; background: url("../img/ui/charsel/slot_name.webp") no-repeat; }
.m2-cs__input {
  position: absolute;
  left: 85px; top: 217px; width: 90px; height: 16px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  line-height: 16px;
  caret-color: #fff;
  outline: none;
}
/* radio_button'lar: cinsiyet (79|139, 247), biçim (79|139, 268) */
.m2-cs__opts { position: absolute; left: 0; width: 208px; height: 21px; }
.m2-cs__opts--gender { top: 247px; }
.m2-cs__opts--shape  { top: 268px; }
.m2-cs__opts .m2-cs__btn { left: calc(79px + 60px * var(--i, 0)); top: 0; }
/* create (11,294) / cancel (109,294) */
.m2-cs__create { left: 11px; top: 294px; }
.m2-cs__cancel { left: 109px; top: 294px; }
.m2-cs [hidden] { display: none !important; }

/* sınıf değiştirme okları (dragon_left/right_button, 160x36) — sahnenin altında, orijinaldeki gibi */
.m2-cs__arrows {
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  zoom: var(--cs-zoom, 1);
}
.m2-cs__arrow {
  width: 160px; height: 36px;
  padding: 0; border: 0;
  background: url("../img/ui/charsel/arrow_left_01.webp") no-repeat;
  cursor: pointer;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
}
.m2-cs__arrow:hover  { background-image: url("../img/ui/charsel/arrow_left_02.webp"); }
.m2-cs__arrow:active { background-image: url("../img/ui/charsel/arrow_left_03.webp"); }
.m2-cs__arrow--right        { background-image: url("../img/ui/charsel/arrow_right_01.webp"); }
.m2-cs__arrow--right:hover  { background-image: url("../img/ui/charsel/arrow_right_02.webp"); }
.m2-cs__arrow--right:active { background-image: url("../img/ui/charsel/arrow_right_03.webp"); }

/* ---------------- kanvas ---------------- */
.m2-cs__stage { position: relative; min-height: 0; border-radius: 6px; overflow: hidden; }
.m2-cs__stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  cursor: grab;
  touch-action: none;       /* döndürme + iki parmakla yakınlaştırma */
  outline: none;
}
.m2-cs__stage canvas:active { cursor: grabbing; }
.m2-cs__ground {
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: 46%;
  height: 8%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.12) 55%, transparent 72%);
  pointer-events: none;
}
/* kamera araç çubuğu: 360° döndür, yakınlaştır, otomatik dönüş, sıfırla */
.m2-cs__tools {
  position: absolute;
  right: 2%;
  top: 2%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.m2-cs__tool {
  width: clamp(20px, 3cqw, 30px);
  height: clamp(20px, 3cqw, 30px);
  border-radius: 4px;
  border: 1px solid rgba(201, 162, 74, 0.7);
  background: linear-gradient(180deg, rgba(60, 10, 12, 0.92), rgba(20, 4, 5, 0.95));
  color: #fef6aa;
  font: 700 clamp(11px, 1.6cqw, 16px)/1 "Segoe UI Symbol", "Readex Pro", sans-serif;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: filter 0.15s, transform 0.1s;
}
.m2-cs__tool:hover { filter: brightness(1.3); }
.m2-cs__tool:active { transform: scale(0.94); }
.m2-cs__tool.is-on { background: linear-gradient(180deg, #c0161d, #6a0a0e); border-color: #f1d98a; }
.m2-cs__loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(2px);
  color: #3a0b0d;
  font-family: "Cinzel", serif;
  font-weight: 700;
  letter-spacing: 0.15em;
  font-size: clamp(9px, 1.4cqw, 14px);
}
.m2-cs__loading[hidden] { display: none; }
.m2-cs__loading::before {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  margin-top: -50px;
  border-radius: 50%;
  border: 3px solid rgba(160, 20, 25, 0.25);
  border-top-color: #a3121b;
  animation: m2-spin 0.9s linear infinite;
}
@keyframes m2-spin { to { transform: rotate(360deg); } }

/* Oluştur bekleme durumu / boş isim uyarısı */
.m2-cs__btn.is-disabled { pointer-events: none; opacity: 0.6; }
.m2-cs__win.is-shake .m2-cs__slot, .m2-cs__win.is-shake .m2-cs__input { animation: m2-shake 0.4s; }
@keyframes m2-shake { 0%, 100% { transform: none; } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---------------- yedek (WebGL yok / JS kapalı) ---------------- */
.m2-cs__fallback {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 40%;
  text-align: center;
  color: #3a0b0d;
  font-family: "Cinzel", serif;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: clamp(10px, 1.8cqw, 16px);
}

/* ---------------- mobil: görselin üst/alt bantları dilim olarak kalır, arayüz akışa geçer ---------------- */
@media (max-width: 767px) {
  .m2-gallery .m2-cs .m2-cs__bg { display: none; }   /* .m2-gallery img kuralını geçmek için */
  .m2-cs__cap {
    display: block;
    width: 100%;
    aspect-ratio: 900 / 120;
    background: url("../img/game/head2.png") no-repeat center top / 100% auto;
  }
  .m2-cs__cap--bottom { aspect-ratio: 900 / 120; background-position: center bottom; }
  .m2-cs__ui {
    position: relative;
    left: auto; right: auto; top: auto; height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 10px;
    padding: 12px 4.5%;
    background:
      linear-gradient(90deg, #5b0d12 0 6px, transparent 6px calc(100% - 6px), #5b0d12 calc(100% - 6px)),
      radial-gradient(120% 80% at 50% 0%, #f2f0ec, #d9d6d0);
  }
  .m2-cs__win { grid-row: auto; order: 2; justify-self: center; }
  .m2-cs__stage { order: 1; aspect-ratio: 4 / 5; }
  .m2-cs__arrows { zoom: calc(var(--cs-zoom, 1) * 0.55); bottom: 2%; }   /* oklar mobilde küçük */
  .m2-cs__stage canvas { touch-action: pan-y; }   /* sayfa kaydırması korunur; yakınlaştırma butonlarla */
  .m2-cs__tool { width: 30px; height: 30px; font-size: 15px; }
}
@media (min-width: 768px) { .m2-cs__cap { display: none; } }
