:root {
  --zemin: #145442;
  --koyu: #0d3b2f;
  --kutu: rgba(0, 0, 0, 0.22);
  --yazi: #f4f7f1;
  --soluk: #c3d6cc;
  --vurgu: #f4b63c;
  --vurgu-koyu: #d99a1c;
  --fildisi: #fbf7ec;
  --nokta: #1f1d1a;
  --kirmizi: #c2362c;
  --sure: 650ms;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--yazi);
  background: radial-gradient(ellipse at 50% 30%, #1b6650 0%, var(--zemin) 55%, #0f4637 100%) fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #ffe08a; outline-offset: 2px; }
.gizli {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
h2 { margin: 0; font-size: 0.95rem; }

.sekmeler { display: flex; gap: 4px; padding: 6px 8px 0; background: var(--koyu); }
.sekme {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 10px 10px 0 0;
  min-height: 40px;
  padding: 0.45rem 0.3rem;
  background: transparent;
  color: var(--soluk);
  font-weight: 700;
  white-space: nowrap;
}
.sekme[aria-selected="true"] { background: var(--zemin); color: var(--yazi); }
.sekme:focus-visible { outline-offset: -3px; }

main { flex: 1; display: flex; flex-direction: column; }
.panel { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 10px; }

.dugme {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 0.45rem 0.9rem;
  background: rgba(255, 255, 255, 0.14);
  color: var(--yazi);
  font-weight: 700;
  white-space: nowrap;
  touch-action: manipulation;
}
.dugme:hover { background: rgba(255, 255, 255, 0.22); }
.dugme--ana { background: var(--vurgu); color: #2b2006; }
.dugme--ana:hover { background: #ffc552; }
.dugme--buyuk { min-height: 54px; font-size: 1.2rem; width: 100%; box-shadow: 0 4px 0 var(--vurgu-koyu); }
.dugme--buyuk:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--vurgu-koyu); }
.dugme--kucuk { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.dugme--secim[aria-pressed="true"] { background: var(--fildisi); color: var(--koyu); }
.dugme:disabled { opacity: 0.5; cursor: default; }

.kutu { background: var(--kutu); border-radius: 14px; padding: 10px 12px; }
.kutu-ust { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Zar */
.sol, .sag { display: flex; flex-direction: column; gap: 10px; }
.zar-ayar { display: flex; gap: 8px; align-items: center; }
.adetler { display: flex; flex: 1; gap: 4px; background: var(--kutu); padding: 3px; border-radius: 12px; }
.adet {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--yazi);
  font-weight: 800;
  font-size: 1.05rem;
}
.adet[aria-pressed="true"] { background: var(--fildisi); color: var(--koyu); }
.adet:disabled { opacity: 0.35; cursor: default; }

.sahne {
  --b: 84px;
  --ara: 12px;
  min-height: 150px;
  width: 100%;
  max-width: calc(var(--k, 2) * var(--b) + (var(--k, 2) - 1) * var(--ara) + 12px);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: var(--ara);
  padding: 6px;
}
.zar {
  width: var(--b);
  height: var(--b);
  border-radius: 18%;
  background: var(--fildisi);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.13), 0 5px 10px rgba(0, 0, 0, 0.3);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: calc(var(--b) * 0.13);
}
.sahne[data-n="1"], .sahne[data-n="2"] { --b: 104px; }
.sahne[data-n="5"], .sahne[data-n="6"] { --b: 78px; }
.zar i {
  width: 76%;
  height: 76%;
  margin: auto;
  border-radius: 50%;
  background: var(--nokta);
  visibility: hidden;
}
.tavla-modu .zar i { background: var(--nokta); }
.tavla-modu .zar[data-d="1"] i:nth-child(5) { background: var(--kirmizi); }
/* 1-9 konumları: 1 2 3 / 4 5 6 / 7 8 9 */
.zar[data-d="1"] i:nth-child(5),
.zar[data-d="2"] i:is(:nth-child(3), :nth-child(7)),
.zar[data-d="3"] i:is(:nth-child(3), :nth-child(5), :nth-child(7)),
.zar[data-d="4"] i:is(:nth-child(1), :nth-child(3), :nth-child(7), :nth-child(9)),
.zar[data-d="5"] i:is(:nth-child(1), :nth-child(3), :nth-child(5), :nth-child(7), :nth-child(9)),
.zar[data-d="6"] i:is(:nth-child(1), :nth-child(3), :nth-child(4), :nth-child(6), :nth-child(7), :nth-child(9)) {
  visibility: visible;
}
.zar.donuyor { animation: yuvarlan var(--sure) cubic-bezier(.25,.8,.35,1); }
.zar.donuyor:nth-child(2n) { animation-direction: reverse; }
@keyframes yuvarlan {
  0% { transform: translateY(-14px) rotate(-200deg) scale(0.8); }
  60% { transform: translateY(4px) rotate(20deg) scale(1.04); }
  100% { transform: none; }
}

.sonuc { text-align: center; min-height: 3.6rem; }
.sonuc p { margin: 0; }
.toplam { font-size: 1.05rem; color: var(--soluk); }
.toplam b { font-size: 2rem; color: var(--yazi); font-variant-numeric: tabular-nums; margin-left: 0.2rem; }
.tavla-adi { font-size: 1.15rem; font-weight: 800; color: var(--vurgu); min-height: 1.4em; }
.tavla-adi small { font-weight: 600; color: var(--soluk); font-size: 0.85rem; }

.ist-ozet { margin: 4px 0 6px; font-size: 0.85rem; color: var(--soluk); }
.siklik { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.siklik th { text-align: left; font-weight: 600; color: var(--soluk); font-size: 0.75rem; padding: 0 4px 2px; }
.siklik td { padding: 2px 4px; font-variant-numeric: tabular-nums; }
.siklik td:first-child { width: 2.2rem; font-weight: 800; }
.siklik td:nth-child(2), .siklik th:nth-child(2) { width: 3.2rem; text-align: right; }
.cubuk { display: flex; align-items: center; gap: 6px; }
.cubuk span { display: block; height: 10px; border-radius: 5px; background: var(--vurgu); min-width: 2px; }
.cubuk small { color: var(--soluk); font-size: 0.75rem; white-space: nowrap; }
.gecmis { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.gecmis li {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.gecmis li:first-child { background: var(--fildisi); color: var(--koyu); font-weight: 700; }
.gecmis:empty::before { content: "Atış yok."; color: var(--soluk); font-size: 0.85rem; }

/* Yazı tura */
.panel-para { align-items: stretch; }
.para-sahne { display: grid; place-items: center; min-height: 170px; perspective: 700px; }
.para {
  width: 150px;
  height: 150px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0s;
}
.para-yuz {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: radial-gradient(circle at 50% 50%, #f7d774 0 58%, #e5b941 59% 64%, #f2cd5f 65% 100%);
  box-shadow: inset 0 0 0 6px #c99a26, 0 6px 14px rgba(0, 0, 0, 0.35);
  color: #5a4206;
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
}
.para-tura { transform: rotateY(180deg); }
.para-tura svg { width: 40px; height: 40px; fill: #8d6a12; }
.para-tura span { font-size: 1.2rem; }
.para.tura { transform: rotateY(180deg); }
.para.atiliyor-yazi { animation: para-yazi 900ms cubic-bezier(.2,.7,.3,1) both; }
.para.atiliyor-tura { animation: para-tura 900ms cubic-bezier(.2,.7,.3,1) both; }
@keyframes para-yazi { 0% { transform: translateY(0) rotateY(0); } 45% { transform: translateY(-40px) rotateY(1080deg); } 100% { transform: translateY(0) rotateY(1800deg); } }
@keyframes para-tura { 0% { transform: translateY(0) rotateY(0); } 45% { transform: translateY(-40px) rotateY(1080deg); } 100% { transform: translateY(0) rotateY(1980deg); } }
.para-sonuc { margin: 0; text-align: center; font-size: 1.25rem; font-weight: 800; min-height: 1.6em; }
.sayimlar { margin: 0; font-size: 1rem; }
.sayimlar b { font-variant-numeric: tabular-nums; }
.para-son { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.para-son li {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #e9c75c;
  color: #4b3705;
  font-weight: 900;
  font-size: 0.85rem;
}
.para-son li.t { background: rgba(255, 255, 255, 0.85); color: var(--koyu); }
.para-son:empty::before { content: "Atış yok."; color: var(--soluk); font-size: 0.85rem; }

/* Sayı seç */
.sayi-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; }
.alan { display: flex; flex-direction: column; gap: 3px; font-size: 0.8rem; font-weight: 700; color: var(--soluk); min-width: 0; }
.alan input {
  width: 100%;
  min-width: 0;
  height: 46px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  color: var(--yazi);
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.alan input[aria-invalid="true"] { border-color: #ff8a7a; }
.kutucuk { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; font-size: 0.95rem; }
.kutucuk input { width: 22px; height: 22px; margin: 0; accent-color: var(--vurgu); }
.sayi-form .dugme--buyuk { grid-column: 1 / -1; }
.hata { margin: 0; color: #ffb4a8; font-weight: 700; min-height: 0; }
.hata:empty { display: none; }
.sayi-sonuc { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 64px; align-items: center; }
.sayi-sonuc span {
  min-width: 64px;
  padding: 0.35rem 0.7rem;
  border-radius: 14px;
  background: var(--fildisi);
  color: var(--koyu);
  font-size: 2rem;
  font-weight: 900;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.sayi-sonuc.cok span { font-size: 1.15rem; min-width: 44px; padding: 0.25rem 0.5rem; border-radius: 10px; }
.sayi-sonuc .yeni { animation: belir 300ms ease-out both; }
@keyframes belir { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.sayi-gecmis { margin: 6px 0 0; padding-left: 1.3rem; font-size: 0.88rem; color: var(--soluk); }
.sayi-gecmis li { margin: 2px 0; overflow-wrap: anywhere; }
.sayi-gecmis:empty::before { content: "Henüz seçim yok."; margin-left: -1.3rem; }

/* Geniş ekran */
@media (min-width: 720px) {
  .panel { padding: 16px 20px; }
  .panel-zar { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; align-items: start; }
  .sahne { min-height: 270px; --ara: 18px; --b: 112px; }
  .sahne[data-n="1"], .sahne[data-n="2"] { --b: 150px; }
  .sahne[data-n="5"], .sahne[data-n="6"] { --b: 104px; }
  .toplam b { font-size: 2.6rem; }
  .panel-para, .panel-sayi { width: min(100%, 560px); margin: 0 auto; }
  .para-sahne { min-height: 260px; }
  .para { width: 200px; height: 200px; }
  .para-yuz { font-size: 2.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .zar.donuyor, .para.atiliyor-yazi, .para.atiliyor-tura, .sayi-sonuc .yeni { animation: none; }
}
