:root {
  --bg: #1b110a;
  --bg2: #2a1a0f;
  --ink: #f3e6cc;
  --muted: #bfa982;
  --gold: #d6ae5c;
  --gold2: #b48a3a;
  --hot: #ffd36b;
  --red: #ff5a4e;
  --green: #5ccf7a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(ellipse at top, #3a2414 0%, var(--bg) 70%) fixed;
  background-color: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
#app {
  max-width: 1240px; margin: 0 auto; height: 100%; height: 100dvh;
  display: flex; flex-direction: column;
  padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.bar { display: flex; align-items: center; gap: 10px; padding: 2px 0 8px; }
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 22px; color: var(--gold); letter-spacing: .5px; }
.score { margin: 0 auto; display: flex; gap: 6px; align-items: baseline; white-space: nowrap; background: rgba(0,0,0,.3); border: 1px solid rgba(214,174,92,.35); padding: 3px 12px; border-radius: 20px; color: var(--muted); }
.score b { font-size: 16px; color: #fff; }
.score:empty { visibility: hidden; }
.tools { display: flex; gap: 6px; align-items: center; }
.sel { display: flex; gap: 6px; }
button, select {
  font: inherit; color: var(--ink); background: var(--bg2);
  border: 1px solid rgba(214,174,92,.45); border-radius: 10px; padding: 6px 10px; cursor: pointer;
}
select { padding: 6px 6px; }
button.icon { width: 36px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
button:disabled { opacity: .38; cursor: default; }
button.primary { background: linear-gradient(#e2bd6d, #b48a3a); color: #2a1708; border-color: #f0d08a; font-weight: 700; }
button.secondary { background: rgba(0,0,0,.25); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.game { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
/* Стол: сукно в деревянной раме */
.tableWrap {
  flex: 1; min-height: 0; position: relative; border-radius: 16px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 48%, #2f6b45 0%, #1f4a30 58%, #15331f 100%);
  box-shadow: inset 0 0 0 3px #5b3a22, inset 0 0 0 5px rgba(214,174,92,.35), inset 0 0 50px rgba(0,0,0,.5), 0 12px 40px rgba(0,0,0,.5);
}
#table { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#table.shake { animation: tblShake .42s; }
#table.shakeS { animation: tblShakeS .3s; }
@keyframes tblShake { 0%,100% { transform: none; } 15% { transform: translate(-7px, 3px); } 30% { transform: translate(6px, -4px); } 45% { transform: translate(-5px, -2px); } 60% { transform: translate(4px, 3px); } 80% { transform: translate(-2px, 1px); } }
@keyframes tblShakeS { 0%,100% { transform: none; } 25% { transform: translate(-3px, 1px); } 50% { transform: translate(3px, -1px); } 75% { transform: translate(-2px, 0); } }

/* Нижняя панель: статус и большие кнопки */
.panel { flex: none; display: flex; flex-direction: column; gap: 6px; align-items: stretch; text-align: center; }
.status { min-height: 1.4em; font-size: 15px; font-weight: 600; line-height: 1.3; }
.status.alert { color: #ffcf7a; }
.actions { display: flex; gap: 10px; justify-content: center; }
.actions button.act { min-width: 180px; min-height: 58px; padding: 6px 16px; font-size: 19px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; border-radius: 14px; }
.actions .l1 { font-weight: 800; letter-spacing: .3px; }
.actions .l2 { font-size: 13px; font-weight: 600; opacity: .9; }
.actions .l2:empty { display: none; }
#btnDraw { box-shadow: 0 4px 0 #7d5a1d, 0 8px 18px rgba(0,0,0,.35); }
#btnDraw:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 #7d5a1d; }
#btnDraw.go { animation: drawGlow 1.3s ease-in-out infinite; }
@keyframes drawGlow { 50% { box-shadow: 0 4px 0 #7d5a1d, 0 0 22px 4px rgba(255,211,107,.55); } }
.p-safe { color: #1f5a2e; } .p-mid { color: #6b4300; } .p-risk { color: #8e1a12; }
button.stop { background: linear-gradient(#7a2b22, #4e1913); border-color: #c8584a; color: #ffe9dc; font-weight: 700; box-shadow: 0 4px 0 #2e0d09, 0 8px 18px rgba(0,0,0,.35); }
button.stop.hot { animation: stopHot 1s ease-in-out infinite; }
@keyframes stopHot { 50% { box-shadow: 0 4px 0 #2e0d09, 0 0 20px 4px rgba(255,120,90,.55); } }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 560px; width: 100%; margin: 0 auto; }
.choice button { min-height: 50px; padding: 6px 10px; font-size: 15px; line-height: 1.2; border-radius: 12px; }
.choice button small { display: block; font-size: 12px; font-weight: 600; opacity: .85; }
.choice button.bustw small { color: #ffb4a8; }
.choice button.primary.bustw small { color: #8e1a12; }
.choice .wide { grid-column: 1 / -1; }

/* Плашки поверх стола */
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; pointer-events: none;
  min-width: 230px; max-width: calc(100% - 24px); text-align: center; padding: 12px 22px; border-radius: 16px;
  background: linear-gradient(rgba(42,26,15,.96), rgba(27,17,10,.96)); border: 2px solid var(--gold); color: var(--ink);
  box-shadow: 0 14px 40px rgba(0,0,0,.6), 0 0 0 4px rgba(214,174,92,.15);
  animation: bannerIn .38s cubic-bezier(.2,1.4,.4,1);
}
.banner .bt { font-family: Georgia, serif; font-size: 25px; font-weight: 700; color: var(--hot); line-height: 1.15; }
.banner .bs { font-size: 15px; margin-top: 4px; color: var(--ink); }
.banner.win { border-color: var(--hot); }
.banner.win .bt { text-shadow: 0 0 14px rgba(255,211,107,.6); }
.banner.lose .bt { color: #f3e6cc; }
.banner.gold { border-color: #ffe08a; background: linear-gradient(#5a3d10, #2a1a06); }
.banner.gold .bt { font-size: 30px; color: #ffe9a8; text-shadow: 0 0 18px #ffcf4a; }
.banner.honor { border-color: #c8584a; background: linear-gradient(#4a1a14, #2a0f0b); }
.banner.honor .bt { color: #ffb4a8; }
.banner.small .bt { font-size: 20px; }
@keyframes bannerIn { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.toast {
  position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 8px); z-index: 4;
  max-width: calc(100% - 24px); width: max-content; text-align: center;
  background: rgba(20,12,6,.92); border: 1px solid var(--gold2); color: var(--ink);
  padding: 7px 14px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* SVG-стол */
.igc-edge { fill: none; }
.box { fill: rgba(0,0,0,.22); stroke: rgba(214,174,92,.28); stroke-width: 1.2; }
.seat.turn .box { fill: rgba(60,40,10,.35); stroke: var(--hot); stroke-width: 2.5; animation: turnGlow 1.1s ease-in-out infinite alternate; }
@keyframes turnGlow { from { stroke-opacity: .45; } to { stroke-opacity: 1; } }
.seat.target .box { stroke: var(--green); stroke-width: 3; stroke-dasharray: 7 5; fill: rgba(40,90,50,.28); animation: dash .8s linear infinite; cursor: pointer; }
.seat.target.bustgo .box { stroke: #ff7a5e; fill: rgba(120,30,20,.3); }
@keyframes dash { to { stroke-dashoffset: -24; } }
.seat.bust .box { fill: rgba(90,15,10,.32); stroke: rgba(255,90,78,.5); }
.seat.out { opacity: .45; }
.seat.won .box { stroke: var(--hot); stroke-width: 3.5; fill: rgba(120,90,20,.35); }
.seat.flashR .box { animation: flashR .7s ease-out; }
@keyframes flashR { 0% { fill: rgba(255,60,40,.75); } 100% { fill: rgba(90,15,10,.32); } }
.nm { font-weight: 700; fill: var(--ink); }
.seat.turn .nm { fill: var(--hot); }
.sub { fill: #cdbb95; font-weight: 600; }
.sub.hot { fill: var(--hot); }
.sub.red { fill: #ff8b7e; }
.chipn { font-weight: 800; fill: #fff; }
.sum { font-weight: 900; fill: #f8efd8; text-anchor: middle; font-family: "Arial Black", "Helvetica Neue", Arial, sans-serif; letter-spacing: -1px; paint-order: stroke; stroke: rgba(0,0,0,.45); stroke-width: 3px; }
.sum.zero { fill: rgba(248,239,216,.35); }
.sum.edge { fill: var(--hot); }
.sumg.edge { animation: edgePulse .75s ease-in-out infinite alternate; }
.sum.ochko { fill: #ffe9a8; }
.sumg.ochko { animation: ochkoGlow 1s ease-in-out infinite alternate; }
.sum.bust { fill: var(--red); text-decoration: line-through; }
.sumg { transform-box: fill-box; transform-origin: center; }
.sumg.pop { animation: sumPop .45s cubic-bezier(.2,1.6,.4,1); }
.sumg.edge.pop { animation: sumPop .45s cubic-bezier(.2,1.6,.4,1), edgePulse .75s .45s ease-in-out infinite alternate; }
@keyframes sumPop { 0% { transform: scale(1.7); } 100% { transform: scale(1); } }
@keyframes edgePulse { from { transform: scale(1); } to { transform: scale(1.13); } }
@keyframes ochkoGlow { from { transform: scale(1); filter: drop-shadow(0 0 2px #ffcf4a); } to { transform: scale(1.12); filter: drop-shadow(0 0 10px #ffcf4a); } }
.sumlbl { fill: #cdbb95; font-weight: 700; text-anchor: middle; letter-spacing: .5px; }
.sumlbl.red { fill: #ff8b7e; }
.stampg { transform-box: fill-box; transform-origin: center; }
.stampg.anim { animation: stamp .45s cubic-bezier(.2,1.5,.4,1); }
@keyframes stamp { 0% { transform: scale(2.2) rotate(-8deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.stamp { fill: none; stroke-width: 2.5; }
.stampT { font-weight: 900; text-anchor: middle; letter-spacing: 1px; }
.rubble { filter: brightness(.55) saturate(.5); }
.minusB { fill: #c21f2c; stroke: #fff; stroke-width: 1.5; }
.minusT { fill: #fff; font-weight: 900; text-anchor: middle; }
.potg { transform-box: fill-box; transform-origin: center; }
.potg.bump { animation: potBump .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes potBump { 0% { transform: scale(1); } 35% { transform: scale(1.28) translateY(-6px); } 100% { transform: scale(1); } }
.potn { font-weight: 900; fill: #fff; text-anchor: middle; font-family: "Arial Black", "Helvetica Neue", Arial, sans-serif; paint-order: stroke; stroke: rgba(0,0,0,.5); stroke-width: 3px; }
.potl { fill: var(--gold); font-weight: 800; text-anchor: middle; letter-spacing: 2px; }
.info { fill: #cdbb95; font-weight: 600; text-anchor: middle; }
.info.hot { fill: #ffb4a8; }
.deckg.go { cursor: pointer; }
.deckg.go .deckglow { animation: deckGlow 1.2s ease-in-out infinite alternate; }
.deckglow { fill: none; stroke: var(--hot); stroke-width: 3; opacity: 0; }
@keyframes deckGlow { from { opacity: .15; } to { opacity: .9; } }
.dcnt { fill: #e8d9b8; font-weight: 700; text-anchor: middle; }
.hcard { cursor: pointer; }
.hcard.sel > g > .igc-edge, .hcard.sel .igc-edge { stroke: var(--hot); stroke-width: 4; }
.hcard.dim { opacity: .55; }
.hint { fill: rgba(243,230,204,.55); font-weight: 600; text-anchor: middle; }
.proj { font-weight: 900; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.6); stroke-width: 3px; }
.proj.ok { fill: #9ff0b4; } .proj.bad { fill: #ff8b7e; }
.mark { fill: var(--hot); }

/* Урок */
.tut { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.tutBlock { position: absolute; inset: 0; pointer-events: auto; }
.tutSpot { position: absolute; border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0,0,0,.62); border: 2px solid var(--hot); transition: all .3s; pointer-events: none; }
.tutTip { position: absolute; left: 50%; transform: translateX(-50%); width: min(380px, calc(100% - 24px)); pointer-events: auto;
  background: linear-gradient(#3a2414, #24160c); border: 1px solid var(--gold); border-radius: 16px; padding: 14px 16px; box-shadow: 0 20px 60px rgba(0,0,0,.6); transition: top .3s; }
.tutStep { color: var(--gold); font-size: 13px; font-weight: 700; margin-bottom: 4px; }
#tutText { font-size: 16px; }
#tutText b { color: var(--hot); }
.tutBtns { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.tutBtns button { padding: 9px 16px; font-size: 16px; }
.tutLift { position: relative; z-index: 21; }

/* Модальное окно */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; }
.card { background: linear-gradient(#3a2414, #24160c); border: 1px solid var(--gold2); border-radius: 16px; padding: 18px 20px; max-width: 500px; width: 100%; max-height: 90vh; max-height: 90dvh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.card h2 { margin: 0 0 10px; font-family: Georgia, serif; color: var(--gold); font-size: 22px; }
.card h3 { margin: 14px 0 4px; font-family: Georgia, serif; color: var(--gold); font-size: 17px; }
.card p { margin: 6px 0; }
.rules { padding-left: 18px; margin: 0; } .rules li { margin: 6px 0; }
.modalBtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modalBtns button { padding: 9px 16px; font-size: 16px; }
.big { font-size: 26px; font-weight: 800; color: #fff; }
.hintSmall { color: var(--muted); font-size: 14px; min-height: 1.2em; }
.res { border-collapse: collapse; margin: 8px 0 2px; width: 100%; }
.res td { padding: 4px 0; border-bottom: 1px solid rgba(214,174,92,.18); }
.res td + td { text-align: right; padding-left: 16px; color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
.res tr.me td { color: var(--hot); }
.opt { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; cursor: pointer; }
.opt input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--gold); }
.invLink { width: 100%; font: inherit; font-size: 15px; padding: 10px; margin: 8px 0; border-radius: 10px; border: 1px solid rgba(214,174,92,.45); background: rgba(0,0,0,.35); color: var(--ink); }
.invBtns { display: flex; gap: 8px; } .invBtns button { flex: 1; padding: 10px; font-size: 16px; }

/* Телефон, портрет: шапка в две строки, стол во всю ширину, кнопки под большой палец */
@media (max-width: 560px) {
  #app { padding-left: max(5px, env(safe-area-inset-left)); padding-right: max(5px, env(safe-area-inset-right)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .brand { display: none; }
  .bar { gap: 6px; padding-bottom: 6px; flex-wrap: wrap; }
  .score { margin: 0 auto 0 0; padding: 3px 10px; font-size: 14px; }
  .tools { display: contents; }
  .sel { order: 3; flex-basis: 100%; }
  .sel select { flex: 1; min-width: 0; }
  .tableWrap { border-radius: 12px; }
  .game { gap: 6px; }
  .actions { gap: 8px; }
  .actions button.act { min-width: 0; flex: 1; min-height: 60px; }
  .choice button { font-size: 14px; min-height: 52px; }
  .status { font-size: 14px; min-height: 2.6em; display: flex; align-items: center; justify-content: center; }
  .banner .bt { font-size: 21px; } .banner.gold .bt { font-size: 25px; }
  .banner { padding: 10px 14px; min-width: 200px; }
}
/* Телефон, ландшафт: стол слева, панель с кнопками справа */
@media (orientation: landscape) and (max-height: 540px) {
  #app { max-width: none; padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .bar { padding: 0 0 4px; flex-wrap: nowrap; }
  .brand { display: none; }
  .tools { display: flex; }
  .sel { order: 0; flex-basis: auto; }
  .score { margin: 0 auto 0 0; }
  .game { flex-direction: row; }
  .tableWrap { border-radius: 10px; }
  .panel { width: 200px; justify-content: center; }
  .actions { flex-direction: column; gap: 8px; }
  .actions button.act { min-width: 0; width: 100%; min-height: 54px; flex: none; }
  .choice { grid-template-columns: 1fr; gap: 6px; }
  .choice button { min-height: 40px; font-size: 13px; padding: 4px 8px; }
  .choice .wide { grid-column: auto; }
  .status { font-size: 13px; min-height: 0; }
}
@media (orientation: landscape) and (max-height: 540px) and (max-width: 760px) { .sel select { max-width: 112px; } }
