/* Kanasta — phone-first card table */

:root {
  --kece-1: #1f7149;
  --kece-2: #0c3a26;
  --yazi: #f4efe1;
  --soluk: rgba(244, 239, 225, 0.68);
  --altin: #e8c25a;
  --altin-koyu: #b8892a;
  --kart: #fffdf7;
  --kart-kenar: #d4ccba;
  --kirmizi: #c4261d;
  --siyah: #1d1d1f;
  --pano: #fbf7ec;
  --pano-yazi: #1f2421;
  --hata: #ffb4a8;
  --mini: 30px;
  /* Card sizes on the table. --el-w is the size of the cards in the hand, set by ekran.js
     (renderHand); the pile always uses it (Arman, 22 Nov: "yerdeki kağıtlar elindekiyle aynı boy"). */
  --el-w: 52px;
  --deste-w: 44px;      /* the stock */
  --kesilen-w: 44px;    /* the cut card, upright under the stock */
  --fi-w: 22px;         /* the fi piles, lying crosswise */
  color-scheme: dark;
}
@media (min-width: 420px) { :root { --mini: 34px; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* Card-table felt (çuha, Arman 22 Nov): a fine fuzzy grain (SVG noise, grey around 50%)
   laid over the green with "soft-light", so the grain only lightens/darkens the green a little. */
body {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='.55 .55 .55 0 -.325 .55 .55 .55 0 -.325 .55 .55 .55 0 -.325 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"),
    radial-gradient(120% 80% at 50% 35%, var(--kece-1) 0%, #145536 45%, var(--kece-2) 100%) fixed;
  background-blend-mode: soft-light, normal;
  background-color: var(--kece-2);
  color: var(--yazi);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

.uygulama {
  max-width: 560px;
  margin: 0 auto;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(44px, 1fr) auto minmax(60px, 1.4fr) auto auto auto;
  padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom);
}

/* ---------- header */
.ust { display: flex; align-items: center; gap: 8px; padding: 8px 2px 4px; }
.logo { font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: 19px; letter-spacing: .02em; color: var(--altin); }
.skor { flex: 1; display: flex; justify-content: flex-end; gap: 6px; font-size: 14px; }
.skor .oyuncu { padding: 3px 9px; border-radius: 999px; background: rgba(0,0,0,.22); white-space: nowrap; }
.skor .oyuncu.sira { background: var(--altin); color: #2a2208; font-weight: 700; }
.skor b { font-variant-numeric: tabular-nums; }
.baglanti { width: 8px; height: 8px; border-radius: 50%; background: #6fd08c; align-self: center; flex: none; }
.baglanti.koptu { background: #ff6b5b; }
.menu-dugme { background: rgba(0,0,0,.22); border: none; border-radius: 10px; width: 38px; height: 34px; font-size: 18px; }

/* ---------- opponent strip */
.rakip { display: flex; align-items: center; gap: 10px; padding: 4px 2px; min-height: 40px; }
.rakip .ad { font-weight: 700; }
.rakip .rozet { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.25); color: var(--soluk); white-space: nowrap; }
.rakip .rozet.iyi { background: rgba(232,194,90,.2); color: var(--altin); }
.rakip .son { margin-left: auto; font-size: 13px; color: var(--soluk); text-align: right; }
.rakip .son.yeni { color: var(--yazi); animation: parla 1.6s ease-out; }
.arkalar { display: flex; align-items: center; }
.arkalar .kart { --w: 18px; margin-left: -12px; }
.arkalar .kart:first-child { margin-left: 0; }
.arkalar .sayi { margin-left: 6px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- groups (melds) */
.gruplar {
  overflow-y: auto; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px 10px;
  padding: 6px 4px; border-radius: 12px; min-height: 0;
}
.benim-gruplarim { background: rgba(0,0,0,.12); }
.benim-gruplarim:empty { background: transparent; }
.gruplar .bos { color: var(--soluk); font-size: 13px; padding: 4px 2px; }
.grup {
  display: flex; flex-direction: column; gap: 3px; padding: 4px 6px 5px; border-radius: 10px;
  background: rgba(0,0,0,.16); border: 1.5px solid transparent; text-align: left;
}
.grup .kartlar { display: flex; padding-right: 2px; }
.grup .kartlar .kart { --w: var(--mini); margin-left: calc(var(--mini) * -0.44); }
.grup .kartlar .kart:first-child { margin-left: 0; }
.grup .etiket { font-size: 11px; color: var(--soluk); display: flex; gap: 4px; align-items: center; min-height: 15px; }
.grup.kanasta { background: rgba(232,194,90,.14); border-color: rgba(232,194,90,.55); }
.grup.kanasta .etiket { color: var(--altin); font-weight: 700; }
.grup.hedef { border-color: #8fe3a8; box-shadow: 0 0 0 3px rgba(143,227,168,.25); }
.grup.yeni-gelen { animation: parla 2.2s ease-out; }
button.grup { color: inherit; }

/* ---------- table centre */
.masa { display: flex; align-items: center; gap: 10px; padding: 6px 2px; min-height: 96px; }
/* Stock column: one fi above the stock and one below, lying crosswise; the cut card
   peeks out from under the stock to the left (Arman, 22 Nov: more room for the pile). */
/* The cut card lies upright under the stock and sticks out to the left, so its corner
   (number and suit) reads straight (Arman, 22 Nov: crosswise it was too small to tell ♣ from ♠). */
.deste-alani { flex: none; width: calc(var(--deste-w) + var(--kesilen-w) * .6); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.deste-alani .fi { width: var(--deste-w); height: var(--fi-w); display: flex; align-items: center; justify-content: center; }
.deste-alani .fi .kart { --w: var(--fi-w); transform: rotate(90deg); box-shadow: 1px 0 0 #f4efe1, 2px 0 0 rgba(0,0,0,.3), 0 1px 3px rgba(0,0,0,.35); }
.deste-satir { position: relative; width: 100%; height: calc(max(var(--deste-w), var(--kesilen-w)) * 1.42 + 2px); display: flex; justify-content: flex-end; align-items: center; }
.deste-satir .kesilen { position: absolute; left: 0; top: 50%; transform: translateY(-50%); z-index: 0; line-height: 0; }
.deste-satir .kesilen .kart { --w: var(--kesilen-w); }
.deste-satir .deste { position: relative; z-index: 1; border: none; background: none; padding: 0; line-height: 0; }
.deste-satir .deste .kart { --w: var(--deste-w); }
.deste-satir .deste .sayi {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none;
  padding: 2px 6px; border-radius: 999px; background: rgba(0,0,0,.5);
  font: 700 12px/1.1 system-ui, sans-serif; color: var(--yazi); font-variant-numeric: tabular-nums;
}
.deste-satir .deste .sayi:empty { display: none; }
.deste.aktif .kart { box-shadow: 0 0 0 3px var(--altin), 0 4px 10px rgba(0,0,0,.4); animation: isik 1.6s ease-in-out infinite; }
/* The pile: as big as the cards in the hand (Arman, 22 Nov). Older cards fan out, each
   showing a strip of --adim px (set by fitPile in ekran.js); the open card on top shows whole. */
.yer-alani { flex: 1; min-width: 0; }
.yer {
  width: 100%; display: flex; align-items: center; border: none; background: rgba(0,0,0,.16);
  border-radius: 12px; padding: 8px; min-height: calc(var(--el-w) * 1.42 + 18px);
}
.yer .eski { flex: 0 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; row-gap: 6px; }
.yer .hucre { flex: none; width: var(--adim, 26px); line-height: 0; }
.yer .hucre .kart { --w: var(--el-w); }
/* only a strip of each older card shows: keep its corner tight to the left so "10" fits */
.yer .hucre .kart .kose { left: 5%; letter-spacing: -.05em; font-size: calc(var(--w) * 0.38); }
.yer .hucre .kart .kose .t { font-size: calc(var(--w) * 0.38); }
.yer .ust-kart { flex: none; line-height: 0; position: relative; z-index: 1; }
.yer .ust-kart .kart { --w: var(--el-w); box-shadow: 0 0 0 2px var(--altin), 0 2px 6px rgba(0,0,0,.4); }
.yer.aktif { box-shadow: 0 0 0 2px var(--altin); }
.yer .bos { color: var(--soluk); font-size: 13px; }

/* cutting the deck */
.kes { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.kes-deste { position: relative; width: 100%; max-width: 420px; height: 82px; border: none; background: none; padding: 0; }
.kes-deste .kart { --w: 50px; position: absolute; top: 6px; }
.kes-deste.aktif:hover .kart { filter: brightness(1.05); }
.kes .not { color: var(--soluk); font-size: 13px; text-align: center; }

/* ---------- status line */
.durum { padding: 6px 4px 2px; font-size: 14px; min-height: 26px; color: var(--soluk); }
.durum b { color: var(--yazi); }
.durum.sira { color: var(--yazi); }
.durum.sira::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--altin); margin-right: 7px; vertical-align: 1px; animation: nabiz 1.6s ease-in-out infinite; }

/* ---------- hand */
.el { padding: 14px 0 4px; display: flex; flex-direction: column; gap: 6px; align-items: center; min-height: 92px; }
.el-satir { display: flex; justify-content: center; }
.el .kart { margin-left: calc(var(--w) * -0.4); transition: transform .12s ease; }
.el .kart:first-child { margin-left: 0; }
.el .kart.secili { transform: translateY(-14px); box-shadow: 0 0 0 2.5px var(--altin), 0 6px 12px rgba(0,0,0,.45); }
.el .kart.yeni::after {
  content: "yeni"; position: absolute; top: -9px; left: 0; font: 700 10px/1 system-ui, sans-serif; color: #2a2208;
  background: var(--altin); padding: 2px 4px; border-radius: 6px;
}
.el .bos { color: var(--soluk); font-size: 14px; padding: 18px 0; }
/* dragging cards in the hand */
.el { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.el .kart { touch-action: none; }
.el .kart.tasinan { opacity: .3; }
.surukle-hayalet { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; will-change: transform; }
.surukle-hayalet .kart { box-shadow: 0 14px 26px rgba(0,0,0,.55); }

/* dealing animation: cards wait hidden in place; a flying copy lands, then the card turns over */
.kart.gizli { visibility: hidden; }
.kart.acildi { animation: acil .3s ease-out; }
.ucan { position: fixed; left: 0; top: 0; z-index: 35; pointer-events: none; transform-origin: 0 0; will-change: transform, opacity; }
.ucan .kart { box-shadow: 0 6px 14px rgba(0,0,0,.4); }

/* ---------- action buttons */
.eylemler { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 8px 0 12px; min-height: 56px; }
.dugme {
  border: none; border-radius: 999px; padding: 10px 16px; font-weight: 700; background: var(--altin); color: #2a2208;
  box-shadow: 0 2px 0 var(--altin-koyu);
}
.dugme:disabled { opacity: .4; cursor: default; }
.dugme.ikincil { background: rgba(0,0,0,.25); color: var(--yazi); box-shadow: none; border: 1px solid rgba(244,239,225,.25); }
.dugme.kucuk { padding: 7px 12px; font-size: 14px; }

/* ---------- cards */
.kart {
  --w: 52px;
  position: relative; flex: none; display: block;
  width: var(--w); height: calc(var(--w) * 1.42);
  border-radius: calc(var(--w) * 0.12);
  background: var(--kart); border: 1px solid var(--kart-kenar);
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
  color: var(--siyah); font-family: Georgia, "Times New Roman", serif; padding: 0; text-align: left;
}
button.kart { cursor: pointer; }
.kart.kirmizi { color: var(--kirmizi); }
/* Corner number and suit sign: big, so ♠ and ♣ are easy to tell apart (Arman, 22 Nov). */
.kart .kose {
  position: absolute; top: 4%; left: 7%; display: flex; flex-direction: column; align-items: center;
  font-weight: 700; line-height: .92; font-size: calc(var(--w) * 0.35); letter-spacing: -.04em;
}
.kart .kose .t { font-size: calc(var(--w) * 0.34); }
.kart .orta { position: absolute; right: 9%; bottom: 5%; font-size: calc(var(--w) * 0.46); line-height: 1; }
/* Real card faces (Arman, 22 Nov): pips by number, a big pip for the Ace, a picture for J/Q/K.
   Placed in the right-hand part of the card, beside the big corner number (see faceHtml). */
.kart { container-type: inline-size; }
.kart .pip { position: absolute; transform: translate(-50%, -50%); font-size: calc(var(--w) * 0.17); line-height: 1; }
.kart .pip.ters { transform: translate(-50%, -50%) rotate(180deg); }
.kart .pip.as { font-size: calc(var(--w) * 0.36); }
.kart .resim { position: absolute; left: 62%; top: 6%; width: 36%; height: 88%; overflow: visible; }
/* Too small to read (the little cards in the score panels): the corner is enough. */
@container (max-width: 39px) { .pip, .resim { display: none; } }
.kart.joker { background: linear-gradient(160deg, #fffdf7 0%, #f3e7ff 100%); color: #5b2a86; }
.kart.joker .kose { font-family: system-ui, sans-serif; font-size: calc(var(--w) * 0.2); letter-spacing: 0; line-height: 1.02; }
.kart.joker .orta { color: var(--altin-koyu); }
.kart.arka {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.09) 0 3px, transparent 3px 7px),
    linear-gradient(160deg, #8e2b2b, #5a1717);
  border: 2px solid #f4efe1;
}
.kart.mini .kose { font-size: calc(var(--w) * 0.44); left: 5%; }
.kart.mini .kose .t { font-size: calc(var(--w) * 0.44); }
.kart.mini .orta { display: none; }

/* ---------- overlays */
#katman:empty { display: none; }
.katman {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 22, 13, .72); backdrop-filter: blur(2px); padding: 12px;
}
.pano {
  background: var(--pano); color: var(--pano-yazi); border-radius: 18px; width: 100%; max-width: 520px;
  max-height: 88dvh; overflow-y: auto; padding: 18px 16px 16px; box-shadow: 0 20px 50px rgba(0,0,0,.45);
  color-scheme: light;
}
.pano h2 { margin: 0 0 4px; font-family: Georgia, "Times New Roman", serif; font-size: 22px; }
.pano h3 { margin: 14px 0 6px; font-size: 15px; }
.pano .alt { color: #5b625d; font-size: 13px; margin: 0 0 10px; }
.pano .dugmeler { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.pano .dugme.ikincil { color: var(--pano-yazi); background: transparent; border-color: #c9c2b0; }
.pano table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.pano th, .pano td { padding: 6px 4px; border-bottom: 1px solid #e4ddcb; text-align: right; }
.pano th:first-child, .pano td:first-child { text-align: left; }
.pano th { font-size: 12px; color: #5b625d; font-weight: 600; }
.pano tr.toplam td { font-weight: 700; border-bottom: none; border-top: 2px solid #c9c2b0; }
.pano .eksi { color: #b3261e; }
.pano .kazanan { background: linear-gradient(90deg, #f6e3a6, #fbf1cf); border-radius: 12px; padding: 10px 12px; margin: 8px 0 4px; font-weight: 700; }
.pano .menu { display: flex; flex-direction: column; gap: 8px; }
.pano .menu .dugme { text-align: left; }
.pano .kartlar-satir { display: flex; flex-wrap: wrap; gap: 3px; margin: 4px 0; }
.pano .kartlar-satir .kart { --w: 28px; }
.pano .kanasta-listesi { margin: 2px 0 0; padding-left: 18px; font-size: 13px; color: #3f4641; }
.pano .gecmis-mac { padding: 8px 0; border-bottom: 1px solid #e4ddcb; }
.pano .gecmis-mac .tarih { font-size: 12px; color: #5b625d; }
.sonuc-dugmesi { position: fixed; right: 12px; bottom: 90px; z-index: 15; }

/* ---------- toast */
.bildirim {
  position: fixed; left: 12px; right: 12px; margin: 0 auto; width: fit-content; top: 44%;
  transform: translateY(20px); max-width: 480px; padding: 10px 14px; border-radius: 12px; background: #1c2a22; color: var(--yazi);
  box-shadow: 0 8px 24px rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30;
  font-size: 14px; text-align: center;
}
.bildirim.goster { opacity: 1; transform: translateY(0); }
.bildirim.hata { background: #4a1a16; color: #ffe1dc; }

.tam-ekran-not { padding: 40px 18px; text-align: center; color: var(--soluk); grid-row: 1 / -1; }
.tam-ekran-not h1 { font-family: Georgia, serif; color: var(--altin); }

/* ---------- wide screens: a computer, or a phone turned sideways (Arman, 22 Nov: no scrolling,
   everything at once, spread sideways). Groups fill the left side from top to bottom (the
   opponent's above, mine below); title, scores, stock and pile on the right; the hand along
   the bottom with the buttons beside it. */
@media (min-aspect-ratio: 5/4) and (min-width: 640px) {
  .uygulama {
    max-width: 1500px;
    grid-template-columns: minmax(0, 1fr) clamp(300px, 36%, 600px);
    /* The 60px row makes up for title + opponent line (above) being taller than the status
       line (below), so the two group areas come out the same height. */
    grid-template-rows: auto auto minmax(0, 1fr) 60px minmax(0, 1fr) auto auto;
    grid-template-areas:
      "rgrup ust"
      "rgrup rakip"
      "rgrup masa"
      "bgrup masa"
      "bgrup masa"
      "bgrup durum"
      "el    eylemler";
    column-gap: 14px;
  }
  /* Desktop is the target (Arman, 22 Nov): stock and cut card as big as the hand and the pile. */
  :root { --deste-w: var(--el-w); --kesilen-w: var(--el-w); --fi-w: calc(var(--el-w) * .42); }
  .deste-satir .deste .sayi { font-size: 15px; padding: 3px 8px; }
  .gruplar { gap: 6px 8px; padding: 4px; }
  .rakip-gruplari { margin-top: 6px; }
  .ust { grid-area: ust; }
  .rakip { grid-area: rakip; }
  .rakip-gruplari { grid-area: rgrup; }
  .masa { grid-area: masa; }
  .benim-gruplarim { grid-area: bgrup; margin-top: 6px; }
  .durum { grid-area: durum; }
  .el { grid-area: el; }
  .eylemler { grid-area: eylemler; align-content: center; padding: 8px 0; }
}

@keyframes nabiz { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@keyframes isik {
  0%, 100% { box-shadow: 0 0 0 3px var(--altin), 0 4px 10px rgba(0,0,0,.4); }
  50% { box-shadow: 0 0 0 3px rgba(232,194,90,.35), 0 4px 10px rgba(0,0,0,.4); }
}
@keyframes parla { 0% { box-shadow: 0 0 0 3px rgba(232,194,90,.9); } 100% { box-shadow: 0 0 0 3px rgba(232,194,90,0); } }
@keyframes acil { from { transform: scaleX(.08); } to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
