:root {
  --plum: #2c1638; --plum2: #3d2150; --plum3: #563070; --ink: #2c1638; --cream: #fbf3e2; --cream2: #f3e6c8;
  --line: #b9d3ea; --red: #e86a6a;
  --l1: #23b0a0; --l2: #f58a2e; --l3: #e8537d; --l4: #3a86f0;
  --gold: #ffd166; --txt: #fff7ea; --muted: #d7c3e3;
  font-size: clamp(11px, calc(min(2.15vh, 1.55vw) + 4px), 21px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--plum); }
body { font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", system-ui, sans-serif; color: var(--txt); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--plum) url(img/bg_wide.jpg) center / cover no-repeat; }
@media (orientation: portrait) { #app { background-image: url(img/bg_tall.jpg); } }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
.hide { display: none !important; }
kbd { display: inline-block; min-width: 1.6em; padding: .05em .35em; border-radius: .35em; background: var(--cream); color: var(--ink); font: 700 .78rem/1.35 inherit; font-family: inherit; text-align: center; box-shadow: 0 2px 0 #b9a27c; margin: 0 .1em; }

/* header */
#top { position: relative; z-index: 25; flex: none; display: flex; align-items: center; gap: .6rem; padding: .45rem .8rem; background: rgba(28, 12, 38, .55); backdrop-filter: blur(3px); border-bottom: 2px solid rgba(255, 209, 102, .25); }
.logo { display: flex; align-items: center; gap: .4rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.15rem; letter-spacing: .02em; white-space: nowrap; }
.logo img { height: 1.9rem; width: auto; }
.logo b { color: var(--gold); }
#modeTag { flex: 1; min-width: 0; text-align: center; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb { display: flex; gap: .3rem; }
.ib { width: 2.3rem; height: 2.3rem; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: var(--cream); }
.ib:hover { background: rgba(255, 255, 255, .2); }
.ib svg { width: 1.3rem; height: 1.3rem; }
.ib .slash { display: none; }
.ib.off .slash { display: inline; }
.ib.off .wave { display: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .6em 1.2em; border-radius: 999px; font-weight: 800; font-size: 1rem; letter-spacing: .02em; transition: transform .1s, background .15s, opacity .15s; }
.btn:active { transform: scale(.96); }
.btn.go { background: var(--gold); color: var(--ink); box-shadow: 0 .22em 0 #c9962c; }
.btn.go:disabled { background: #9d8aa8; color: #e9dcef; box-shadow: 0 .22em 0 #6f5d7a; cursor: default; }
.btn.ghost { background: rgba(255, 255, 255, .1); border: 2px solid rgba(255, 247, 234, .55); color: var(--txt); }
.btn.ghost:hover { background: rgba(255, 255, 255, .18); }
.btn.big { font-size: 1.25rem; padding: .7em 1.6em; }

/* play layout */
.screen { flex: 1; min-height: 0; display: flex; }
#play { flex-direction: row; gap: 1.1rem; padding: .9rem 1.2rem; align-items: stretch; }
#boardWrap { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
#board { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: .55rem; width: 100%; height: 100%; max-width: 62rem; }
#side { flex: none; width: 13.5rem; display: flex; flex-direction: column; justify-content: center; gap: .8rem; background: rgba(28, 12, 38, .72); border-radius: 1rem; padding: .9rem .8rem; align-self: center; box-shadow: 0 .5rem 1.4rem rgba(0, 0, 0, .3); }
.tip { font-size: .95rem; color: var(--muted); text-align: center; line-height: 1.3; }
.lives { display: flex; flex-direction: column; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); }
#dots { display: flex; gap: .45rem; }
#dots i { width: 1rem; height: 1rem; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px rgba(255, 255, 255, .25); transition: transform .3s, background .3s; }
#dots i.gone { background: rgba(255, 255, 255, .15); transform: scale(.7); }
.acts { display: flex; flex-direction: column; gap: .5rem; }
.acts .btn { width: 100%; }
.sideMascot { width: 7rem; align-self: center; filter: drop-shadow(0 .3rem .5rem rgba(0, 0, 0, .35)); transition: transform .3s; }
.sideMascot.hop { animation: hop .6s; }
@keyframes hop { 30% { transform: translateY(-.8rem) rotate(-6deg); } 60% { transform: translateY(0) rotate(4deg); } }

/* cards */
.card { position: relative; display: flex; align-items: center; justify-content: center; padding: .2rem .3rem; border-radius: .55rem; background: var(--cream);
  background-image: linear-gradient(var(--red), var(--red)), repeating-linear-gradient(transparent 0 calc(1.15rem - 1px), var(--line) calc(1.15rem - 1px) 1.15rem);
  background-size: 100% 2px, 100% 100%; background-position: 0 .55rem, 0 .55rem; background-repeat: no-repeat, no-repeat;
  color: var(--ink); font-weight: 800; letter-spacing: .03em; text-align: center; line-height: 1.05; box-shadow: 0 .2rem 0 #cdb98f, 0 .35rem .7rem rgba(0, 0, 0, .28);
  transition: transform .14s, box-shadow .14s, background-color .14s; min-width: 0; min-height: 0; overflow: hidden; white-space: nowrap; }
.card:hover { transform: translateY(-2px); }
.card.sel { background-color: #ffe2a8; transform: translateY(-4px) rotate(-1.2deg); box-shadow: 0 0 0 .2rem var(--gold), 0 .45rem .9rem rgba(0, 0, 0, .35); }
.card.sel::after { content: ""; position: absolute; top: .25rem; right: .3rem; width: .55rem; height: .55rem; border-radius: 50%; background: var(--l3); box-shadow: 0 0 0 2px #fff; }
.card.cur { outline: .2rem dashed #fff; outline-offset: .15rem; }
.card.shake { animation: shake .4s; }
.card.jump { animation: jump .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes jump { 40% { transform: translateY(-10px) scale(1.04); } }
.band { grid-column: 1 / -1; border-radius: .65rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; color: #fff; text-align: center; box-shadow: 0 .2rem 0 rgba(0, 0, 0, .25); min-height: 0; overflow: hidden; padding: .15rem .5rem; position: relative; }
.band.fresh { animation: bandIn .45s ease-out; }
.band b { font-size: 1.05rem; letter-spacing: .03em; text-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.band span { font-size: .85rem; font-weight: 700; opacity: .95; }
.band .lvtag { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); font-size: .7rem; font-weight: 800; background: rgba(255, 255, 255, .25); padding: .1rem .45rem; border-radius: 999px; }
.band.l1, .lv.l1 { background: var(--l1); }
.band.l2, .lv.l2 { background: var(--l2); }
.band.l3, .lv.l3 { background: var(--l3); }
.band.l4, .lv.l4 { background: var(--l4); }
.lv { color: #fff; padding: 0 .4em; border-radius: .3em; font-weight: 700; }
@keyframes bandIn { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* toast + fx */
#toast { position: fixed; left: 50%; top: 4.2rem; transform: translateX(-50%) translateY(-1rem); background: var(--cream); color: var(--ink); font-weight: 800; padding: .5rem 1.1rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; box-shadow: 0 .3rem .8rem rgba(0, 0, 0, .3); white-space: nowrap; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
#fx i { position: absolute; width: .6rem; height: .9rem; border-radius: 2px; animation: conf 1.6s ease-in forwards; }
@keyframes conf { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); opacity: .9; } }

/* overlays */
.ov { position: fixed; inset: 0; top: var(--hdr, 3rem); z-index: 20; display: flex; align-items: center; justify-content: center; padding: .8rem; background: rgba(24, 9, 33, .6); }
.ov.guard { pointer-events: none; }
.panel { position: relative; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; background: linear-gradient(#45255a, #33193f); border: 2px solid rgba(255, 209, 102, .4); border-radius: 1.2rem; padding: 1.1rem 1.4rem; box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, .45); }
.panel h2 { margin: 0 0 .5rem; font-family: Georgia, serif; font-size: 1.5rem; color: var(--gold); text-align: center; }
.panel h3 { margin: .6rem 0 .2rem; font-size: 1rem; color: var(--gold); }
.scroll { overflow-y: auto; min-height: 0; flex: 1 1 auto; padding-right: .3rem; }
.scroll ul { margin: 0; padding-left: 1.2rem; line-height: 1.45; }
.pfoot { flex: none; display: flex; gap: .6rem; justify-content: center; align-items: center; margin-top: .8rem; }
.pfoot.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.startp { flex-direction: row; gap: 1.6rem; align-items: center; width: 50rem; }
.sl { flex: 1.1; text-align: center; }
.sr { flex: 1; display: flex; flex-direction: column; gap: .55rem; align-items: stretch; }
.mascot { width: 9rem; filter: drop-shadow(0 .4rem .6rem rgba(0, 0, 0, .4)); }
.mascot.sm { width: 5rem; align-self: center; margin-bottom: -.2rem; }
.startp h1 { margin: .2rem 0 .4rem; font-family: Georgia, serif; font-size: 2.1rem; line-height: 1.1; }
.startp h1 b { color: var(--gold); }
.startp h1 i { display: inline-block; font-size: .55em; background: var(--l3); padding: .1em .5em; border-radius: 999px; vertical-align: middle; font-style: normal; font-family: inherit; }
.intro { margin: 0; line-height: 1.4; font-size: .95rem; color: var(--muted); }
.sub { text-align: center; font-size: .85rem; color: var(--muted); margin-top: -.2rem; }
.row2 { display: flex; gap: .5rem; }
.row2 .btn { flex: 1; padding-left: .6em; padding-right: .6em; }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem .8rem; font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.streak { text-align: center; font-size: .85rem; color: var(--gold); min-height: 1em; }
.helpp { width: 40rem; }
.archp { width: 44rem; height: 100%; max-height: 34rem; }
.archp > p { text-align: center; margin: -.2rem 0 .5rem; font-size: .85rem; }
#archGrid { padding-top: .6rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(4.2rem, 1fr)); gap: .45rem; align-content: start; }
.ap { position: relative; height: 3.2rem; border-radius: .6rem; background: var(--cream); color: var(--ink); font-weight: 800; font-size: 1rem; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ap small { font-size: .62rem; font-weight: 700; color: #7b6688; }
.ap.won { background: #c9f0e7; }
.ap.lost { background: #f7d2db; }
.ap.today { box-shadow: 0 0 0 .2rem var(--gold), 0 0 1rem rgba(255, 209, 102, .7); }
.ap .badge { position: absolute; top: -.45rem; left: 50%; transform: translateX(-50%); background: var(--gold); color: var(--ink); font-size: .58rem; padding: .05rem .35rem; border-radius: 999px; white-space: nowrap; }
.resp { width: 30rem; align-items: center; text-align: center; overflow: auto; }
.resp p { margin: 0 0 .4rem; color: var(--muted); }
#resGrid { font-size: 1.25rem; line-height: 1.25; letter-spacing: .12em; margin: .2rem 0 .4rem; }
.statsRow { display: flex; gap: 1.1rem; justify-content: center; }
.statsRow div { display: flex; flex-direction: column; font-size: .7rem; color: var(--muted); }
.statsRow b { font-size: 1.3rem; color: var(--txt); }
.setp { width: 30rem; }
.setp > p { margin: 0 0 .6rem; text-align: center; font-size: .9rem; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin: .3rem 0; font-weight: 700; }
.seg { display: flex; background: rgba(0, 0, 0, .25); border-radius: 999px; padding: .2rem; }
.seg button { padding: .35em .9em; border-radius: 999px; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--gold); color: var(--ink); }
#names { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .5rem; margin: .2rem 0 .3rem; }
#names input, #pList input { font: inherit; font-weight: 700; border: 2px solid transparent; border-radius: .5rem; padding: .3rem .5rem; background: var(--cream); color: var(--ink); min-width: 0; width: 100%; user-select: text; -webkit-user-select: text; }
#names input:focus, #pList input:focus { outline: none; border-color: var(--gold); }
.passp { width: 26rem; align-items: center; text-align: center; }
.passp p { margin: 0; }
.bigLetter { width: 5rem; height: 5rem; border-radius: 1rem; background: var(--cream); color: var(--ink); font: 800 3.4rem/5rem Georgia, serif; text-align: center; margin-bottom: .5rem; box-shadow: 0 .3rem 0 #cdb98f; }
.bigLetter.roll { animation: roll .7s; }
@keyframes roll { 0% { transform: rotateX(0); } 100% { transform: rotateX(720deg); } }

/* party */
#party { flex-direction: column; padding: .7rem 1rem; }
#pRound, #pReview { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 60rem; margin: 0 auto; background: rgba(28, 12, 38, .55); border-radius: 1rem; padding: .7rem .9rem; }
.phead { flex: none; display: flex; align-items: center; gap: .9rem; }
.letterBox { width: 3.6rem; height: 3.6rem; border-radius: .8rem; background: var(--cream); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; box-shadow: 0 .25rem 0 #cdb98f; }
.letterBox small { font-size: .55rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #8a7398; }
.letterBox b { font: 800 2.1rem Georgia, serif; }
.pwho { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pwho b { font-size: 1.15rem; }
.pwho span { font-size: .8rem; color: var(--muted); }
.timer { width: 3.6rem; height: 3.6rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; background: conic-gradient(var(--l1) var(--p, 100%), rgba(255, 255, 255, .12) 0); position: relative; }
.timer::before { content: ""; position: absolute; inset: .3rem; border-radius: 50%; background: #2d1739; }
.timer { isolation: isolate; }
.timer::before { z-index: -1; }
.timer.low { background: conic-gradient(var(--l3) var(--p, 100%), rgba(255, 255, 255, .12) 0); animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.07); } }
.ptip { flex: none; font-size: .8rem; color: var(--muted); margin: .4rem 0; }
#pList { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: min-content; gap: .4rem .9rem; align-content: start; }
.prow { display: flex; flex-direction: column; gap: .12rem; }
.prow label { font-size: .78rem; font-weight: 700; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow label i { font-style: normal; color: var(--muted); margin-right: .3em; }
#rTable { flex: 1; min-height: 0; overflow: auto; margin-top: .5rem; }
#rTable table { border-collapse: separate; border-spacing: .3rem .25rem; width: 100%; font-size: .85rem; }
#rTable th { text-align: left; color: var(--gold); font-weight: 800; white-space: nowrap; }
#rTable td.cat { color: var(--muted); font-weight: 700; white-space: nowrap; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.ans { display: inline-block; min-width: 3rem; padding: .2rem .5rem; border-radius: .45rem; background: var(--cream); color: var(--ink); font-weight: 700; cursor: pointer; }
.ans.ok::after { content: " +1"; color: var(--l1); font-weight: 800; }
.ans.bad { background: #6c4b7b; color: #d4bfe0; text-decoration: line-through; }
.ans.dup { background: #d9c7a0; }
.ans.dup::after { content: " same"; font-size: .7em; color: #7b5a2b; }
.ans.empty { background: transparent; color: var(--muted); cursor: default; }
#rTotals { font-weight: 800; color: var(--gold); margin-right: auto; }
#finList { display: flex; flex-direction: column; gap: .35rem; width: 100%; margin: .3rem 0; }
.frow { display: flex; justify-content: space-between; padding: .4rem .8rem; border-radius: .6rem; background: rgba(255, 255, 255, .08); font-weight: 800; }
.frow.win { background: var(--gold); color: var(--ink); }

/* portrait / narrow: board above controls */
@media (max-aspect-ratio: 5/4) {
  #play { flex-direction: column; padding: .7rem .7rem; gap: .6rem; }
  #side { width: 100%; align-self: stretch; padding: .5rem .6rem; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: .5rem .8rem; }
  .tip { width: 100%; order: -1; }
  .lives { flex-direction: row; gap: .6rem; width: 100%; justify-content: center; }
  .acts { flex-direction: row; width: 100%; }
  .acts .btn { flex: 1; padding-left: .4em; padding-right: .4em; }
  .sideMascot { display: none; }
  #board { gap: .4rem; max-height: 125vw; }
  .startp { flex-direction: column; gap: .7rem; width: 26rem; }
  .sr { width: 100%; }
  #pList { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .logo span { display: none; }
  #modeTag { text-align: left; }
  .mascot { width: 6.5rem; }
  .startp h1 { font-size: 1.8rem; }
}
/* short windows (store frame 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  #top { padding: .25rem .7rem; }
  .ib { width: 2rem; height: 2rem; }
  #play { padding: .55rem .9rem; gap: .9rem; }
  .sideMascot { width: 5rem; }
  .mascot { width: 6.5rem; }
  .startp { width: 46rem; padding: .9rem 1.2rem; }
  .startp h1 { font-size: 1.8rem; }
  .panel h2 { font-size: 1.3rem; margin-bottom: .3rem; }
  .pfoot { margin-top: .5rem; }
}
@media (max-height: 420px) {
  .sideMascot { display: none; }
  .mascot { width: 5rem; }
  .mascot.sm { display: none; }
  .keys { display: none; }
  #side { gap: .55rem; }
  .bigLetter { width: 4rem; height: 4rem; font-size: 2.6rem; line-height: 4rem; }
}
