:root {
  --ink: #22304c; --ink2: #5a6478; --cream: #fbf4e3; --paper: #fffdf7;
  --g: #1f56b5; --p: #e0663a; --a: #a89b7f; --line: #d8cbaa; --lemon: #ffd23f;
  --tile: 56px; --kh: 54px; --kw: 40px;
  font-size: clamp(12px, calc(min(1.9vh, 1.5vw) + 5px), 17px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink);
  background: var(--cream) url(img/bg.webp) repeat; background-size: 360px; touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
body::before { content: ""; position: fixed; inset: 0; background: rgba(251, 244, 227, .86); pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
.hidden { display: none !important; }
#app { position: relative; height: 100%; display: flex; flex-direction: column; max-width: 1200px; margin: 0 auto; }

/* ---------- header ---------- */
#top { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; flex-wrap: wrap; border-bottom: 2px solid rgba(31, 86, 181, .15); }
#brand { display: flex; align-items: center; gap: .35rem; flex: 1 1 auto; min-width: 0; }
#brand img { width: 1.9rem; height: auto; }
#brand b { font-family: Georgia, "Times New Roman", serif; font-size: 1.55rem; color: var(--g); letter-spacing: .02em; }
#brand small { font-size: .8rem; color: var(--p); font-weight: 700; white-space: nowrap; }
#tabs { display: flex; gap: .25rem; background: rgba(31, 86, 181, .08); border-radius: 999px; padding: .2rem; }
.tab { padding: .38rem .8rem; border-radius: 999px; font-weight: 700; font-size: .9rem; color: var(--ink2); white-space: nowrap; }
.tab.on { background: var(--g); color: #fff; box-shadow: 0 2px 0 #143c85; }
#icons { display: flex; gap: .15rem; flex: 1 1 auto; justify-content: flex-end; }
.ib { width: 2.3rem; height: 2.3rem; border-radius: 50%; display: grid; place-items: center; color: var(--g); }
.ib:hover { background: rgba(31, 86, 181, .1); }
.ib svg { width: 1.35rem; height: 1.35rem; }

/* ---------- main ---------- */
#main { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; z-index: 1; }
#play { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: .4rem .6rem 0; }
#headline { width: 100%; max-width: 560px; display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 2.2rem; }
#hlText { display: flex; flex-direction: column; min-width: 0; }
#hlText b { font-size: 1.05rem; }
#hlText span { font-size: .8rem; color: var(--ink2); }
#hlTools { display: flex; gap: .4rem; align-items: center; }
.seg { display: flex; background: #fff; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { padding: .2rem .7rem; font-weight: 800; color: var(--ink2); }
.seg button.on { background: var(--p); color: #fff; }
#clueCard { width: 100%; max-width: 560px; margin-top: .35rem; display: flex; align-items: center; gap: .5rem; background: var(--paper); border: 2px solid var(--line); border-radius: 14px; padding: .35rem .6rem; box-shadow: 0 3px 0 rgba(0, 0, 0, .06); }
#clueCard img { width: 1.9rem; height: auto; flex: none; }
#clueCard p { margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.25; }
#boardBox { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; padding: .35rem 0; }
#board { display: grid; gap: calc(var(--tile) * .1); }
.row { display: grid; grid-auto-flow: column; gap: calc(var(--tile) * .1); }
.row.shake { animation: shake .4s; }
.t {
  width: var(--tile); height: var(--tile); display: grid; place-items: center; background: var(--paper);
  border: 2px solid var(--line); border-radius: calc(var(--tile) * .18); font-weight: 800; font-size: calc(var(--tile) * .52);
  text-transform: uppercase; color: var(--ink); box-shadow: 0 3px 0 rgba(0, 0, 0, .07); transition: border-color .1s;
}
.t.f { border-color: #7c8aa6; animation: pop .12s; }
.t.g, .t.p, .t.a { color: #fff; border-color: transparent; }
.t.g { background: var(--g); box-shadow: 0 3px 0 #143c85; }
.t.p { background: var(--p); box-shadow: 0 3px 0 #a9461f; }
.t.a { background: var(--a); box-shadow: 0 3px 0 #7d7159; }
.t.flip { animation: flip .5s ease; }
.t.win { animation: hop .5s ease; }
.ex .t { --tile: 2.4rem; }
@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes hop { 40% { transform: translateY(-30%); } 70% { transform: translateY(5%); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- keyboard ---------- */
#kbBox { padding: .3rem .4rem .5rem; display: flex; justify-content: center; }
#kb { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: calc(var(--kh) * .14); }
.kr { display: flex; justify-content: center; gap: .3rem; }
.k {
  flex: 1 1 0; max-width: var(--kw); height: var(--kh); border-radius: .5rem; background: #fff; border: 2px solid var(--line);
  font-weight: 800; font-size: max(13px, calc(var(--kh) * .36)); text-transform: uppercase; box-shadow: 0 3px 0 rgba(0, 0, 0, .1);
  display: grid; place-items: center;
}
.k.wide { flex: 1.6 1 0; max-width: calc(var(--kw) * 1.65); font-size: max(11px, calc(var(--kh) * .27)); }
.k.wide svg { width: 1.5em; height: 1.5em; }
.k:active, .k.press { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .1); }
.k.g { background: var(--g); color: #fff; border-color: var(--g); }
.k.p { background: var(--p); color: #fff; border-color: var(--p); }
.k.a { background: #d9d0bb; color: #8a7f68; border-color: #d9d0bb; }
.k.enter { background: var(--lemon); border-color: #e6b600; }

/* side by side (short landscape frames) */
body.side #main { flex-direction: row; }
body.side #play { flex: 1.15; padding-top: .2rem; }
body.side #kbBox { flex: 1; align-items: center; padding: .4rem .6rem .4rem .2rem; }
body.side #headline, body.side #clueCard { max-width: none; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff;
  padding: .55rem 1rem; border-radius: 12px; font-weight: 800; font-size: 1rem; box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  animation: tin .2s ease; pointer-events: none; max-width: 90vw; text-align: center;
}
@keyframes tin { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 3vh 3vw; background: rgba(34, 48, 76, .45); }
.panel {
  position: relative; background: var(--paper); border-radius: 20px; border: 3px solid var(--g); box-shadow: 0 10px 0 rgba(20, 60, 133, .35);
  width: min(30rem, 96vw); max-height: 94vh; display: flex; flex-direction: column; padding: 1rem 1.1rem; animation: pin .25s ease;
}
@keyframes pin { from { transform: scale(.92); opacity: 0; } }
.pScroll { overflow: auto; min-height: 0; flex: 1; }
.pFoot { padding-top: .6rem; display: flex; justify-content: center; gap: .6rem; flex: none; }
.panel h1, .panel h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; color: var(--g); }
.panel h1 { font-size: 2.6rem; line-height: 1; }
.panel h2 { font-size: 1.5rem; }
.panel p { margin: .45rem 0; line-height: 1.35; }
.sm { font-size: .85rem; color: var(--ink2); }
.btn {
  background: var(--g); color: #fff; font-weight: 800; padding: .6rem 1.2rem; border-radius: 999px; box-shadow: 0 4px 0 #143c85;
  font-size: 1rem; white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #143c85; }
.btn.alt { background: var(--p); box-shadow: 0 4px 0 #a9461f; }
.btn.small { padding: .3rem .8rem; font-size: .85rem; box-shadow: 0 3px 0 #143c85; }
.btn.big { font-size: 1.15rem; padding: .75rem 1.4rem; width: 100%; margin-top: .3rem; }
.xbtn { position: absolute; right: .4rem; top: .3rem; font-size: 1.8rem; line-height: 1; width: 2.2rem; height: 2.2rem; color: var(--ink2); z-index: 2; }

.startPanel { width: min(46rem, 96vw); flex-direction: row; align-items: center; gap: 1.2rem; padding: 1.2rem 1.4rem; }
.limoBig { width: 9.5rem; height: auto; flex: none; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.startBody { flex: 1; min-width: 0; overflow: auto; }
.tag { color: var(--p); font-weight: 800; margin: .1rem 0 0 !important; font-size: 1.05rem; }
.intro { font-size: .95rem; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .85rem; color: var(--ink2); margin: .2rem 0 .5rem; }
.legend span { display: flex; align-items: center; gap: .3rem; }
.lg { width: 1rem; height: 1rem; border-radius: 4px; display: inline-block; }
.lg.g { background: var(--g); } .lg.p { background: var(--p); } .lg.a { background: var(--a); }
.modes { display: flex; gap: .5rem; margin-top: .7rem; }
.modeBtn { flex: 1; text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: .45rem .7rem; box-shadow: 0 3px 0 rgba(0, 0, 0, .07); }
.modeBtn b { display: block; color: var(--g); font-size: .95rem; }
.modeBtn small { color: var(--ink2); font-size: .78rem; }
.ctl { display: flex; flex-wrap: wrap; gap: .3rem .8rem; margin-top: .6rem; font-size: .78rem; color: var(--ink2); }
kbd { display: inline-block; min-width: 1.4rem; padding: .05rem .3rem; border-radius: 5px; background: #fff; border: 1.5px solid var(--line); border-bottom-width: 3px; font: 700 .75rem/1.3 inherit; text-align: center; margin-right: .1rem; color: var(--ink); }

.ex { display: flex; align-items: center; gap: .25rem; margin: .4rem 0; flex-wrap: wrap; }
.ex em { font-style: normal; font-size: .85rem; margin-left: .4rem; color: var(--ink2); flex-basis: 100%; }

.resPanel { width: min(27rem, 96vw); }
.rHead { display: flex; align-items: center; gap: .7rem; padding-right: 1.8rem; }
.rHead img { width: 4.2rem; height: auto; }
#rWord { display: flex; gap: .2rem; margin-top: .3rem; }
#rWord .t { --tile: 1.9rem; }
#rStats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .3rem; margin: .6rem 0 .2rem; text-align: center; }
#rStats div b { display: block; font-size: 1.5rem; color: var(--g); }
#rStats div span { font-size: .72rem; color: var(--ink2); }
#rDist { display: grid; gap: .2rem; }
.dr { display: flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 700; }
.dr i { font-style: normal; background: var(--a); color: #fff; padding: .05rem .4rem; border-radius: 4px; min-width: 1.6rem; text-align: right; }
.dr i.cur { background: var(--g); }
.row2 .btn { flex: 1; }
#rNext { text-align: center; margin-top: .5rem; font-weight: 700; }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* ---------- responsive ---------- */
@media (max-width: 660px) {
  #tabs { order: 3; width: 100%; justify-content: center; }
  .tab { flex: 1; text-align: center; padding: .34rem .3rem; }
  #brand small { display: none; }
  #icons { flex: 0 0 auto; }
  .startPanel { flex-direction: column; gap: .4rem; text-align: center; padding: 1rem; }
  .limoBig { width: 5.5rem; }
  .legend, .ctl { justify-content: center; }
  .modes { flex-direction: column; }
  .modeBtn { text-align: center; }
}
@media (max-width: 900px) { #brand small { display: none; } }
@media (max-height: 560px) {
  #top { padding: .15rem .5rem; }
  #brand b { font-size: 1.25rem; }
  .ib { width: 2rem; height: 2rem; }
  .tab { padding: .25rem .65rem; font-size: .82rem; }
  .startPanel { padding: .8rem 1rem; gap: .9rem; }
  .limoBig { width: 7rem; }
  .panel h1 { font-size: 2rem; }
  .intro { font-size: .85rem; margin: .3rem 0 !important; }
  .btn.big { padding: .55rem 1rem; font-size: 1.05rem; }
  .modes { margin-top: .5rem; }
  .ctl { display: none; }
  .panel { padding: .7rem .9rem; }
  #rStats { margin: .3rem 0 .1rem; }
  #rStats div b { font-size: 1.2rem; }
}
@media (max-height: 420px) {
  .limoBig { display: none; }
  .legend { margin-bottom: .2rem; }
  .panel p { margin: .25rem 0; }
  .rHead img { width: 3rem; }
}

@media (min-height: 900px) and (min-width: 900px) { #kb { max-width: 640px; } #headline, #clueCard { max-width: 640px; } }
#sideLimo { display: none; }
@media (min-width: 1150px) and (min-height: 700px) { #sideLimo { display: block; position: absolute; left: 2%; bottom: 6%; width: 11rem; height: auto; animation: bob 2.6s ease-in-out infinite; pointer-events: none; } }
