:root {
  --red: #c62f24; --red-d: #8f1d16; --cream: #fff6e4; --ink: #3a2418; --green: #2f8a3c; --gold: #f2b731; --blue: #2c6db3;
  --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: #f4e7cc; color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
body { background: #f4e7cc 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(#d23a2e, #a8241b); color: #fff; box-shadow: 0 3px 0 #7d1a13, 0 4px 12px 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 #7d1a13; }
#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 6px 18px rgba(60,25,5,.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 #d9b98a, 0 3px 10px rgba(80,40,10,.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: #ffe9e4; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 0 4px #c62f2440; } }
#storkCard { display: flex; align-items: flex-end; gap: .4rem; flex: none; }
#stork { width: auto; height: 4.6rem; flex: none; filter: drop-shadow(0 3px 2px rgba(0,0,0,.25)); transition: transform .25s; }
#stork.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 #e5c99c; margin-bottom: .6rem; min-height: 2.4rem; }
#bubble:before { content: ""; position: absolute; left: -9px; bottom: 10px; border: 8px solid transparent; border-right-color: #e5c99c; 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 #d9b98a; }
.pl.turn { border-color: var(--green); background: #effbe9; }
.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, #efe1c4); border: 2px solid #b48a5a; }
.disc.black { background: radial-gradient(circle at 35% 35%, #5c4a42, #1f1714); border: 2px solid #0e0a08; }
.caps { font-size: .78rem; font-weight: 700; color: #7b5a3c; 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 #d0ad7c; 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 #1d5e26; }
.tool:active { transform: translateY(2px); box-shadow: none; }
.tool:disabled { color: #b8a58c; box-shadow: 0 3px 0 #e6d3b4; }
#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 #d9b98a; }
#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; columns: 1; font-variant-numeric: tabular-nums; }
#moves li { padding: 1px 0; }
#moves li span { display: inline-block; min-width: 4.6rem; }
#moves li .last { background: #ffe37a; border-radius: 4px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(70,25,10,.45); }
.overlay.hidden { display: none; }
.panel { background: var(--cream); border-radius: 18px; border: 4px solid #fff; box-shadow: 0 0 0 4px var(--red), 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(#fff6e400, 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: 1.9rem; color: var(--red); text-shadow: 0 2px 0 #fff, 0 3px 0 #e8c79a; line-height: 1.05; }
.brand .sub { margin: .25rem 0 0; font-weight: 700; font-size: .85rem; color: #7b5a3c; }
.intro { font-size: .9rem; line-height: 1.4; margin: .7rem 0 .5rem; }
.keys { font-size: .78rem; color: #6d4c33; }
.k { display: inline-block; background: #fff; border: 1.5px solid #c9a678; 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 #e0c08f; 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: #5d4330; margin: .3rem 0 0; background: #fff; border-radius: 8px; padding: .35rem .5rem; border: 1.5px dashed #e0c08f; }
.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 #cfab79; }
.btn.big { background: linear-gradient(#3aa64a, #2a8037); color: #fff; font-size: 1.25rem; padding: .6rem 2.4rem; box-shadow: 0 4px 0 #1b5a24, 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 #e0c08f; 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: #6d4c33; }
.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; }
  #stork { height: 3.4rem; }
  #main { padding: 6px; gap: 8px; }
}
@media (max-height: 420px) {
  :root { --hh: 32px; }
  #storkCard { 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: 380px) { #top h1 small { display: none; } }
