/* Kral Okey - styles */
:root {
  --felt1: #1d6b47;
  --felt2: #0d4430;
  --wood1: #7a4a21;
  --wood2: #4c2c12;
  --tile-w: 48px;
  --tile-h: 66px;
  --tile-radius: 7px;
  --red: #cc2222;
  --yellow: #c79400;
  --black: #262626;
  --blue: #2456b8;
  --gold: #f2c14e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

html, body {
  overscroll-behavior: none;           /* no pull-to-refresh / rubber banding */
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse at 50% 40%, var(--felt1) 0%, var(--felt2) 75%);
  color: #f4efe4;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;         /* no iOS long-press callout on tiles */
}

#table { position: fixed; top: 0; right: 0; bottom: 0; left: 0; display: block; }

/* ---------------- top bar ---------------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 46px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.45), rgba(0,0,0,.12));
  z-index: 30;
}
#brand { font-size: 20px; font-weight: 700; letter-spacing: 1px; color: var(--gold); text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.topbar-actions { display: flex; gap: 8px; }

/* ---------------- buttons ---------------- */
.btn {
  font: inherit; font-size: 13.5px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.10);
  color: #f4efe4; cursor: pointer; transition: all .15s ease;
  touch-action: manipulation;          /* no double-tap zoom on controls */
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { background: rgba(255,255,255,.22); }
.btn:disabled { opacity: .38; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #2e8f5b, #1d6b47); border-color: #57c98a55; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #37a86c, #23805a); }
.btn.danger { background: linear-gradient(180deg, #b0392f, #87281f); border-color: #e77a6a55; }
.btn.danger:hover:not(:disabled) { background: linear-gradient(180deg, #c94a3e, #9c332a); }
.btn.special { background: linear-gradient(180deg, #b98a1d, #8a650e); border-color: #f2c14e66; }
.btn.special:hover:not(:disabled) { background: linear-gradient(180deg, #d3a02a, #a27812); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 18px; padding: 12px 34px; }
.btn.tiny { padding: 2px 8px; font-size: 12px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------------- tiles ---------------- */
.tile {
  width: var(--tile-w); height: var(--tile-h);
  border-radius: var(--tile-radius);
  background: linear-gradient(160deg, #fffdf4 0%, #f1ecd9 80%, #e2dcc4 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9), inset 0 -3px 5px rgba(0,0,0,.14), 0 3px 5px rgba(0,0,0,.45);
  display: inline-flex; align-items: center; justify-content: center;
  position: relative; vertical-align: top; flex: 0 0 auto;
}
.tile .num { font-size: 26px; font-weight: 800; text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.tile .pip { position: absolute; bottom: 4px; right: 6px; font-size: 11px; opacity: .85; }
.tile.red .num, .tile.red .pip { color: var(--red); }
.tile.yellow .num, .tile.yellow .pip { color: var(--yellow); }
.tile.black .num, .tile.black .pip { color: var(--black); }
.tile.blue .num, .tile.blue .pip { color: var(--blue); }

.tile.fake {
  background: linear-gradient(160deg, #fdf6ff 0%, #ece2f2 70%, #d8cbdf 100%);
}
.tile.fake::after {
  content: "✦"; font-size: 24px; color: #7a4d9e;
  text-shadow: 0 0 6px #b58ee066;
}
.tile.fake .fake-note {
  position: absolute; bottom: 3px; width: 100%; text-align: center;
  font-size: 8px; letter-spacing: .5px; color: #7a4d9e; font-weight: 700;
}

.tile.okey-tile { outline: 2px solid var(--gold); outline-offset: -2px; }
.tile.okey-tile::before {
  content: "OKEY"; position: absolute; top: 3px; left: 0; right: 0;
  text-align: center; font-size: 8px; letter-spacing: 1px; color: #a8811c; font-weight: 800;
}
.tile.okey-tile .num { margin-top: 10px; }

.tile.back {
  background:
    repeating-linear-gradient(45deg, #8d3f32 0 6px, #7c3529 6px 12px);
  border: 2px solid #5d241b;
  box-shadow: inset 0 0 8px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.5);
}

.tile.mini { --tile-w: 38px; --tile-h: 52px; }
.tile.mini .num { font-size: 19px; }
.tile.micro { --tile-w: 15px; --tile-h: 21px; --tile-radius: 3px; box-shadow: none; border: 1px solid #5d241b; }

.tile.selectable { cursor: pointer; transition: transform .12s ease, filter .12s ease; }
.tile.selectable:hover { transform: translateY(-6px); filter: brightness(1.06); }

.tile.selected { transform: translateY(-14px); box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 0 0 2px var(--gold), 0 8px 14px rgba(0,0,0,.5); z-index: 2; }

.tile.winning-glow { animation: pulseWin 1s ease-in-out infinite; cursor: pointer; }
@keyframes pulseWin {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 0 0 2px #59d97c, 0 3px 5px rgba(0,0,0,.45); }
  50% { box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 0 0 5px #59d97caa, 0 3px 9px rgba(40,200,90,.5); }
}

.tile.joker-cell {
  background: repeating-linear-gradient(135deg, #efe7cf 0 8px, #e3d9bc 8px 16px);
  border: 2px dashed #a8811c;
}
.tile.joker-cell::after { content: "ᴶ"; font-size: 20px; color: #a8811c; font-weight: 800; }

/* ---------------- seats (bots) ---------------- */
.seat {
  position: absolute; z-index: 10;
  background: linear-gradient(180deg, var(--wood1), var(--wood2));
  border: 1px solid #2e1908; border-radius: 12px;
  box-shadow: 0 6px 14px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.15);
  padding: 8px 10px;
}
.seat-n { top: 54px; left: 50%; transform: translateX(-50%); }
.seat-w { left: 12px; top: 42%; transform: translateY(-50%); max-width: 210px; }
.seat-e { right: 12px; top: 42%; transform: translateY(-50%); max-width: 210px; }
.seat-s { position: static; transform: none; display: inline-block; min-width: 170px; }

.seat.active { box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0,0,0,.5); }
.seat .seat-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; display:flex; justify-content: space-between; gap: 8px;}
.seat .score-chip { background: rgba(0,0,0,.35); padding: 1px 8px; border-radius: 10px; font-size: 12.5px; color: var(--gold); }
.seat .backs { display: flex; flex-wrap: wrap; gap: 2px; max-width: 150px; min-height: 21px; }
.seat .starter-badge { font-size: 11px; color: #ffd97a; margin-top: 3px; }
.seat .thinking { color: #ffe9ad; font-size: 11.5px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* compact tile-count chip (shown instead of card backs on narrow screens) */
.seat .hand-count { display: none; font-size: 12px; opacity: .9; }

/* top bar respects notches */
#topbar {
  padding-top: env(safe-area-inset-top);
}

.seat-s .seat-name { font-size: 15px; }

/* ---------------- human rack & controls ---------------- */
#south-area {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom));
}
#rack-wrap {
  background: linear-gradient(180deg, var(--wood1), var(--wood2));
  border: 1px solid #2e1908; border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 8px 18px rgba(0,0,0,.55), inset 0 2px 0 rgba(255,255,255,.18);
  max-width: 96vw;
}
#rack { display: flex; flex-direction: column; gap: 7px; max-width: 900px; }
.rack-row {
  display: flex; flex-wrap: wrap; gap: 5px; justify-content: center;
  align-items: flex-end; padding: 2px 4px 4px;
  min-height: calc(var(--tile-h) + 6px);
  position: relative;
}
/* upper ledge of the istaka casts a small shadow onto the lower one */
.rack-row.ledged {
  border-bottom: 3px solid rgba(30, 14, 4, .65);
  box-shadow: 0 4px 6px -2px rgba(0,0,0,.45);
}
.rack-row .tile { margin-bottom: 0; touch-action: none; }
.rack-row .tile.selectable { cursor: grab; }
.tile.drag-origin { opacity: .35; outline: 2px dashed rgba(255,255,255,.55); }
.dragging-clone {
  position: fixed; z-index: 200; pointer-events: none;
  transform: translate(-50%, -60%) scale(1.06) rotate(2deg);
  box-shadow: 0 14px 26px rgba(0,0,0,.6) !important;
  will-change: transform;
}
.drop-indicator {
  width: 4px; border-radius: 2px; background: var(--gold);
  align-self: stretch; min-height: var(--tile-h);
  box-shadow: 0 0 10px var(--gold);
}
#controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  background: rgba(0,0,0,.28); padding: 6px 12px; border-radius: 10px;
}
#controls .btn { white-space: nowrap; }
#status-text { font-size: 13.5px; color: #ffe9ad; min-width: 220px; text-align: center; }

/* ---------------- center piles ---------------- */
#center {
  position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%);
  display: flex; gap: 34px; align-items: flex-end; z-index: 5;
}
.pile-group { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile-label { font-size: 11.5px; letter-spacing: 1px; color: #cfe3d3; text-transform: uppercase; opacity: .85; }
#deck-pile { position: relative; width: var(--tile-w); height: var(--tile-h); }
#deck-pile .tile { position: absolute; }
#gosterge-slot, #discard-slot { position: relative; width: var(--tile-w); height: var(--tile-h); }
#discard-slot .count-tag {
  position: absolute; bottom: -8px; right: -10px; z-index: 3;
  background: #333; border: 1px solid #777; color: #eee;
  font-size: 10.5px; padding: 1px 6px; border-radius: 9px;
}
#discard-slot.claimable .tile { animation: claimGlow 1.2s ease-in-out infinite; cursor: pointer; }
@keyframes claimGlow {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 0 0 2px #59d97c, 0 3px 5px rgba(0,0,0,.45); }
  50% { box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 0 0 5px #59d97caa, 0 3px 9px rgba(40,200,90,.55); }
}

/* ---------------- log panel ---------------- */
#log-panel {
  position: absolute; top: 46px; right: 0; bottom: 0; width: 300px; z-index: 40;
  background: rgba(8, 30, 20, .96); border-left: 1px solid #2f5a44;
  display: flex; flex-direction: column;
}
.log-head { padding: 8px 12px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #2f5a44; }
#log-lines { overflow-y: auto; padding: 8px 12px; font-size: 12.5px; line-height: 1.55; color: #d7e8dc; }
#log-lines .log-line { margin-bottom: 3px; }
#log-lines .log-line.sys { color: #ffd97a; }

/* ---------------- toast ---------------- */
#toast-stack {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 50; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none;
}
.toast {
  background: rgba(10, 25, 18, .92); border: 1px solid #3f7a5c;
  color: #f4efe4; font-size: 13px; padding: 6px 14px; border-radius: 18px;
  box-shadow: 0 4px 10px rgba(0,0,0,.4);
  animation: toastIn .18s ease-out;
}
.toast.fadeout { opacity: 0; transition: opacity .5s ease; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- modals ---------------- */
#modal-overlay, #intro-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 60;
  background: rgba(0, 10, 6, .72);
  display: flex; align-items: center; justify-content: center;
}
#modal-box, #intro-box {
  background: linear-gradient(180deg, #14382a, #0c241b);
  border: 1px solid #3f7a5c; border-radius: 16px;
  padding: 26px 32px; max-width: min(720px, 92vw); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,.65);
  text-align: center;
}
#intro-box h1 { color: var(--gold); font-size: 40px; letter-spacing: 2px; margin-bottom: 8px; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
#intro-box .sub { color: #d7e8dc; margin-bottom: 14px; line-height: 1.5; }
.mini-rules { text-align: left; list-style-position: inside; color: #bcd6c4; font-size: 13.5px; line-height: 1.7; margin: 0 auto 20px; max-width: 520px; }
#intro-box .btn.big { margin-top: 6px; }

.hand-title { font-size: 22px; font-weight: 800; color: var(--gold); margin-bottom: 4px; }
.hand-subtitle { color: #cfe3d3; margin-bottom: 14px; font-size: 14px; }
.meld-row { display: flex; gap: 4px; justify-content: center; margin-bottom: 10px; flex-wrap: wrap; }
.meld-row .tile { --tile-w: 40px; --tile-h: 55px; }
.meld-row .tile .num { font-size: 20px; }
.meld-sep { width: 18px; }
.delta-table { margin: 12px auto 18px; border-collapse: collapse; font-size: 14.5px; }
.delta-table td, .delta-table th { padding: 5px 16px; border-bottom: 1px solid #2f5a44; }
.delta-table th { color: #9fc3aa; font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 1px; }
.delta-table .delta-pos { color: #7be495; font-weight: 700; }
.delta-table .delta-neg { color: #ff9b8a; font-weight: 700; }
.delta-table .winner-row td { color: var(--gold); font-weight: 700; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }

.rules-text { text-align: left; color: #d7e8dc; font-size: 13.5px; line-height: 1.65; }
.rules-text h3 { color: var(--gold); margin: 12px 0 4px; font-size: 15px; }
.rules-text b.tl { color: #ffd97a; }

/* crown for champion */
.crown { font-size: 44px; }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  :root { --tile-w: 40px; --tile-h: 56px; }
  .tile .num { font-size: 21px; }
  #rack { max-width: 640px; }
}

/* ---------------- phones & narrow screens ---------------- */
@media (max-width: 700px) {
  /* tiles scale with the viewport: 8 tiles + gaps must fit one shelf */
  :root {
    --tile-w: min(44px, calc((100vw - 64px) / 8));
    --tile-h: calc(var(--tile-w) * 1.36);
    --tile-radius: 5px;
  }
  .tile .num { font-size: calc(var(--tile-w) * 0.52); }
  .tile.mini .num { font-size: calc(var(--tile-w) * 0.44); }

  /* top bar */
  #topbar { padding-left: 10px; padding-right: 10px; }
  #brand { font-size: 16px; }
  .btn { font-size: 12.5px; padding: 7px 10px; }

  /* north opponent stays on screen, tighter */
  .seat-n { top: calc(50px + env(safe-area-inset-top)); padding: 6px 8px; }
  .seat-n .backs { max-width: 190px; }

  /* east/west opponents become compact side chips (score + count visible) */
  .seat-w, .seat-e {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    top: auto; bottom: 62%; transform: none;
    max-width: 84px; min-width: 64px;
    padding: 5px 6px; border-radius: 9px;
  }
  .seat-w { left: 4px; }
  .seat-e { right: 4px; }
  .seat-w .backs, .seat-e .backs { display: none; }
  .seat-w .seat-name, .seat-e .seat-name { font-size: 11px; flex-direction: column; align-items: center; gap: 1px; }
  .seat .hand-count { display: block; text-align: center; }
  .seat-w .thinking, .seat-e .thinking { font-size: 9.5px; text-align: center; }
  .seat-w .starter-badge, .seat-e .starter-badge { display: none; }

  /* center piles */
  #center { gap: 12px; top: 42%; }
  .pile-label { font-size: 9.5px; letter-spacing: .5px; }
  .drop-indicator { width: 3px; }

  /* rack & controls */
  .seat-s { min-width: 0; padding: 4px 8px; }
  #south-area { gap: 4px; }
  #rack-wrap { padding: 6px 8px; border-radius: 10px; }
  #rack { gap: 4px; max-width: 100%; }
  #rack-row-top, #rack-row-bottom { gap: 4px; padding: 1px 2px 3px; }
  #controls { gap: 5px; padding: 5px 8px; width: 100%; justify-content: center; }
  #controls .btn { padding: 8px 10px; font-size: 12px; }
  #status-text { order: -1; flex-basis: 100%; min-width: 0; font-size: 12px; }

  /* overlays */
  #log-panel { width: min(320px, 92vw); }
  #toast-stack { top: calc(50px + env(safe-area-inset-top)); width: 96vw; }
  .toast { font-size: 12px; max-width: 94vw; }
  #modal-box, #intro-box { padding: 18px 16px; border-radius: 12px; }
  #intro-box h1 { font-size: clamp(26px, 9vw, 34px); }
  .mini-rules { font-size: 12px; line-height: 1.55; }
  .meld-row .tile { --tile-w: 32px; --tile-h: 44px; }
  .delta-table td, .delta-table th { padding: 4px 10px; font-size: 13px; }
}

/* short landscape phones: compress vertically */
@media (max-height: 460px) and (orientation: landscape) {
  :root { --tile-h: calc(var(--tile-w) * 1.18); }
  .pile-label { display: none; }
  #center { top: 46%; gap: 20px; }
  .seat-n { top: 48px; }
  #rack-wrap { padding: 4px 8px; }
}
