:root {
  --felt: #12704a; --felt-dark: #0b4a31; --cream: #fbf4e2; --cream-2: #f3e8cc; --ink: #2b2418;
  --gold: #d4a52a; --gold-2: #f3d57a; --cw: 84px; --ch: 116px; --gap: 8px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #fff; background: radial-gradient(ellipse at 50% 30%, #1a8a5c 0%, var(--felt) 45%, var(--felt-dark) 100%);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#app { position: fixed; inset: 0; padding-top: var(--sat); padding-bottom: var(--sab); }
button { font: inherit; border: 0; cursor: pointer; color: inherit; }

/* ---------- home ---------- */
.home { height: 100%; display: flex; flex-direction: column; align-items: center; padding: 16px 18px 12px; overflow: hidden; }
.logo { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 8px 24px rgba(0,0,0,.35); margin-top: 4px; flex-shrink: 0; }
.home h1 { margin: 10px 0 2px; font-size: 34px; letter-spacing: .5px; text-shadow: 0 2px 0 rgba(0,0,0,.25); flex-shrink: 0; }
.home .sub { opacity: .85; margin-bottom: 12px; font-size: 15px; flex-shrink: 0; }
.home .btn-big { flex-shrink: 0; }
.btn-big { background: linear-gradient(#ffd866, #e9a91f); color: #4a2f00; font-weight: 800; font-size: 21px; padding: 16px 30px; border-radius: 18px; box-shadow: 0 5px 0 #a8730d, 0 10px 18px rgba(0,0,0,.3); min-width: 260px; }
.btn-big:active { transform: translateY(3px); box-shadow: 0 2px 0 #a8730d; }
.btn-soft { background: rgba(255,255,255,.14); padding: 10px 18px; border-radius: 14px; font-weight: 600; font-size: 15px; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; max-width: 380px; margin: 14px 0 12px; flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; align-content: start; padding: 2px 2px 10px; }
.lv { aspect-ratio: 1; border-radius: 14px; background: var(--cream); color: var(--ink); font-weight: 800; font-size: 17px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 3px 0 #c9b98f; }
.lv small { font-size: 10px; color: var(--gold); letter-spacing: 1px; height: 12px; }
.lv.locked { background: rgba(255,255,255,.12); color: rgba(255,255,255,.4); box-shadow: none; }
.lv.current { outline: 3px solid var(--gold-2); }
.home .row { display: flex; gap: 10px; flex-shrink: 0; padding-bottom: 4px; }

/* ---------- game ---------- */
.game { height: 100%; display: flex; flex-direction: column; touch-action: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px var(--gap) 2px; height: 44px; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; background: rgba(0,0,0,.2); font-size: 20px; display: flex; align-items: center; justify-content: center; }
.title { font-weight: 800; font-size: 18px; text-shadow: 0 1px 0 rgba(0,0,0,.3); }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.facts-toggle { font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 700; font-size: 18px; width: 34px; height: 34px; border-radius: 50%; background: rgba(0,0,0,.22); color: rgba(255,255,255,.55); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.25); }
.facts-toggle.on { background: linear-gradient(#ffd866, #e9a91f); color: #4a2f00; box-shadow: 0 2px 0 #a8730d, inset 0 0 0 1.5px rgba(255,255,255,.45); }
.progress { font-size: 12px; opacity: .85; text-align: right; min-width: 38px; }
.row1, .row2, .tableau { display: grid; grid-template-columns: repeat(4, var(--cw)); gap: var(--gap); justify-content: center; padding: 0 var(--gap); }
.row1 { margin-top: 6px; height: var(--ch); }
.row2 { margin-top: 6px; height: calc(var(--ch) + 18px); overflow: visible; }
.tableau { margin-top: 14px; flex: 1; min-height: 0; }
.movesbox { width: var(--cw); height: var(--ch); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.banner { background: linear-gradient(#c0392b, #8e2219); border-radius: 10px; padding: 6px 4px 8px; width: 100%; text-align: center; box-shadow: 0 3px 0 #5c140e, 0 6px 12px rgba(0,0,0,.3); }
.banner .n { font-size: 28px; font-weight: 900; line-height: 1; }
.banner .l { font-size: 10px; letter-spacing: 1.5px; font-weight: 700; opacity: .9; }
.banner.low { animation: pulse 1s infinite; }
.waste { grid-column: span 2; position: relative; height: var(--ch); }
.stock { position: relative; width: var(--cw); height: var(--ch); }
.stock .count { position: absolute; right: -4px; top: -6px; background: #fff; color: var(--felt-dark); font-weight: 800; font-size: 12px; min-width: 22px; height: 22px; border-radius: 11px; display: flex; align-items: center; justify-content: center; padding: 0 5px; box-shadow: 0 2px 4px rgba(0,0,0,.3); z-index: 5; }
.stock.empty .recycle { position: absolute; inset: 0; border: 2px dashed rgba(255,255,255,.35); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 30px; opacity: .8; }
.slot { position: relative; width: var(--cw); height: calc(var(--ch) + 18px); border-radius: 10px; overflow: visible; }
.slot > .card { top: 18px; }
.slot.empty { background: transparent; border: none; }
.slot.empty::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: var(--ch); border: 2px dashed rgba(255,255,255,.3); border-radius: 10px; background: rgba(0,0,0,.08); }
.slot.empty::after { content: "♛"; position: absolute; left: 0; right: 0; bottom: 0; height: var(--ch); display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .42); opacity: .28; }
.slot .tab { position: absolute; left: 3px; right: 3px; top: 0; height: 18px; display: flex; align-items: center; justify-content: center; background: linear-gradient(#ffe9a0, #e8b134); color: #5a3a00; font-weight: 800; font-size: calc(var(--cw) * .125); line-height: 1; padding: 0 4px 1px; border-radius: 7px 7px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 -1px 2px rgba(0,0,0,.18); z-index: 4; pointer-events: none; }
.slot .stack-edge { position: absolute; left: 3px; right: -3px; bottom: -3px; height: calc(var(--ch) - 6px); border-radius: 10px; background: var(--cream-2); border: 1px solid #d9caa3; z-index: 0; box-shadow: 0 2px 4px rgba(0,0,0,.18); }
.slot .stack-edge.e2 { left: 5px; right: -5px; bottom: -5px; height: calc(var(--ch) - 8px); background: #efe3c4; }
.col { position: relative; height: 100%; border-radius: 10px; }
.col.emptycol::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: var(--ch); border: 2px dashed rgba(255,255,255,.22); border-radius: 10px; }
.bottombar { display: flex; justify-content: space-around; align-items: center; padding: 6px 68px 16px 16px; height: 84px; }
.tool { position: relative; width: 62px; height: 62px; border-radius: 18px; background: linear-gradient(#fff6dd, #ead9ad); color: var(--ink); font-size: 28px; box-shadow: 0 4px 0 #b8a271, 0 8px 14px rgba(0,0,0,.25); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.tool span { font-size: 10px; font-weight: 800; letter-spacing: .5px; margin-top: -2px; }
#restartBtn span { letter-spacing: 0; font-size: 9px; }
.tool:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8a271; }
.tool[disabled] { opacity: .45; }
.tool .badge { position: absolute; top: -6px; right: -6px; background: #c0392b; color: #fff; border-radius: 11px; min-width: 22px; height: 22px; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; }

/* ---------- cards ---------- */
.card { position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch); border-radius: 10px; background: linear-gradient(170deg, #fffaf0, var(--cream) 60%, var(--cream-2)); color: var(--ink); box-shadow: 0 1px 0 rgba(0,0,0,.15), 0 3px 6px rgba(0,0,0,.25); border: 1px solid #cfc19a; overflow: hidden; will-change: transform; }
.card::after { content: ""; position: absolute; inset: 3px; border: 1.5px solid #fff8e8; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(201, 184, 143, .4); pointer-events: none; z-index: 6; }
.card .lbl { position: absolute; left: 6px; right: 6px; top: 6px; height: calc(var(--ch) * .30); padding: 1px 1px 0; font-weight: 800; font-size: calc(var(--cw) * .135); line-height: 1.15; text-align: center; display: flex; align-items: flex-start; justify-content: center; overflow: hidden; word-break: keep-all; overflow-wrap: normal; hyphens: none; -webkit-hyphens: none; z-index: 2; }
.card .lbl span { display: block; max-width: 100%; text-align: center; word-break: keep-all; overflow-wrap: normal; hyphens: none; -webkit-hyphens: none; }
.card .art { position: absolute; left: 0; right: 0; top: 30%; bottom: 8%; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .5); line-height: 1; }
.card .art.glyph { font-family: "Noto Serif", "DejaVu Serif", "Times New Roman", Times, Georgia, serif; font-weight: 700; font-size: calc(var(--cw) * .52); line-height: 1; }
.card.with-cnt .art { bottom: 20%; }
.card .art.pic { left: 5%; right: 5%; top: 29%; bottom: 5%; }
.card.with-cnt .art.pic { bottom: 19%; }
.card .art.pic svg { width: 100%; height: 100%; display: block; }
.card .cnt { position: absolute; left: 0; right: 0; bottom: 5px; text-align: center; font-weight: 800; font-size: calc(var(--cw) * .13); color: #7a5200; z-index: 2; }
.card .name { position: absolute; left: 6px; right: 6px; top: 8px; bottom: 8px; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 800; font-size: calc(var(--cw) * .24); line-height: 1.15; color: var(--ink); overflow: hidden; word-break: keep-all; overflow-wrap: normal; hyphens: none; -webkit-hyphens: none; z-index: 2; }
.card .name span { display: block; max-width: 100%; text-align: center; word-break: keep-all; overflow-wrap: normal; hyphens: none; -webkit-hyphens: none; }
.card.with-cnt .name { bottom: 22px; }
.card.text-card.covered .name { top: 3px; bottom: auto; height: calc(var(--peek, calc(var(--ch) * .27)) - 5px); left: 5px; right: 5px; align-items: center; justify-content: center; font-size: calc(var(--cw) * .135); line-height: 1.1; }
.card.text-card.covered .name span { white-space: nowrap; overflow: hidden; max-width: 100%; }
.card.cat { background: linear-gradient(170deg, #fff6d6, #f7e3a3); border: 3px solid var(--gold); }
.card.cat::after { inset: 3px; border: 1.5px solid #fff6d0; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(212, 165, 42, .28); }
.card.cat .lbl { color: #7a5200; font-size: calc(var(--cw) * .14); }
.card.cat .crown { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: calc(var(--cw) * .2); color: var(--gold); z-index: 2; }
.card.cat .art { top: 46%; bottom: 22%; font-size: calc(var(--cw) * .36); }
.card.cat .cnt { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-weight: 900; font-size: calc(var(--cw) * .17); color: #7a5200; }
.card.joker { background: linear-gradient(160deg, #f3e6ff, #d9c2ff); border: 2px solid #8e5ad8; }
.card.joker::after { border-color: #f7efff; box-shadow: inset 0 0 0 1px rgba(142, 90, 216, .28); }
.card.joker .lbl { color: #5a2ea6; }
.card.down { background: repeating-linear-gradient(45deg, #1f6fb0 0 6px, #1b62a0 6px 12px); border: 3px solid #fff; }
.card.down::after { border-color: rgba(255,255,255,.35); box-shadow: none; }
.card.down > * { display: none; }
.card.down::after { display: block; }
.card.shake { animation: shake .35s; }
.card.hint, .slot.hint, .col.hint, .stock.hint { animation: glow 0.6s ease-in-out 3; }
.card.hint, .stock.hint .card { box-shadow: 0 0 0 3px #fff35c, 0 0 18px 6px rgba(255,240,90,.8); z-index: 50; }
.slot.hint, .col.hint { box-shadow: 0 0 0 3px #fff35c, 0 0 18px 6px rgba(255,240,90,.6); }
.ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 1000; }
.ghost .card { box-shadow: 0 10px 24px rgba(0,0,0,.45); }
.lifted { opacity: 0 !important; }
.slot .done { position: absolute; left: -10px; right: -10px; top: 8px; bottom: -10px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 24px; color: #fff35c; text-shadow: 0 2px 0 #7a5200, 0 0 12px rgba(0,0,0,.4); animation: donepop 1.3s forwards; z-index: 60; pointer-events: none; }
.toast { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(0,0,0,.72); padding: 12px 18px; border-radius: 14px; font-weight: 700; z-index: 2000; animation: fade 1.6s forwards; pointer-events: none; text-align: center; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 3000; padding: 20px; animation: fadein .2s; }
.modal { background: var(--cream); color: var(--ink); border-radius: 22px; padding: 22px 20px 20px; width: 100%; max-width: 340px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.5); border: 4px solid var(--gold); }
.modal h2 { margin: 0 0 6px; font-size: 26px; }
.modal p { margin: 6px 0 14px; line-height: 1.4; font-size: 15px; }
.modal .stars { font-size: 38px; letter-spacing: 4px; margin: 4px 0 10px; color: var(--gold); }
.modal .stars .off { color: #d5c9a8; }
.modal .btns { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.modal .btns .btn-soft { background: #e8dcbc; color: var(--ink); min-width: 200px; }
.modal ul { text-align: left; padding-left: 20px; margin: 6px 0 14px; font-size: 14px; line-height: 1.45; }

@keyframes shake { 0%,100% { translate: 0 } 25% { translate: -6px 0 } 75% { translate: 6px 0 } }
@keyframes glow { 50% { filter: brightness(1.25); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes donepop { 0% { transform: scale(.4); opacity: 0 } 25% { transform: scale(1.15); opacity: 1 } 80% { opacity: 1 } 100% { transform: scale(1) translateY(-20px); opacity: 0 } }
@keyframes fade { 0% { opacity: 0 } 15% { opacity: 1 } 80% { opacity: 1 } 100% { opacity: 0 } }
@keyframes fadein { from { opacity: 0 } }
/* waste fan: cards underneath show their name vertically on the visible strip */
.card.fan .lbl, .card.fan .name { writing-mode: vertical-rl; transform: rotate(180deg); top: 0; bottom: 0; left: 0; right: auto; height: auto; width: calc(var(--cw) * .4); padding: 6px 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .12); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.fan .lbl span, .card.fan .name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: none; }
.card.fan .art, .card.fan .crown, .card.fan .cnt { display: none; }
/* selected card / run: lifted with a gold ring */
.card.selected { translate: 0 -7px; box-shadow: 0 0 0 3px #ffd84a, 0 10px 18px rgba(0,0,0,.4); }

/* ---------- Learn About (card facts) ---------- */
.card .fact-i { position: absolute; right: 5px; bottom: 5px; width: 16px; height: 16px; border-radius: 50%; background: #2a6aa8; color: #fff; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 700; font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center; padding: 0 0 1px; z-index: 7; border: 1px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); cursor: pointer; }
.card.with-cnt .fact-i { bottom: 18px; }
.fact-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 2500; padding: 20px; animation: fadein .15s; }
.fact-pop { position: relative; background: var(--cream); color: var(--ink); border-radius: 18px; padding: 18px 16px 16px; width: 100%; max-width: 300px; text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,.45); border: 3px solid var(--gold); -webkit-user-select: text; user-select: text; }
.fact-pop h2 { margin: 0 0 8px; font-size: 20px; line-height: 1.2; }
.fact-pop .fact-text { margin: 0 0 14px; line-height: 1.4; font-size: 14px; text-align: left; }
.fact-close { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 16px; background: #e8dcbc; color: var(--ink); font-size: 22px; line-height: 1; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.fact-art { width: 86px; height: 86px; margin: 4px auto 8px; display: flex; align-items: center; justify-content: center; }
.fact-art .art { position: static; font-size: 64px; line-height: 1; }
.fact-art .art.pic { width: 100%; height: 100%; }
.fact-art .art.pic svg { width: 100%; height: 100%; display: block; }
.fact-more { display: inline-block; background: linear-gradient(#ffd866, #e9a91f); color: #4a2f00; font-weight: 800; font-size: 15px; padding: 10px 16px; border-radius: 14px; text-decoration: none; box-shadow: 0 3px 0 #a8730d; }
.fact-more:active { transform: translateY(2px); box-shadow: 0 1px 0 #a8730d; }
