:root {
  --bg: #0c120f;
  --surface: #151e19;
  --surface-2: #1c2821;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f5f7f5;
  --muted: #9ca9a1;
  --accent: #66e18f;
  --accent-dark: #153f25;
  --danger: #ff6b70;
  --success: #6ee7a0;
  --card-w: clamp(68px, 19vw, 104px);
  --card-h: calc(var(--card-w) * 1.43);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; }

#app { position: relative; width: 100%; height: 100%; min-height: 100svh; background:
  radial-gradient(circle at 50% 25%, rgba(83, 170, 106, 0.12), transparent 40%),
  linear-gradient(180deg, #101813, #0a0f0c); }

.screen { display: none; width: 100%; height: 100%; min-height: 100svh; }
.screen.active { display: flex; }
.screen--center { align-items: center; justify-content: center; padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom)); text-align: center; }

.logo-card { width: 74px; height: 96px; display: grid; place-items: center; margin: 0 auto 18px; font-size: 38px; border-radius: 16px; background: #f6f3e8; box-shadow: 0 20px 55px rgba(0, 0, 0, .35); transform: rotate(-5deg); }
h1 { margin: 0; font-size: clamp(30px, 9vw, 46px); letter-spacing: -1.8px; }
h2 { margin: 0 0 8px; font-size: 27px; }
p { line-height: 1.45; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.hidden { display: none !important; }

.home-card, .waiting-card, .result-card { width: min(100%, 420px); }
.home-card > .muted { margin: 8px 0 28px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 12px 0; padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .035); }
.segmented.compact { margin-bottom: 24px; }
.segment { min-height: 46px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; }
.segment.active { background: var(--surface-2); color: var(--text); box-shadow: 0 5px 16px rgba(0, 0, 0, .18); }
.primary-button, .ghost-button { width: 100%; min-height: 54px; border-radius: 15px; cursor: pointer; }
.primary-button { border: 0; background: var(--accent); color: #07140b; font-weight: 800; font-size: 17px; box-shadow: 0 12px 34px rgba(67, 217, 111, .2); }
.ghost-button { margin-top: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.03); }
#userLabel { margin-top: 18px; }

.spinner { width: 48px; height: 48px; margin: 0 auto 22px; border: 4px solid rgba(255,255,255,.09); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.game-screen.active { display: grid; grid-template-rows: auto auto 1fr auto auto; position: relative; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.game-header { min-height: 68px; display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: rgba(10, 16, 12, .8); backdrop-filter: blur(18px); z-index: 3; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.04); font-size: 27px; line-height: 1; }
.opponent { display: flex; align-items: center; gap: 10px; min-width: 0; }
.opponent strong { display: block; max-width: 42vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; overflow: hidden; background: var(--surface-2); font-weight: 800; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.round-info { display: grid; gap: 2px; text-align: right; font-size: 11px; color: var(--muted); }

.opponent-hand { height: 52px; display: flex; justify-content: center; align-items: flex-start; overflow: hidden; padding-top: 5px; }
.opponent-hand .card-back { width: 37px; height: 53px; margin-left: -20px; border-radius: 7px; transform-origin: 50% -50px; }
.opponent-hand .card-back:first-child { margin-left: 0; }

.table-area { position: relative; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 16px 64px 10px 10px; }
.table-cards { display: grid; grid-template-columns: repeat(2, minmax(84px, 112px)); gap: 16px 10px; justify-content: center; align-content: center; min-height: 180px; width: 100%; }
.table-pair { position: relative; width: 94px; height: 140px; cursor: pointer; border-radius: 12px; }
.table-pair.targetable::after { content: 'Выбрать'; position: absolute; inset: -5px; border: 2px solid var(--accent); border-radius: 15px; display: grid; place-items: end center; padding-bottom: 3px; color: var(--accent); font-size: 10px; background: rgba(102,225,143,.05); animation: pulse 1s ease-in-out infinite alternate; }
.table-pair .playing-card { position: absolute; width: 80px; height: 114px; }
.table-pair .attack-card { left: 0; top: 0; transform: rotate(-5deg); }
.table-pair .defense-card { right: 0; bottom: 0; transform: rotate(8deg); z-index: 2; }
.table-pair.new-card { animation: dealIn .25s ease-out; }
@keyframes dealIn { from { opacity: 0; transform: translateY(-18px) scale(.9); } }
@keyframes pulse { from { opacity: .65; } to { opacity: 1; } }
.table-hint { color: var(--muted); font-size: 14px; }
.deck-zone { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 56px; display: grid; gap: 8px; justify-items: center; }
.deck-stack { position: relative; }
.deck-count { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; font-size: 12px; text-shadow: 0 1px 3px #000; }
.trump-card .playing-card { width: 43px; height: 61px; transform: rotate(90deg); font-size: 9px; }

.status-panel { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: rgba(21, 30, 25, .86); backdrop-filter: blur(14px); }
.status-text { font-size: 13px; font-weight: 650; line-height: 1.25; }
.action-buttons { display: flex; gap: 7px; flex-shrink: 0; }
.action-button { min-width: 76px; height: 38px; border: 0; border-radius: 11px; font-weight: 800; }
.action-button.danger { background: rgba(255, 107, 112, .16); color: #ff9a9e; }
.action-button.success { background: var(--accent); color: #07140b; }

.my-zone { min-height: calc(var(--card-h) + 52px); background: rgba(7, 12, 9, .68); }
.hand-toolbar { min-height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 5px 12px 0; }
.role-pill { padding: 5px 9px; border-radius: 999px; background: var(--accent-dark); color: var(--accent); font-size: 11px; font-weight: 800; }
.my-hand { height: calc(var(--card-h) + 16px); display: flex; align-items: flex-end; overflow-x: auto; overflow-y: hidden; padding: 5px max(14px, calc(50vw - var(--card-w) / 2)) 10px; scroll-snap-type: x proximity; scrollbar-width: none; touch-action: pan-x; }
.my-hand::-webkit-scrollbar { display: none; }
.my-hand .playing-card { flex: 0 0 var(--card-w); width: var(--card-w); height: var(--card-h); margin-left: calc(var(--card-w) * -.24); scroll-snap-align: center; transform-origin: 50% 100%; transition: transform .16s ease, filter .16s ease, opacity .16s ease; cursor: pointer; }
.my-hand .playing-card:first-child { margin-left: 0; }
.my-hand .playing-card.selected { transform: translateY(-16px); filter: drop-shadow(0 8px 9px rgba(102,225,143,.22)); }
.my-hand .playing-card.disabled { opacity: .58; }

.playing-card, .card-back { border-radius: 11px; box-shadow: 0 8px 20px rgba(0,0,0,.33); }
.playing-card { position: relative; padding: 7px; overflow: hidden; background: #f8f6ee; color: #161915; border: 1px solid rgba(0,0,0,.14); user-select: none; }
.playing-card.red { color: #d6353c; }
.card-corner { display: grid; justify-items: center; width: min-content; font-weight: 900; line-height: .9; font-size: clamp(15px, 4.2vw, 21px); }
.card-corner.bottom { position: absolute; right: 7px; bottom: 7px; transform: rotate(180deg); }
.card-suit { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(34px, 10vw, 56px); opacity: .92; }
.card-back { background:
  linear-gradient(135deg, rgba(255,255,255,.11) 25%, transparent 25%) 0 0/12px 12px,
  linear-gradient(315deg, rgba(255,255,255,.11) 25%, transparent 25%) 0 0/12px 12px,
  #254e35;
  border: 3px solid #e9e4d5;
  outline: 1px solid rgba(0,0,0,.28); }
.card-back.small { width: 43px; height: 61px; }

.overlay-screen { position: absolute; inset: 0; z-index: 20; background: rgba(4,8,5,.84); backdrop-filter: blur(16px); }
.result-card { padding: 28px; border-radius: 24px; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.result-emoji { font-size: 58px; margin-bottom: 12px; }
.result-card p { margin: 8px 0 24px; }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 50; max-width: calc(100% - 28px); transform: translate(-50%, 18px); opacity: 0; pointer-events: none; padding: 11px 15px; border-radius: 12px; background: #222c26; box-shadow: 0 16px 45px rgba(0,0,0,.4); transition: .2s ease; font-size: 13px; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #4a2023; }

@media (min-width: 680px) {
  #app { max-width: 520px; margin: 0 auto; box-shadow: 0 0 70px rgba(0,0,0,.45); }
  .table-cards { grid-template-columns: repeat(3, 100px); }
}
