:root {
  --red: #0e8a4b; --red-d: #075c31; --cream: #fffbea; --ink: #1d2a1f; --green: #1d58b8; --gold: #ffcc1a; --blue: #1d58b8;
  --hh: 44px; --bs: 400px;
  font-size: clamp(11px, min(2.1vh, 3vw) + 4px, 17px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe6ff; color: var(--ink);
  font-family: "Segoe UI", "Trebuchet MS", system-ui, -apple-system, Roboto, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
body { background: #bfe6ff url(img/bg.webp) center / cover; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }

/* header */
#top { height: var(--hh); flex: none; display: flex; align-items: center; gap: .5rem; padding: 0 .6rem;
  background: linear-gradient(#14a159, #0b7a40); color: #fff; box-shadow: 0 3px 0 #ffcc1a, 0 6px 0 #1d58b8, 0 7px 14px rgba(0,0,0,.25);
  border-bottom: 3px solid #fff3; position: relative; z-index: 3; }
#top h1 { flex: 1; margin: 0; font-size: 1.25rem; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 2px 0 #064a27; }
#top h1 small { font-size: .75rem; font-weight: 600; opacity: .9; margin-left: .35rem; background: #ffffff2a; padding: .1rem .45rem; border-radius: 1rem; }
.snd { display: flex; gap: .35rem; }
.icon { width: calc(var(--hh) - 10px); height: calc(var(--hh) - 10px); border-radius: 50%; border: 2px solid #ffffff90; background: #ffffff22; color: #fff; display: grid; place-items: center; padding: 0; }
.icon svg { width: 62%; height: 62%; }
.icon .slash { display: none; }
.icon.off .slash { display: inline; }
.icon.off .wave { display: none; }
.icon:active { transform: scale(.92); }

/* main layout: JS sets --bs and class land/port */
#main { flex: 1; min-height: 0; display: flex; gap: 10px; padding: 8px; justify-content: center; align-items: center; }
#app.port #main { flex-direction: column; justify-content: flex-start; padding-top: 10px; }
#boardCol { flex: none; width: var(--bs); height: var(--bs); }
#boardWrap { position: relative; width: 100%; height: 100%; }
#board { width: 100%; height: 100%; display: block; border-radius: 10px; box-shadow: 0 8px 22px rgba(10,50,25,.45); touch-action: none; outline: none; }
#banner { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); background: #fffdf6f2; color: var(--red-d); font-weight: 800; font-size: 1.3rem;
  padding: .55rem 1.1rem; border-radius: 14px; border: 3px solid var(--red); box-shadow: 0 6px 20px rgba(0,0,0,.3); pointer-events: none; white-space: nowrap; transition: opacity .25s; }
#banner.hidden { opacity: 0; }

#side { flex: none; display: flex; flex-direction: column; gap: 7px; min-height: 0; }
#app.land #side { width: var(--sw); height: var(--bs); }
#app.port #side { width: var(--bs); flex: 1; }
.card { background: var(--cream); border-radius: 12px; box-shadow: 0 2px 0 #cfe0b8, 0 3px 10px rgba(10,50,25,.2); }
#hintLine { background: #fffdf5; border: 2px solid var(--red); border-radius: 10px; padding: .35rem .55rem; font-weight: 700; font-size: .85rem; line-height: 1.25; color: var(--red-d); min-height: 2.1rem; display: flex; align-items: center; }
#hintLine.must { background: #fff6cf; border-color: #ffb000; color: #8a5a00; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 0 4px #ffb00050; } }
#mascotCard { display: flex; align-items: flex-end; gap: .4rem; flex: none; }
#mascot { width: auto; height: 4.6rem; flex: none; filter: drop-shadow(0 3px 2px rgba(0,0,0,.25)); transition: transform .25s; }
#mascot.bounce { animation: bounce .5s; }
@keyframes bounce { 40% { transform: translateY(-8px) rotate(-4deg); } }
#bubble { position: relative; flex: 1; background: #fff; border-radius: 12px; padding: .4rem .6rem; font-size: .82rem; line-height: 1.25; border: 2px solid #cfe0b8; margin-bottom: .6rem; min-height: 2.4rem; }
#bubble:before { content: ""; position: absolute; left: -9px; bottom: 10px; border: 8px solid transparent; border-right-color: #cfe0b8; border-left: 0; }
#players { display: flex; flex-direction: column; gap: 4px; flex: none; }
.pl { display: flex; align-items: center; gap: .45rem; background: var(--cream); border-radius: 10px; padding: .28rem .5rem; border: 2px solid transparent; font-size: .85rem; box-shadow: 0 2px 0 #cfe0b8; }
.pl.turn { border-color: #ffb000; background: #fff8d6; }
.pl b { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.disc { width: 1.05rem; height: 1.05rem; border-radius: 50%; flex: none; }
.disc.white { background: radial-gradient(circle at 35% 35%, #fff, #efe6cc); border: 2px solid #0e8a4b; }
.disc.black { background: radial-gradient(circle at 35% 35%, #5a3a33, #1a0d0b); border: 2px solid #ffcc1a; }
.caps { font-size: .78rem; font-weight: 700; color: #4c6a3a; white-space: nowrap; }
#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; flex: none; }
#app.port #tools { grid-template-columns: repeat(4, 1fr); }
.tool { display: flex; align-items: center; justify-content: center; gap: .3rem; padding: .38rem .3rem; border-radius: 10px; border: 0; background: #fff; box-shadow: 0 3px 0 #c4d6a6; font-weight: 700; font-size: .8rem; color: var(--ink); white-space: nowrap; min-height: 2.1rem; }
.tool svg { width: 1.05rem; height: 1.05rem; flex: none; }
.tool.primary { background: var(--green); color: #fff; box-shadow: 0 3px 0 #123a80; }
.tool:active { transform: translateY(2px); box-shadow: none; }
.tool:disabled { color: #a8b3cc; box-shadow: 0 3px 0 #e2ead2; }
#movesBox { flex: 1; min-height: 0; background: var(--cream); border-radius: 12px; padding: .3rem .5rem; display: flex; flex-direction: column; box-shadow: 0 2px 0 #cfe0b8; }
#movesBox h3 { margin: 0 0 .15rem; font-size: .78rem; color: var(--red-d); text-transform: uppercase; letter-spacing: .5px; }
#moves { margin: 0; padding: 0 0 0 1.8rem; overflow-y: auto; font-size: .8rem; flex: 1; min-height: 0; font-variant-numeric: tabular-nums; }
#moves li { padding: 1px 0; }
#moves li span { display: inline-block; min-width: 4.6rem; }
#moves li .last { background: #ffe58a; border-radius: 4px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(8,48,24,.5); }
.overlay.hidden { display: none; }
.panel { background: var(--cream); border-radius: 18px; border: 4px solid #fff; box-shadow: 0 0 0 4px var(--red), 0 0 0 7px #ffcc1a, 0 0 0 10px #1d58b8, 0 14px 40px rgba(0,0,0,.4); max-width: 720px; width: 100%; max-height: calc(100% - 12px); display: flex; flex-direction: column; overflow: hidden; }
.panel .scroll { overflow-y: auto; min-height: 0; flex: 1; padding: 1rem 1.1rem .6rem; }
.panel .foot { flex: none; display: flex; gap: .6rem; justify-content: center; padding: .6rem 1rem .8rem; background: linear-gradient(#fffbea00, var(--cream) 30%); }
.start .scroll { display: grid; grid-template-columns: 1fr 1.15fr; gap: 1rem; align-items: start; }
.brand { display: flex; align-items: center; gap: .7rem; }
.brand img { height: 6.5rem; width: auto; filter: drop-shadow(0 4px 3px rgba(0,0,0,.25)); }
.brand h2 { margin: 0; font-size: 2.1rem; color: var(--red); text-shadow: 0 2px 0 #fff, 0 3px 0 #ffd84d; line-height: 1.05; }
.brand .sub { margin: .25rem 0 0; font-weight: 700; font-size: .85rem; color: #4c6a3a; }
.intro { font-size: .9rem; line-height: 1.4; margin: .7rem 0 .5rem; }
.keys { font-size: .78rem; color: #3d5530; }
.k { display: inline-block; background: #fff; border: 1.5px solid #a9c48d; border-bottom-width: 3px; border-radius: 6px; padding: 0 .35rem; font-weight: 700; margin: 0 .1rem; }
.grp { margin-bottom: .5rem; }
.lab { display: block; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--red-d); margin-bottom: .2rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.seg.three { grid-template-columns: 1fr 1fr 1fr; }
.seg button { border: 2px solid #cfe0b8; background: #fff; border-radius: 10px; padding: .38rem .25rem; font-weight: 700; font-size: .8rem; line-height: 1.15; }
.seg button.on { background: var(--red); border-color: var(--red-d); color: #fff; box-shadow: inset 0 -3px 0 #0002; }
.varNote { font-size: .76rem; line-height: 1.3; color: #33502a; margin: .3rem 0 0; background: #fff; border-radius: 8px; padding: .35rem .5rem; border: 1.5px dashed #a9c48d; }
.btn { border: 0; border-radius: 14px; padding: .6rem 1.2rem; font-weight: 800; font-size: 1rem; background: #fff; color: var(--ink); box-shadow: 0 4px 0 #c0d49e; }
.btn.big { background: linear-gradient(#ffd83a, #ffb300); color: #3a2a00; font-size: 1.25rem; padding: .6rem 2.4rem; box-shadow: 0 4px 0 #a86f00, 0 6px 14px rgba(0,0,0,.25); }
.btn:active { transform: translateY(3px); box-shadow: none; }
.rules { max-width: 640px; }
.tabs { display: flex; gap: 4px; padding: .7rem .8rem 0; flex: none; }
.tabs button { flex: 1; border: 2px solid #cfe0b8; background: #fff; border-radius: 10px 10px 0 0; padding: .35rem .2rem; font-weight: 700; font-size: .8rem; }
.tabs button.on { background: var(--red); color: #fff; border-color: var(--red-d); }
#rulesText h3 { margin: .2rem 0 .3rem; color: var(--red); font-size: 1.05rem; }
#rulesText ul { margin: 0 0 .5rem; padding-left: 1.2rem; }
#rulesText li { margin: .22rem 0; font-size: .88rem; line-height: 1.35; }
#rulesText p { font-size: .88rem; line-height: 1.4; margin: .3rem 0; }
.end { max-width: 520px; flex-direction: row; align-items: center; padding: .8rem; gap: .6rem; }
.end img { height: 9rem; width: auto; flex: none; }
.endTxt { flex: 1; text-align: center; }
.end h2 { margin: 0; font-size: 1.9rem; color: var(--red); }
.end p { margin: .3rem 0; }
.end .stats { font-size: .8rem; color: #3d5530; }
.foot.row { background: none; padding: .5rem 0 0; flex-wrap: wrap; }

/* short screens (store frame 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  :root { --hh: 36px; }
  #top h1 { font-size: 1.05rem; }
  .panel .scroll { padding: .6rem .8rem .3rem; }
  .brand img { height: 4.6rem; }
  .brand h2 { font-size: 1.45rem; }
  .intro { margin: .4rem 0 .3rem; font-size: .82rem; }
  .grp { margin-bottom: .3rem; }
  .seg button { padding: .26rem .2rem; }
  .panel .foot { padding: .35rem .8rem .5rem; }
  .btn.big { font-size: 1.1rem; padding: .45rem 2rem; }
  .end img { height: 6.5rem; }
  #mascot { height: 3.4rem; }
  #main { padding: 6px; gap: 8px; }
}
@media (max-height: 420px) {
  :root { --hh: 32px; }
  #mascotCard { display: none; }
  .brand img { height: 3.6rem; }
  .varNote { display: none; }
  .end img { height: 5rem; }
}
@media (max-height: 420px) and (max-width: 700px) {
  .keys { display: none; }
}
/* narrow portrait: one column start panel */
@media (max-width: 600px) and (min-height: 561px) {
  .start .scroll { grid-template-columns: 1fr; gap: .4rem; }
  .brand img { height: 5rem; }
  .end { flex-direction: column; }
  .end img { height: 7rem; }
}
@media (max-width: 430px) { #top h1 small { display: none; } }

/* five level buttons with a number + small label */
.seg.five { grid-template-columns: repeat(3, 1fr); }
.seg.five button { display: flex; flex-direction: column; align-items: center; font-size: 1rem; padding: .25rem .1rem; }
.seg.five button small { font-size: .62rem; font-weight: 700; opacity: .85; white-space: nowrap; }
#hintLine { border-color: var(--red); color: var(--red-d); }
@media (max-height: 420px) { .seg.five button { font-size: .9rem; padding: .15rem .1rem; } }
@media (max-width: 420px) { .seg.five button small { font-size: .55rem; } }

.panel { max-height: calc(100% - 26px); }
.brand h2 { letter-spacing: .5px; }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg.two button small { display:block; font-size:.62rem; font-weight:700; opacity:.85; }
.intro strong { color: var(--red-d); }
/* big screens: larger side panel text and mascot */
@media (min-height: 760px) and (min-width: 1300px) { :root { font-size: 19px; } #mascot { height: 6.2rem; } }
@media (min-height: 1000px) and (min-width: 1800px) { :root { font-size: 21px; } }
