:root {
  --indigo: #1f2a44; --indigo2: #2c3b60; --soga: #a8692f; --soga2: #c98a45; --cream: #f7efdb; --paper: #fbf6e8;
  --ink: #221d17; --red: #c8452b; --mustard: #f2b33d; --hl: #fbe2a2; --ok: #3f9a5a; --block: #241f1a;
  --serif: Georgia, "Times New Roman", "Noto Serif", serif;
  --cs: 32px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; color: var(--ink);
  background-color: var(--indigo);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='%23a8692f' fill-opacity='.42' stroke='%23e9d6ad' stroke-opacity='.28' stroke-width='1.3'%3E%3Cellipse cx='28' cy='13.5' rx='8.5' ry='12'/%3E%3Cellipse cx='28' cy='42.5' rx='8.5' ry='12'/%3E%3Cellipse cx='13.5' cy='28' rx='12' ry='8.5'/%3E%3Cellipse cx='42.5' cy='28' rx='12' ry='8.5'/%3E%3C/g%3E%3Cg fill='%23e9d6ad' fill-opacity='.4'%3E%3Ccircle cx='28' cy='28' r='2.4'/%3E%3Ccircle cx='0' cy='0' r='2.4'/%3E%3Ccircle cx='56' cy='0' r='2.4'/%3E%3Ccircle cx='0' cy='56' r='2.4'/%3E%3Ccircle cx='56' cy='56' r='2.4'/%3E%3Ccircle cx='28' cy='13' r='1.5'/%3E%3Ccircle cx='28' cy='43' r='1.5'/%3E%3Ccircle cx='13' cy='28' r='1.5'/%3E%3Ccircle cx='43' cy='28' r='1.5'/%3E%3C/g%3E%3C/svg%3E");
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* masthead */
#mast { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
  background: linear-gradient(#18213a, #1f2a44); color: var(--cream); border-bottom: 3px double var(--soga2); }
#masthead { flex: 1; min-width: 0; line-height: 1; }
#mTitle { font-family: var(--serif); font-weight: 900; font-size: 22px; letter-spacing: .5px; }
#mTitle span { color: var(--mustard); font-style: italic; }
#mSub { font-size: 11px; opacity: .8; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .3px; }
#stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.05; }
#stars { color: var(--mustard); font-size: 14px; letter-spacing: 1px; }
#stars i { font-style: normal; opacity: .25; }
#stars i.on { opacity: 1; }
#timer { font-variant-numeric: tabular-nums; font-size: 16px; }
.ib { width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.1); display: grid; place-items: center; padding: 0; flex: none; }
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: scale(.92); }
.ib.dark { background: rgba(0,0,0,.07); color: var(--ink); }

/* play */
#playView { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: 8px; gap: 8px; }
#paper { background: var(--paper); border-radius: 6px; box-shadow: 0 6px 0 rgba(0,0,0,.25), 0 10px 24px rgba(0,0,0,.35);
  padding: 8px 10px 10px; border: 1px solid #e3d6b5; position: relative; max-width: 100%; flex: none;
  background-image: linear-gradient(rgba(168,105,47,.05) 1px, transparent 1px); background-size: 100% 4px; }
#paperHead { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin-bottom: 8px; flex-wrap: wrap; }
#pTitle { font-family: var(--serif); font-size: 17px; }
#pInfo { font-size: 12px; color: #6c5c45; flex: 1; }
#clueMode { display: flex; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg { border: 0; background: transparent; font-size: 12px; font-weight: 700; padding: 3px 10px; }
.seg.on { background: var(--ink); color: var(--paper); }
#gridWrap { display: flex; justify-content: center; }
#grid { display: grid; grid-template-columns: repeat(var(--cols), var(--cs)); grid-auto-rows: var(--cs); border: 2px solid var(--ink); background: var(--block); gap: 1px; }
.c { position: relative; background: #fffdf6; display: grid; place-items: center; font-weight: 800; font-size: calc(var(--cs) * .58); line-height: 1; color: var(--ink); cursor: pointer; transition: background .12s; font-family: var(--serif); }
.c.x { background: var(--block); cursor: default;
  background-image: radial-gradient(circle at 50% 50%, rgba(201,138,69,.22) 0 18%, transparent 19%); }
.c .n { position: absolute; left: 2px; top: 1px; font-size: max(8px, calc(var(--cs) * .27)); font-weight: 700; font-family: system-ui, sans-serif; color: #5b4a33; }
.c.w { background: var(--hl); }
.c.cur { background: var(--mustard); box-shadow: inset 0 0 0 2px #b9771c; }
.c.bad { color: var(--red); }
.c.bad::after { content: ""; position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; background: var(--red); transform: rotate(-35deg); opacity: .8; }
.c.rev { color: #2b4fa0; }
.c.rev::before { content: ""; position: absolute; right: 0; top: 0; border-style: solid; border-width: 0 7px 7px 0; border-color: transparent #2b4fa0 transparent transparent; }
.c.ok { animation: okflash .7s ease; }
@keyframes okflash { 0% { background: #bfe8c4; } 60% { background: #bfe8c4; } }
.c.pop { animation: pop .18s ease; }
@keyframes pop { 0% { transform: scale(.7); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
.c.won { animation: wonwave .9s ease both; }
@keyframes wonwave { 0% { background: #fffdf6; } 40% { background: #ffe08a; } 100% { background: #e9f6df; } }

#side { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: none; }
#clueBar { display: flex; align-items: stretch; background: var(--cream); border-radius: 12px; border: 2px solid var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.25); min-height: 56px; }
.cb { border: 0; background: transparent; width: 40px; flex: none; display: grid; place-items: center; color: var(--ink); }
.cb svg { width: 22px; height: 22px; }
#clueText { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 2px; cursor: pointer; }
#cilMini { width: 30px; height: auto; flex: none; margin-bottom: -6px; align-self: flex-end; }
#clueText > div { min-width: 0; }
#clueDir { display: block; font-size: 11px; font-weight: 800; color: var(--red); text-transform: uppercase; letter-spacing: .5px; }
#clueStr { display: block; font-size: 15px; font-weight: 600; line-height: 1.25; }
#tools { display: flex; gap: 6px; }
.tool { flex: 1; border: 0; border-radius: 10px; background: var(--soga); color: #fff8ea; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px 4px;
  box-shadow: 0 3px 0 #6e4219; font-size: 11px; font-weight: 700; }
.tool svg { width: 20px; height: 20px; }
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 #6e4219; }
#tList { display: none; }
#lists { display: none; }
.note { color: var(--cream); font-size: 12px; opacity: .85; margin: 0; text-align: center; }

/* on-screen keyboard */
#kbd { width: 100%; max-width: 560px; display: none; flex-direction: column; gap: 6px; margin-top: auto; padding-bottom: env(safe-area-inset-bottom); }
.kr { display: flex; gap: 5px; justify-content: center; }
.k { flex: 1; max-width: 46px; height: 44px; border: 0; border-radius: 8px; background: var(--cream); color: var(--ink); font-weight: 800; font-size: 18px; box-shadow: 0 3px 0 #b9a77f; font-family: var(--serif); touch-action: manipulation; }
.k.wide { max-width: 64px; flex: 1.5; font-size: 13px; font-family: system-ui, sans-serif; background: var(--soga2); color: #fff; box-shadow: 0 3px 0 #7a4a1c; }
.k.down { transform: translateY(2px); box-shadow: 0 1px 0 #b9a77f; background: var(--mustard); }
body.touch #kbd { display: flex; }
body.touch #tList { display: flex; }
body.touch #hint { display: none; }

/* wide screens: grid left, clue lists right */
body.wide #playView { flex-direction: row; align-items: flex-start; justify-content: center; padding: 14px; gap: 16px; }
body.wide #side { width: 400px; height: 100%; }
body.wide #lists { display: flex; gap: 10px; flex: 1; min-height: 0; }
body.wide #tList { display: none; }
.list { flex: 1; background: var(--paper); border-radius: 8px; padding: 6px 4px 6px 8px; overflow: auto; border: 1px solid #e3d6b5; min-height: 0; }
.list h3 { margin: 2px 0 4px; font-family: var(--serif); font-size: 15px; border-bottom: 2px solid var(--ink); text-transform: uppercase; letter-spacing: 1px; }
.list ol { list-style: none; margin: 0; padding: 0; }
.list li { font-size: 13px; padding: 4px 4px; border-radius: 6px; cursor: pointer; line-height: 1.3; }
.list li b { display: inline-block; min-width: 20px; }
.list li.on { background: var(--hl); }
.list li.done { color: #8b7d68; text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(15,20,35,.66); display: grid; place-items: center; z-index: 20; padding: 14px; }
.panel { background: var(--paper); border-radius: 18px; padding: 14px 18px 18px; width: min(420px, 100%); text-align: center; position: relative;
  box-shadow: 0 8px 0 rgba(0,0,0,.25), 0 18px 40px rgba(0,0,0,.4); border: 3px solid var(--ink);
  background-image: linear-gradient(var(--soga) 0 6px, transparent 6px); max-height: 100%; overflow: auto; }
.cilBig { height: 150px; width: auto; margin-top: 4px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.15)); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-1.5deg); } }
.panel h1, .panel h2 { font-family: var(--serif); margin: 4px 0 0; font-size: 30px; line-height: 1.05; }
.tag { margin: 4px 0 8px; font-weight: 700; color: var(--red); }
.intro { margin: 0 0 12px; font-size: 14px; line-height: 1.4; color: #4a3f31; }
.btn { display: block; width: 100%; border: 0; border-radius: 14px; padding: 12px; font-weight: 800; font-size: 17px; margin-top: 8px; }
.btn.big { background: var(--red); color: #fff; font-size: 20px; padding: 15px; box-shadow: 0 5px 0 #7d2414; }
.btn.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #7d2414; }
.btn.ghost { background: transparent; border: 2px solid var(--ink); }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 12px; margin-top: 12px; font-size: 12px; color: #5b4a33; }
kbd { display: inline-block; border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: 5px; padding: 0 5px; font-family: inherit; font-weight: 800; background: #fff; font-size: 11px; }
.keys .touch { display: none; }
body.touch .keys span { display: none; }
body.touch .keys .touch { display: inline; font-size: 13px; }

.sheet { background: var(--paper); border-radius: 18px; width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column; border: 3px solid var(--ink); overflow: hidden; }
.sheetHead { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px; }
.sheetHead h2 { margin: 0; font-family: var(--serif); font-size: 24px; }
#tabs { display: flex; gap: 4px; padding: 0 10px; border-bottom: 2px solid var(--ink); }
.tab { flex: 1; border: 0; background: transparent; padding: 8px 2px; font-weight: 800; font-size: 14px; border-radius: 10px 10px 0 0; }
.tab.on { background: var(--ink); color: var(--paper); }
#tabNote { color: #5b4a33; padding: 8px 12px 0; text-align: left; opacity: 1; }
#tabBody { overflow: auto; padding: 10px 12px 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.tile { border: 2px solid var(--ink); background: #fff; border-radius: 10px; padding: 6px 2px 4px; font-weight: 800; font-family: var(--serif); font-size: 18px; position: relative; }
.tile small { display: block; font-size: 11px; color: var(--mustard); letter-spacing: 1px; font-family: system-ui; min-height: 13px; }
.tile.done { background: #eef7e4; }
.tile.next { background: var(--hl); box-shadow: 0 0 0 3px var(--mustard); }
.tile.part { background: #fff6dd; }
.daily { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 12px; }
.daily img { height: 92px; width: auto; }
.daily h3 { margin: 0 0 4px; font-family: var(--serif); font-size: 20px; }
.daily p { margin: 0 0 8px; font-size: 13px; color: #4a3f31; }
.daily .btn { margin: 0; width: auto; display: inline-block; padding: 10px 18px; font-size: 16px; }
.arch { margin-top: 14px; }
.arch h4 { margin: 0 0 8px; font-family: var(--serif); }
#sheetLists { overflow: auto; padding: 0 10px 12px; display: flex; flex-direction: column; gap: 10px; }
#sheetLists .list { flex: none; overflow: visible; }

#winStars { font-size: 44px; color: #d9cdb2; letter-spacing: 4px; margin: 4px 0; }
#winStars i { font-style: normal; display: inline-block; }
#winStars i.on { color: var(--mustard); animation: starIn .5s cubic-bezier(.3,1.6,.5,1) both; text-shadow: 0 3px 0 #b9771c; }
@keyframes starIn { 0% { transform: scale(0) rotate(-90deg); } 100% { transform: scale(1) rotate(0); } }
#winInfo, #winStreak { margin: 2px 0; font-size: 15px; }
#winStreak { color: var(--red); font-weight: 800; }

#say { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); background: var(--ink); color: var(--cream); padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; z-index: 30; pointer-events: none; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis; animation: sayIn .25s ease; }
@keyframes sayIn { from { opacity: 0; transform: translate(-50%, -8px); } }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; width: 100%; height: 100%; }
.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
