:root {
  --bg: #08261a;
  --felt1: #1f7a4d;
  --felt2: #0d3d27;
  --ink: #f4efe2;
  --muted: #a9c7b5;
  --gold: #f2c14e;
  --red: #c8102e;
  --black: #1d1d1d;
  --paper: #fbf8f1;
  --line: rgba(255, 255, 255, 0.14);
  --panel: rgba(6, 30, 20, 0.92);
  --cw: 60px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.screen {
  position: fixed; inset: 0;
  max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
  background: radial-gradient(120% 80% at 50% 30%, var(--felt1), var(--felt2));
}

/* ---------- Düğmeler ---------- */
.btn {
  display: block; width: 100%;
  padding: 14px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08);
  font-weight: 700; font-size: 17px;
}
.btn.primary { background: var(--gold); color: #3a2a00; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn:active { transform: scale(0.98); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: transparent; font-size: 22px; display: grid; place-items: center;
}
.icon-btn.corner { position: absolute; top: calc(var(--safe-t) + 8px); right: 8px; }
.bar { display: flex; align-items: center; gap: 6px; padding: 4px 6px; min-height: 52px; }
.bar h2 { flex: 1; text-align: center; margin: 0; font-size: 19px; }

/* ---------- Ana menü ---------- */
#home { justify-content: center; align-items: center; padding: 24px; gap: 28px; }
.logo { text-align: center; }
.logo img { border-radius: 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.logo h1 { font-family: Georgia, 'Times New Roman', serif; font-size: 42px; margin: 14px 0 4px; letter-spacing: 0.5px; }
.logo p { margin: 0; color: var(--muted); }
.menu { width: 100%; max-width: 320px; display: grid; gap: 12px; }
.stats { color: var(--muted); font-size: 14px; margin: 0; min-height: 1em; }

/* ---------- Kurulum ---------- */
.form { padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.form label { font-weight: 700; margin-top: 12px; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; }
.form .btn { margin-top: 24px; }
.seg { display: flex; background: rgba(0, 0, 0, 0.25); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 11px 6px; border-radius: 9px; font-weight: 700; }
.seg button.on { background: var(--paper); color: var(--felt2); }
.seg button:disabled { opacity: 0.35; }
.hint { margin: 2px 2px 0; color: var(--muted); font-size: 14px; min-height: 2.6em; }

/* ---------- Masa ---------- */
.chips { flex: 1; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.chip { background: rgba(0, 0, 0, 0.28); border-radius: 999px; padding: 4px 10px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.chip .s { background: var(--paper); color: var(--black); border-radius: 6px; padding: 0 4px; font-size: 15px; }
.chip .s.r { color: var(--red); }
.felt { position: relative; flex: 1; min-height: 0; }

.seat { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; width: 96px; }
.seat[data-pos='top'] { top: 6px; left: 50%; transform: translateX(-50%); }
.seat[data-pos='left'] { left: 4px; top: 42%; transform: translateY(-50%); }
.seat[data-pos='right'] { right: 4px; top: 42%; transform: translateY(-50%); }
.p3 .seat[data-pos='left'], .p3 .seat[data-pos='right'] { top: 26%; }
.seat.mine { position: static; width: auto; flex-direction: row; justify-content: center; gap: 10px; padding: 4px 8px; }
.av {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.3); border: 2px solid var(--line); font-weight: 800; font-size: 18px; position: relative;
}
.mine .av { width: 34px; height: 34px; font-size: 15px; }
.seat.turn .av { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.25); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(242, 193, 78, 0.1); } }
.av .dl {
  position: absolute; right: -6px; bottom: -4px; background: var(--paper); color: var(--felt2);
  border-radius: 50%; width: 18px; height: 18px; font-size: 11px; display: grid; place-items: center;
}
.av .bd { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); font-size: 14px; }
.nm { font-weight: 700; font-size: 14px; }
.st { font-size: 13px; color: var(--ink); background: rgba(0, 0, 0, 0.28); padding: 1px 8px; border-radius: 999px; min-height: 1.4em; }
.st:empty { visibility: hidden; }
.st.ok { color: #9be7b0; }
.st.bad { color: #ffb3b3; }
.sc { font-size: 13px; color: var(--muted); }
.team .nm::after { content: ' ★'; color: var(--gold); }
.backs { display: flex; height: 22px; }
.backs i { width: 15px; height: 22px; border-radius: 3px; margin-left: -8px; background: repeating-linear-gradient(45deg, #b0283c 0 3px, #8e1c2e 3px 6px); border: 1px solid #f4efe2; }
.backs i:first-child { margin-left: 0; }
.backs b { font-size: 12px; margin-left: 4px; line-height: 22px; color: var(--muted); }

/* ---------- Kart ---------- */
.card {
  position: absolute; width: var(--cw); height: calc(var(--cw) * 1.4);
  border-radius: calc(var(--cw) * 0.1); background: var(--paper); color: var(--black);
  border: 1px solid #d9d2c2; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  font-family: Georgia, 'Times New Roman', serif;
}
.card.red { color: var(--red); }
.card .ix { position: absolute; left: 4%; top: 3%; font-weight: 700; font-size: calc(var(--cw) * 0.3); line-height: 0.95; text-align: center; width: 0.95em; }
.card .ix small { display: block; font-size: 0.9em; }
.card .pip { position: absolute; right: 8%; bottom: 4%; font-size: calc(var(--cw) * 0.55); line-height: 1; }

.me { position: relative; }
.hand { position: relative; height: calc(var(--cw) * 1.4 + 22px); margin: 0 12px 8px; }
.hand .card { bottom: 0; transition: transform 0.15s, filter 0.15s; }
.hand .card.ok { transform: translateY(-14px); }
.hand .card.no { filter: brightness(0.6) saturate(0.6); }
.hand .card.shake { animation: shake 0.35s; }
.hand.deal .card { animation: deal 0.4s backwards; animation-delay: calc(var(--i) * 35ms); }
@keyframes deal { from { transform: translateY(60px); opacity: 0; } }
@keyframes shake { 25% { margin-left: -6px; } 75% { margin-left: 6px; } }

.trick { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.trick .card {
  --s: 0.9;
  transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)) scale(var(--s));
  transition: transform 0.35s ease-in, opacity 0.35s ease-in;
}
.trick .card.in { animation: fly 0.25s ease-out; }
@keyframes fly {
  from { transform: translate(calc(-50% + var(--fx)), calc(-50% + var(--fy))) scale(0.7); opacity: 0.4; }
}
.trick .card.win { box-shadow: 0 0 0 3px var(--gold), 0 4px 12px rgba(0, 0, 0, 0.4); }
.trick.gone .card { transform: translate(calc(-50% + var(--gx)), calc(-50% + var(--gy))) scale(0.4); opacity: 0; }

/* ---------- İhale / koz paneli ---------- */
.panel {
  position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45); z-index: 5;
}
.panel h3 { margin: 0 0 2px; text-align: center; font-size: 17px; }
.panel p { margin: 0 0 10px; text-align: center; color: var(--muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.grid button, .suits button {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); border-radius: 11px;
  padding: 10px 0; font-weight: 800; font-size: 17px; position: relative;
}
.grid button.wide { grid-column: span 2; }
.grid.dense { grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grid.dense button { padding: 8px 0; font-size: 16px; }
.grid button.sug::after, .suits button.sug::after {
  content: ''; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold);
}
.suits { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.suits button { font-size: 34px; padding: 6px 0; background: var(--paper); color: var(--black); }
.suits button.red { color: var(--red); }

/* ---------- Pencere ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center;
  padding: 16px; z-index: 20;
}
.card-box {
  width: 100%; max-width: 420px; max-height: 88vh; overflow: auto;
  background: #0f3a27; border: 1px solid var(--line); border-radius: 20px; padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.card-box h2 { margin: 0; text-align: center; font-family: Georgia, serif; font-size: 26px; }
.card-box h4 { margin: 8px 0 0; color: var(--gold); }
.card-box p { margin: 0; color: var(--muted); text-align: center; }
.card-box .rules p { text-align: left; color: var(--ink); font-size: 15px; }
table.sc { width: 100%; border-collapse: collapse; font-size: 14px; }
table.sc th, table.sc td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
table.sc th:first-child, table.sc td:first-child { text-align: left; }
table.sc tfoot td { font-weight: 800; border-bottom: 0; }
table.sc .pos { color: #9be7b0; }
table.sc .neg { color: #ffb3b3; }
table.sc tr.me td { background: rgba(242, 193, 78, 0.1); }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; }
.set-row .seg { flex: 0 0 auto; min-width: 170px; }
.banner { text-align: center; font-size: 22px; font-weight: 800; color: var(--gold); }

#toasts { position: fixed; left: 0; right: 0; top: 30%; display: grid; justify-items: center; gap: 6px; z-index: 30; pointer-events: none; }
.toast { background: rgba(0, 0, 0, 0.8); padding: 8px 14px; border-radius: 999px; font-size: 15px; font-weight: 600; animation: toast 2.2s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
