@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('assets/fonts/PatrickHand-v25.ttf') format('truetype');
}

html[data-malzeme="kursunkalem"] {
  --mavi: #2b4a9f;
  --kirmizi: #c0392b;
  --kursun: #4a4a4a;
  --soluk: #69645c;
  --sq: 24px;
  --tahta: clamp(300px, calc(100svh - 400px), 560px);
  scrollbar-color: #9a8d77 #e5dece;
}

html[data-malzeme="kursunkalem"] body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: calc(64px + env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-right, 0px)) max(40px, env(safe-area-inset-bottom, 0px)) max(24px, env(safe-area-inset-left, 0px));
  min-height: 100svh;
}

::selection { background: #d3dded; color: #243b77; }
button { -webkit-tap-highlight-color: transparent; }

/* Mangala ve Tavla ile aynı: düz duran yatay yaprak, altında iki yaprak ve uzun gölge. */
html[data-malzeme="kursunkalem"] .defter {
  position: relative;
  width: 100%;
  --kagit-egimi: -.6deg;
  max-width: clamp(940px, calc(var(--tahta) + 480px), 1040px);
  margin: 0;
  transform: none;
  will-change: auto;
  animation: none;
  isolation: isolate;
}
html[data-malzeme="kursunkalem"] .defter::before,
html[data-malzeme="kursunkalem"] .defter::after { content: none; }

.defterde-donus { position: absolute; top: -52px; left: 16px; display: inline-flex; align-items: center; min-height: 44px; font: 18px/1 'Patrick Hand', cursive; color: #393732; text-decoration: none; text-underline-offset: 4px; touch-action: manipulation; }
.defterde-donus:hover { color: var(--mavi); text-decoration: underline; }
.defterde-donus:focus-visible { outline: 2px dashed var(--mavi); outline-offset: 3px; }

html[data-malzeme="kursunkalem"] .sayfa {
  --marj-x: 36px;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 26px 36px 18px 60px;
  background: none;
  box-shadow: none;
}
.sayfa::before, .sayfa::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: url("kit/gren.png") #f7f4eb;
}
/* Amiral Battı gibi: kâğıt katmanları sola yatar, yazı, tahta ve dokunma katmanı düz kalır. */
.sayfa::before {
  z-index: -3; transform: translate(5px, 4px) rotate(calc(var(--kagit-egimi) + .7deg));
  background-color: #efebdf;
  box-shadow: 16px 28px 40px -6px rgba(58, 36, 16, .44);
}
.sayfa::after {
  z-index: -2; transform: translate(-3px, 7px) rotate(calc(var(--kagit-egimi) - .5deg));
  background-color: #ece6d7;
  box-shadow: 0 1px 2px rgba(40, 24, 10, .25);
}
.kagit-yuzeyi {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  transform: rotate(var(--kagit-egimi));
  background-color: var(--kagit);
  background-image:
    linear-gradient(to right, transparent var(--marj-x), var(--marj) var(--marj-x), var(--marj) calc(var(--marj-x) + 1px), transparent calc(var(--marj-x) + 1px)),
    linear-gradient(to right, var(--izgara) 1px, transparent 1px),
    linear-gradient(to bottom, var(--izgara) 1px, transparent 1px),
    url("kit/gren.png");
  background-size: 100% 100%, var(--sq) var(--sq), var(--sq) var(--sq), 256px 256px;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .85);
}

/* Üst satır tahtayla aynı sütunlara oturur: başlık solda, skor ve sıra tahtanın tam üstünde. */
.ust { display: grid; grid-template-columns: minmax(96px, 1fr) var(--tahta) minmax(96px, 1fr); align-items: start; column-gap: 36px; }
h1 { grid-column: 1 / 3; grid-row: 1; justify-self: start; margin: 8px 0 0; color: var(--kursun); font: 400 clamp(40px, 3.3vw, 46px)/1.15 'Kalam', cursive; letter-spacing: -.01em; white-space: nowrap; }
.baslik-yazi { position: relative; display: inline-block; padding-bottom: 4px; }
h1 svg { position: absolute; left: -3%; bottom: -6px; width: 106%; height: 13px; overflow: visible; }
.durum { grid-column: 2; grid-row: 1; text-align: center; min-width: 0; }
.skor { display: flex; flex-direction: column; align-items: center; margin: 0; }
.skor-etiket { font-size: 16px; line-height: 1.15; color: var(--soluk); }
.skor-satir { display: flex; align-items: baseline; justify-content: center; gap: 10px; font-size: 24px; line-height: 1.3; white-space: nowrap; }
.skor-oyuncu { display: inline-flex; align-items: center; gap: .35em; }
.skor-sayi { font-weight: 400; font-variant-numeric: tabular-nums; }
.skor-tire { color: var(--soluk); }
.nokta { width: .5em; height: .55em; background: currentColor; border-radius: 46% 51% 45% 53%; transform: rotate(-11deg); opacity: .85; }
.mavi { color: var(--mavi); }
.kirmizi { color: var(--kirmizi); }
.sira { margin: 6px 0 0; color: var(--mavi); font-size: 34px; line-height: 1.25; }
.sira[data-takim="kirmizi"] { color: var(--kirmizi); }
.sira.sonuc { text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 1px; }
.kenar-notu { margin: 2px 0 0; min-height: 1.45em; font-size: 19px; line-height: 1.45; color: var(--soluk); text-wrap: balance; }

/* Tahta ortada; iki yanda oyuncu ve aldığı taşlar. */
.oyun-alani { display: grid; grid-template-columns: minmax(96px, 1fr) var(--tahta) minmax(96px, 1fr); column-gap: 36px; align-items: stretch; margin-block: 8px 30px; }
.oyun-alani[data-cevrik="true"] .yan.kirmizi { order: 3; }
.oyun-alani[data-cevrik="true"] .yan.mavi { order: -1; }
.tahta { position: relative; align-self: start; width: var(--tahta); aspect-ratio: 1; }
#tahta-cizim, #hucreler { position: absolute; inset: 0; width: 100%; height: 100%; }
#tahta-cizim { overflow: visible; pointer-events: none; }
#hucreler { display: grid; grid-template-rows: repeat(8, 1fr); }
.tahta-satir { display: grid; grid-template-columns: repeat(8, 1fr); min-height: 0; }
.hucre { background: none; border: 0; padding: 0; min-width: 0; min-height: 0; color: var(--kursun); cursor: default; touch-action: manipulation; }
.hucre[data-secilebilir="true"], .hucre[data-hedef="true"] { cursor: pointer; }
.hucre:focus { outline: none; }
.hucre:focus-visible { outline: 2px dashed rgba(43, 74, 159, .7); outline-offset: -4px; }
.satir-adlari { position: absolute; right: calc(100% + 10px); top: 0; bottom: 0; display: grid; grid-template-rows: repeat(8, 1fr); font-size: 18px; color: var(--soluk); }
.satir-adlari span { align-self: center; }
.sutun-adlari { position: absolute; top: calc(100% + 4px); left: 0; right: 0; display: grid; grid-template-columns: repeat(8, 1fr); text-align: center; font-size: 18px; line-height: 1.2; color: var(--soluk); }

.yan { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; min-width: 0; text-align: center; }
.yan-ad { margin-top: -4px; font-size: 22px; line-height: 1.3; }
.oyuncu-tasi { width: 44px; height: 48px; }
.yan-etiket { margin-top: 10px; font-size: 16px; line-height: 1.2; color: var(--soluk); }
.alinanlar { width: 76px; height: 167px; overflow: visible; }
.dama-notu { margin: auto 0 0; color: var(--soluk); }
.yan.kirmizi .dama-notu, .oyun-alani[data-cevrik="true"] .yan.mavi .dama-notu { display: none; }
.oyun-alani[data-cevrik="true"] .yan.kirmizi .dama-notu { display: block; }
.dama-notu svg { width: 46px; height: 50px; }
.dama-notu figcaption { font-size: 16px; line-height: 1.2; }

/* Alt satır: solda oyun modu, sağda altı çizili komutlar ve hoparlör. */
.alt { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-top: 2px; }
.mod { min-height: 44px; padding: 4px 0; border: 0; background: none; font: inherit; font-size: 17px; color: var(--soluk); text-align: left; white-space: nowrap; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 5px; touch-action: manipulation; }
.mod:hover { color: var(--mavi); }
.mod:focus-visible { outline: 2px dashed var(--mavi); outline-offset: 3px; }
.komutlar { display: flex; align-items: center; justify-content: flex-end; gap: 6px 22px; }
html[data-malzeme="kursunkalem"] .dugme {
  min-height: 44px;
  padding: 5px 4px 10px;
  font-size: 23px;
  line-height: 1.25;
  color: var(--kursun);
}
.dugme .yazi { white-space: nowrap; }
.dugme svg { pointer-events: none; }
html[data-malzeme="kursunkalem"] .dugme[disabled] { color: #8a8783; opacity: 1; cursor: default; }
html[data-malzeme="kursunkalem"] .dugme:hover:not([disabled]) { color: #1b367c; }
html[data-malzeme="kursunkalem"] .dugme:focus-visible { outline: 2px dashed var(--mavi); outline-offset: 3px; }
html[data-malzeme="kursunkalem"] .dugme.ses { display: inline-flex; flex-direction: column; align-items: center; min-width: 44px; padding: 0 2px; }
.ses svg { display: block; width: 34px; height: 34px; overflow: visible; }
.ses .yazi { font-size: 12px; line-height: 1; color: var(--soluk); }
#ses-simge .ses-acik, #ses-simge.acik .ses-kapali { display: none; }
#ses-simge.acik .ses-acik { display: inline; }

.nasil-not h2 { font-size: 30px; font-weight: 400; color: var(--kursun); margin: 0 0 8px; }
.kural-ozeti { display: flex; align-items: flex-start; gap: 24px; }
.kural-ozeti p { font-size: 20px; line-height: 1.5; max-width: 54ch; margin: 0 0 12px; }
.kural-ozeti figure { margin: 0; flex: 0 0 130px; text-align: center; color: var(--mavi); }
.kural-ozeti svg { width: 85px; height: 95px; }
.kural-ozeti figcaption { font-size: 19px; line-height: 1.35; }
.ornekler { max-width: 420px; margin: 16px 0; font-size: 21px; }
.ornekler p { color: var(--soluk); font-size: 18px; }
.ornekler > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px dashed #69645c55; }
.ornekler .dugme, .ogretici-bant .dugme { text-decoration: underline; text-underline-offset: 5px; }
.ogretici-bant { padding: 0 0 12px; color: var(--kursun); font-size: 20px; }
.ogretici-bant p { margin: 0 0 3px; }
.ogretici-bant .dugme { margin-right: 18px; }
.ogretici-bant[hidden] { display: none; }

dialog { width: 460px; max-width: calc(100% - 24px); max-height: calc(100svh - 32px); overflow: auto; padding: 28px; border: 0; color: var(--kursun); background: url("kit/gren.png") #fbf9f2; box-shadow: 2px 4px 12px #362e241c; }
dialog::backdrop { background: #fbf9f299; }
dialog h2 { color: var(--kursun); font-weight: 400; font-size: 29px; line-height: 1.3; margin: 0 0 18px; }
dialog p { font-size: 19px; line-height: 1.45; }
.ayar-grubu { display: flow-root; border: 0; padding: 0; margin: 0 0 8px; min-width: 0; }
.ayar-grubu[hidden] { display: none; }
.ayar-grubu legend { float: left; width: 92px; min-height: 44px; margin-right: 12px; padding: 11px 0 0; color: var(--soluk); font-size: 16px; line-height: 1.4; }
.ayar-secenekleri { display: flex; flex-wrap: wrap; gap: 0 16px; }
.ayar-secenekleri label { position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; font-size: 21px; cursor: pointer; }
.ayar-secenekleri input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.ayar-secenekleri input:checked + span { color: var(--mavi); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 6px; }
.ayar-secenekleri label:hover { color: var(--mavi); }
.ayar-secenekleri label:focus-within { outline: 2px dashed var(--mavi); outline-offset: 2px; }
dialog .secenek { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; min-height: 44px; font-size: 18px; cursor: pointer; }
dialog input[type="checkbox"] { accent-color: var(--mavi); width: 22px; height: 22px; flex: 0 0 auto; }
dialog .ayar-notu { color: var(--soluk); font-size: 16px; }
.dialog-komutlar { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px; }
html[data-malzeme="kursunkalem"] dialog .dugme { font-size: 20px; text-decoration: underline; text-underline-offset: 5px; }
html[data-malzeme="kursunkalem"] :is(#ayar-form button[type="submit"], #sonuc-yeni) { color: var(--kirmizi); }
dialog .teklif-dugmesi { margin-top: 16px; }
dialog input[type="checkbox"]:focus-visible { outline: 2px dashed var(--mavi); outline-offset: 3px; }

dialog.nasil-not { width: 680px; padding: 0; user-select: text; overscroll-behavior: contain; }
.nasil-ust { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 28px 12px; background: url("kit/gren.png") var(--kagit); }
.nasil-ust h2 { margin: 0; }
.nasil-ust h2:focus-visible { outline: 2px dashed var(--mavi); outline-offset: 3px; }
.nasil-ust .dugme { flex: 0 0 auto; }
.nasil-icerik { padding: 0 28px 24px; }
.nasil-not .kural-ozeti figure { flex-basis: 90px; }
.nasil-not .ornekler { max-width: none; margin-bottom: 0; }

.sonuc-notu { text-align: center; padding: 28px; }
.sonuc-taslar { display: flex; justify-content: center; gap: 10px; margin-bottom: 10px; }
.sonuc-taslar svg { width: 72px; height: 78px; }
dialog.sonuc-notu h2 { margin: 0; font-size: clamp(32px, 6vw, 42px); line-height: 1.2; text-wrap: balance; }
.sonuc-notu[data-takim="kirmizi"] h2 { color: var(--kirmizi); }
.sonuc-notu[data-takim="mavi"] h2 { color: var(--mavi); }
.sonuc-notu[data-durum="kayip"] h2 { color: var(--kursun); }
.sonuc-alt-cizgi { width: 75%; height: 12px; display: block; margin: 5px auto 18px; }
.sonuc-notu p { margin: 0 0 12px; }
.sonuc-notu .sonuc-davet { color: var(--soluk); font-size: 18px; margin-bottom: 24px; }
.sonuc-notu .dialog-komutlar { justify-content: center; gap: 10px 24px; }
.sonuc-notu[open][data-hareket="tam"] { animation: sonuc-kagit .32s cubic-bezier(.16, 1, .3, 1); }
@keyframes sonuc-kagit {
  from { transform: rotate(-1.2deg) scale(1.025); }
  to { transform: rotate(0) scale(1); }
}

@media (min-width: 1024px) and (max-height: 820px) {
  html[data-malzeme="kursunkalem"] body { padding-top: calc(56px + env(safe-area-inset-top, 0px)); padding-bottom: 24px; }
  html[data-malzeme="kursunkalem"] { --tahta: clamp(300px, calc(100svh - 350px), 560px); }
  html[data-malzeme="kursunkalem"] .sayfa { gap: 10px; padding-top: 20px; padding-bottom: 10px; }
  .sira { font-size: 30px; margin-top: 2px; }
  .oyun-alani { margin-bottom: 18px; }
}

/* Tablet: tahta genişler, yan sütunlar daralır. */
@media (max-width: 999px) {
  html[data-malzeme="kursunkalem"] { --tahta: clamp(260px, min(calc(100vw - 370px), calc(100svh - 330px)), 560px); }
  html[data-malzeme="kursunkalem"] .defter { max-width: 760px; }
  .yan-ad { font-size: 19px; }
  html[data-malzeme="kursunkalem"] .sayfa { padding-left: 52px; }
  .ust { grid-template-columns: minmax(0, 1fr); row-gap: 10px; }
  h1, .durum { grid-column: 1; grid-row: auto; }
  h1 { margin-top: 0; }
  .durum { grid-column: 1 / -1; }
  .oyun-alani { grid-template-columns: minmax(84px, 1fr) var(--tahta) minmax(84px, 1fr); column-gap: 30px; }
  .alinanlar { width: 60px; height: 132px; }
  .alt { flex-direction: column-reverse; gap: 6px; }
  .komutlar { justify-content: center; flex-wrap: wrap; }
}

/* Telefon: tek sütun; oyuncular üstte skor satırında, alınanlar gizli. */
@media (max-width: 699px) {
  html[data-malzeme="kursunkalem"] { --sq: 20px; --tahta: calc(100vw - 72px); }
  html[data-malzeme="kursunkalem"] body { padding: calc(52px + env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px)); justify-content: flex-start; }
  html[data-malzeme="kursunkalem"] .sayfa { --marj-x: 22px; gap: 12px; padding: 18px 14px 12px 38px; }
  .defterde-donus { top: -48px; left: 4px; }
  html[data-malzeme="kursunkalem"] .defter { --kagit-egimi: -.4deg; }
  h1 { font-size: clamp(36px, 10vw, 46px); }
  .skor-satir { font-size: 21px; gap: 8px; }
  .skor-etiket { font-size: 14px; }
  .sira { font-size: 27px; }
  .kenar-notu { font-size: 17px; }
  .oyun-alani { grid-template-columns: var(--tahta); justify-content: start; margin-bottom: 26px; }
  .yan { display: none; }
  .satir-adlari { right: calc(100% + 5px); font-size: 14px; }
  .sutun-adlari { font-size: 15px; }
  .komutlar { display: grid; grid-template-columns: repeat(3, max-content); justify-content: space-between; column-gap: 8px; row-gap: 2px; width: 100%; }
  html[data-malzeme="kursunkalem"] .dugme { font-size: 20px; padding: 6px 3px 9px; }
  html[data-malzeme="kursunkalem"] .dugme.ses { flex-direction: row; gap: 4px; }
  .ses svg { width: 28px; height: 28px; }
  .ses .yazi { font-size: 15px; }
  .mod { text-align: center; white-space: normal; }
}

@media (max-width: 419px) {
  html[data-malzeme="kursunkalem"] { --tahta: calc(100vw - 41px); }
  html[data-malzeme="kursunkalem"] body { padding-left: max(7px, env(safe-area-inset-left, 0px)); padding-right: max(7px, env(safe-area-inset-right, 0px)); }
  html[data-malzeme="kursunkalem"] .sayfa { --marj-x: 11px; padding: 16px 9px 12px 18px; }
  .satir-adlari { right: calc(100% + 4px); font-size: 13px; }
  .ust { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: clamp(32px, 10vw, 40px); }
  .skor-satir { font-size: 18px; gap: 6px; }
  .sira { font-size: 25px; }
  .kenar-notu { font-size: 16px; }
  .komutlar { display: flex; flex-wrap: wrap; justify-content: center; column-gap: 14px; }
  html[data-malzeme="kursunkalem"] .dugme { font-size: 19px; }
}

@media (max-width: 520px) {
  dialog { padding: 18px; }
  dialog h2 { font-size: 26px; margin-bottom: 12px; }
  .ayar-secenekleri { column-gap: 14px; }
  .ayar-secenekleri label { font-size: 20px; }
  .ayar-grubu legend { width: 80px; margin-right: 10px; }
  .secim-isareti { opacity: .95; }
  .secim-isareti path { vector-effect: non-scaling-stroke; stroke: #5a564d; stroke-width: 1.4px; }
  .nasil-ust { padding: 16px 18px 10px; gap: 12px; }
  .nasil-icerik { padding: 0 18px 18px; }
  .nasil-not h2 { font-size: 26px; }
  .kural-ozeti { display: block; }
  .kural-ozeti p { font-size: 18px; }
  .kural-ozeti figure { display: flex; justify-content: center; align-items: center; gap: 12px; }
  .kural-ozeti svg { width: 68px; height: 78px; }
  .kural-ozeti figcaption { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  body { background: white; }
  .defterde-donus, .sayfa::before, .sayfa::after { display: none; }
}
