@font-face { font-family: 'Fraunces'; font-weight: 800; font-display: swap; src: url(../fonts/fraunces-800.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-weight: 300 900; font-display: swap; src: url(../fonts/figtree.woff2) format('woff2'); }

:root {
  --ember: #e2622f;
  --ember-2: #f39a62;
  --gold: #ffd23f;
  --moss: #6f9a3a;
  --ink: #2a2238;
  --ink-2: #1c1726;
  --cream: #fff4de;
  --birch: #f6e3bc;
  --glass: rgba(34, 26, 44, 0.62);
  --glass-2: rgba(34, 26, 44, 0.82);
  --line: rgba(255, 244, 222, 0.16);
  --head: 'Fraunces', Georgia, serif;
  --body: 'Figtree', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink-2); color: var(--cream); font-family: var(--body); -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
button, input, select { font: inherit; color: inherit; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: crosshair; }

/* --- yläpalkki ---------------------------------------------------------------- */
.top { position: fixed; top: calc(var(--safe-t) + 8px); left: 10px; right: 10px; display: flex; align-items: center; gap: 10px; pointer-events: none; z-index: 5; }
.top > * { pointer-events: auto; }
.back { display: inline-flex; align-items: center; gap: 5px; color: var(--cream); text-decoration: none; font-weight: 700; font-size: 14px; padding: 7px 11px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); white-space: nowrap; }
.back:hover { background: var(--glass-2); }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--head); font-weight: 800; font-size: 22px; letter-spacing: 0.01em; text-shadow: 0 2px 8px rgba(30, 10, 30, 0.5); pointer-events: none; }
.brand img { display: block; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35)); }
.tools { margin-left: auto; display: flex; gap: 6px; }
.ib { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: grid; place-items: center; cursor: pointer; padding: 0; }
.ib:hover { background: var(--glass-2); }
.ib:focus-visible, .btn:focus-visible, .sb:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.ib.txt { font-weight: 800; font-size: 13px; letter-spacing: 0.04em; }
.ib.small { width: 34px; height: 34px; border-radius: 10px; }
.ib[disabled] { opacity: 0.35; cursor: default; }

/* --- pistetaulu ---------------------------------------------------------------- */
.board { position: fixed; top: calc(var(--safe-t) + 58px); left: 10px; right: 10px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; z-index: 4; pointer-events: auto; padding-bottom: 4px; }
.board::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-width: 128px; padding: 8px 11px 9px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: transform 0.25s, border-color 0.25s, opacity 0.25s; }
.chip.cur { border-color: var(--ember); box-shadow: 0 0 0 2px rgba(226, 98, 47, 0.35), 0 6px 18px rgba(0, 0, 0, 0.3); transform: translateY(2px); }
.chip.out { opacity: 0.45; }
.chip.won { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255, 210, 63, 0.45); }
.chip.warn .mx i.on { animation: blink 0.9s infinite; }
.chip-top { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; }
.nm { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--birch); opacity: 0.75; }
.sc { font-family: var(--head); font-weight: 800; font-size: 30px; line-height: 1.05; margin-top: 1px; }
.sc.bump { animation: bump 0.6s ease-out; color: #c9f08a; }
.sc.drop { animation: shake 0.6s; color: #ff9a8a; }
.bar { position: relative; height: 5px; border-radius: 3px; background: rgba(255, 244, 222, 0.14); overflow: hidden; margin: 3px 0 5px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--birch); border-radius: 3px; transition: width 0.6s cubic-bezier(.2, .9, .3, 1.3); }
.bar.hot i { background: linear-gradient(90deg, var(--ember-2), var(--gold)); }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.need { opacity: 0.85; }
.mx { display: inline-flex; gap: 3px; }
.mx i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid rgba(255, 244, 222, 0.55); }
.mx i.on { background: #ff6b5a; border-color: #ff6b5a; }

@media (min-width: 900px) and (min-height: 560px) {
  .board { flex-direction: column; right: auto; width: 176px; overflow: visible; top: calc(var(--safe-t) + 66px); }
  .chip { min-width: 0; }
  .chip.cur { transform: translateX(8px); }
}

/* --- banneri, popup, vihje ---------------------------------------------------------- */
.banner { position: fixed; left: 50%; top: calc(var(--safe-t) + 150px); transform: translate(-50%, -8px); opacity: 0; transition: 0.3s; z-index: 3; text-align: center; pointer-events: none; max-width: min(92vw, 520px); }
.banner.show { opacity: 1; transform: translate(-50%, 0); }
.b-main { display: block; font-family: var(--head); font-weight: 800; font-size: 20px; text-shadow: 0 2px 10px rgba(20, 10, 30, 0.7); }
.b-sub { display: block; font-size: 14px; font-weight: 600; opacity: 0.9; text-shadow: 0 1px 6px rgba(20, 10, 30, 0.8); }
@media (min-width: 900px) and (min-height: 560px) { .banner { top: calc(var(--safe-t) + 70px); } }

.popup { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(0.6); opacity: 0; pointer-events: none; z-index: 6; text-align: center; }
.popup.show { animation: pop 1.4s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.pop-main { font-family: var(--head); font-weight: 800; font-size: clamp(44px, 11vw, 96px); line-height: 1; color: var(--cream); text-shadow: 0 4px 0 rgba(60, 20, 10, 0.35), 0 8px 30px rgba(20, 0, 20, 0.5); white-space: nowrap; }
.pop-sub { font-weight: 800; font-size: clamp(16px, 4vw, 24px); margin-top: 6px; text-shadow: 0 2px 8px rgba(20, 0, 20, 0.7); }
.popup.good .pop-main { color: #d8f59a; }
.popup.single .pop-main { color: var(--ember-2); }
.popup.gold .pop-main { color: var(--gold); font-size: clamp(52px, 13vw, 120px); }
.popup.gold { animation-duration: 2.6s; }
.popup.bad .pop-main { color: #ff8a73; }
.popup.miss .pop-main { color: var(--birch); font-size: clamp(36px, 9vw, 72px); }
.popup.turn .pop-main { font-size: clamp(26px, 6vw, 44px); }

.hint { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translateX(-50%); background: var(--glass); padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; opacity: 0; transition: opacity 0.4s; pointer-events: none; z-index: 3; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis; }
.hint.show { opacity: 1; }
.toast { position: fixed; left: 50%; top: 50%; transform: translate(-50%, 20px); background: var(--glass-2); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; opacity: 0; transition: 0.3s; pointer-events: none; z-index: 30; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- ohjauspalkki ---------------------------------------------------------------- */
.controls { position: fixed; left: 10px; right: 10px; bottom: calc(var(--safe-b) + 10px); display: flex; align-items: flex-end; gap: 8px; pointer-events: none; z-index: 4; flex-wrap: wrap; }
.controls > * { pointer-events: auto; }
.controls.locked .seg { opacity: 0.45; pointer-events: none; }
.seg { display: flex; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 3px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: opacity 0.25s; }
.sb { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 8px 10px; border-radius: 11px; cursor: pointer; font-weight: 700; font-size: 13px; min-height: 40px; }
.sb span:empty { display: none; }
.sb[aria-checked="true"] { background: var(--cream); color: var(--ink); }
#spinSeg .sb span { display: none; }
.wind { margin-left: auto; display: flex; align-items: center; gap: 6px; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 0 12px; height: 48px; font-size: 13px; font-weight: 700; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.wind svg { transition: transform 0.5s; color: #bfe3ff; }
.wl { opacity: 0.7; font-weight: 600; }
@media (max-width: 420px) { .sb span { display: none; } .wl { display: none; } .wind { padding: 0 9px; } }

/* --- modaali ---------------------------------------------------------------- */
.modal { position: fixed; inset: 0; background: rgba(18, 12, 26, 0.55); display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity 0.25s; z-index: 20; padding: 14px; }
.modal.open { opacity: 1; pointer-events: auto; }
.sheet { width: min(440px, 100%); max-height: calc(100vh - 28px); overflow: auto; background: linear-gradient(170deg, #3a2c46 0%, #2a2238 60%, #241d31 100%); border: 1px solid var(--line); border-radius: 22px; padding: 22px 20px 18px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); transform: translateY(14px) scale(0.98); transition: transform 0.3s cubic-bezier(.2, 1.2, .4, 1); user-select: text; }
.modal.open .sheet { transform: none; }
.sheet h2 { font-family: var(--head); font-weight: 800; font-size: 30px; margin: 0 0 6px; line-height: 1.1; }
.sheet h2.win { color: var(--gold); }
.sheet h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.7; margin: 18px 0 8px; }
.tag { margin: 0; opacity: 0.8; font-size: 14px; line-height: 1.45; }
.menu-head { display: flex; gap: 14px; align-items: center; margin: -4px 0 4px; }
.menu-head h2 { font-size: 34px; margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: rgba(255, 244, 222, 0.08); padding: 12px 14px; border-radius: 14px; cursor: pointer; font-weight: 700; font-size: 15px; min-height: 46px; transition: background 0.15s, transform 0.1s; }
.btn:hover { background: rgba(255, 244, 222, 0.16); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--ember); border-color: transparent; color: #fff; }
.btn.primary:hover { background: #f0733f; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: 8px; justify-content: flex-start; }
.btn[disabled] { opacity: 0.4; cursor: default; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.stack { display: grid; gap: 8px; margin-top: 14px; }
.lvl:nth-child(1) { border-color: rgba(156, 196, 90, 0.5); }
.lvl:nth-child(2) { border-color: rgba(255, 210, 63, 0.5); }
.lvl:nth-child(3) { border-color: rgba(226, 98, 47, 0.7); }
.foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 13px; opacity: 0.85; }
.rules { margin: 0; padding-left: 20px; line-height: 1.5; font-size: 14.5px; }
.rules li { margin-bottom: 6px; }
.credits { font-size: 12px; opacity: 0.6; margin: 14px 0; }
.plist { display: grid; gap: 8px; margin: 14px 0 10px; }
.prow { display: grid; grid-template-columns: 22px 1fr auto 34px; gap: 6px; align-items: center; }
.pn { font-family: var(--head); font-weight: 800; opacity: 0.6; text-align: center; }
.prow input, .prow select, .nickrow input { min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); padding: 0 10px; }
.prow select { max-width: 160px; }
.prow select option { background: var(--ink); }
.stand { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; counter-reset: s; }
.stand li { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-radius: 12px; background: rgba(255, 244, 222, 0.06); counter-increment: s; }
.stand li::before { content: counter(s) "."; font-family: var(--head); font-weight: 800; opacity: 0.5; margin-right: 10px; }
.snm { flex: 1; font-weight: 700; }
.ssc { font-family: var(--head); font-weight: 800; font-size: 20px; }
.stand li.w { background: rgba(255, 210, 63, 0.16); }
.stand li.w .ssc { color: var(--gold); }
.stand li.o { opacity: 0.55; }
.big { font-size: 17px; font-weight: 700; margin: 10px 0 0; }
.emoji { font-size: 22px; letter-spacing: 2px; margin: 10px 0 0; word-break: break-all; }
.nickrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 14px; }

.embed-link { display: none; position: fixed; right: 8px; bottom: calc(var(--safe-b) + 66px); font-size: 12px; font-weight: 800; color: var(--cream); text-decoration: none; background: var(--glass); padding: 4px 9px; border-radius: 999px; z-index: 5; }
body.embed .embed-link { display: block; }
body.embed .back, body.embed #btnMenu, body.embed #btnLang, body.embed .brand { display: none; }
.noscript { position: fixed; inset: 40% 0 auto; text-align: center; }

@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  22% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -54%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(0.96); }
}
@keyframes bump { 0% { transform: scale(1); } 30% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes blink { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .popup.show { animation: none; opacity: 1; transform: translate(-50%, -50%); } * { transition: none !important; } }
