:root {
  --felt: #1d4436; --felt2: #173a2f; --bar: #132f26; --gold: #c9a24a; --gold2: #e6c779; --gold3: #9c7a2c;
  --paper: #fffaf0; --paper2: #f3ead7; --ink: #1c2b25; --green: #23523f; --green2: #163a2c; --berry: #b23a48; --muted: #5f6f66;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", "Noto Serif", serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--felt); font-family: var(--font); color: var(--ink);
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
canvas#c { position: fixed; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }

/* top bar */
#bar { position: fixed; left: 0; right: 0; top: 0; height: 50px; display: flex; align-items: center; gap: 6px; padding: 0 6px;
  background: var(--bar); color: #f6efdc; z-index: 5; border-bottom: 2px solid var(--gold); }
#info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
#pname { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; font-family: var(--serif); font-style: italic; }
#nums { display: flex; gap: 12px; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
#prog { color: var(--gold2); }
body.calm #time { display: none; }
.grp { display: flex; gap: 4px; }
.ib { height: 40px; min-width: 40px; padding: 0 9px; border: 1px solid rgba(230,199,121,.25); border-radius: 8px; background: rgba(255,255,255,.06); color: #f6efdc;
  display: flex; align-items: center; gap: 5px; cursor: pointer; font: 600 13px var(--font); }
.ib svg { width: 21px; height: 21px; flex: none; }
.ib:hover { background: rgba(255,255,255,.14); }
.ib.on { background: var(--gold); color: var(--bar); border-color: var(--gold2); }
.ib.off { opacity: .5; }
.ib .slash, .ib .xm { display: none; }
.ib.off .slash, .ib.off .xm { display: inline; }
.ib.off .wave { display: none; }
@media (max-width: 760px) { .ib .t { display: none; } .ib { padding: 0; } }
@media (max-width: 380px) { .ib { min-width: 36px; } .grp { gap: 3px; } }

#hint { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 4; pointer-events: none;
  background: rgba(19,47,38,.85); color: #f6efdc; font-weight: 600; font-size: 13px; padding: 5px 12px; border-radius: 6px; border: 1px solid rgba(230,199,121,.35);
  white-space: nowrap; max-width: calc(100vw - 20px); overflow: hidden; text-overflow: ellipsis; transition: opacity .3s; }
#zoom { position: fixed; z-index: 4; display: flex; gap: 6px; }
.zb { width: 40px; height: 40px; border-radius: 8px; border: 2px solid var(--gold); background: var(--bar); color: var(--gold2); font: 700 24px/1 var(--font);
  display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.3); padding: 0; }
.zb svg { width: 20px; height: 20px; }
#toast { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.92); z-index: 9; pointer-events: none; opacity: 0;
  background: var(--paper); color: var(--green2); border: 2px solid var(--gold); font-weight: 700; font-size: 18px; padding: 10px 22px;
  border-radius: 10px; transition: opacity .25s, transform .25s; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.35); font-family: var(--serif); }
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* overlays */
.ov { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 12px;
  background: radial-gradient(circle at 50% 35%, rgba(29,68,54,.55), rgba(10,24,19,.88)); overflow: auto; }
.panel { position: relative; background: var(--paper); border-radius: 14px; border: 2px solid var(--gold); padding: 18px 20px 16px;
  box-shadow: 0 0 0 6px rgba(201,162,74,.18), 0 20px 50px rgba(0,0,0,.45); width: min(560px, 100%); text-align: center; margin: auto; }
.logo svg { width: 54px; height: 54px; display: block; margin: -4px auto 2px; filter: drop-shadow(0 3px 3px rgba(0,0,0,.25)); animation: tilt 4s ease-in-out infinite; }
@keyframes tilt { 50% { transform: rotate(8deg); } }
h1 { margin: 0 0 4px; font: 700 38px/1.05 var(--serif); color: var(--green2); }
h1 span { display: block; font: italic 400 18px var(--serif); color: var(--gold3); margin-top: 4px; }
h2 { margin: 0 0 6px; font: 700 28px var(--serif); color: var(--green2); }
.intro { margin: 8px 4px 12px; font-size: 14.5px; line-height: 1.4; color: #3f4f47; }
.cols { display: flex; flex-direction: column; gap: 4px; }
.daily { display: flex; gap: 12px; align-items: center; background: #fff; border: 1px solid #d9c9a0; border-radius: 10px;
  padding: 8px; text-align: left; cursor: pointer; box-shadow: 0 2px 8px rgba(60,40,0,.08); }
.daily:hover { border-color: var(--gold); }
.daily img { width: 114px; height: 76px; border-radius: 6px; object-fit: cover; flex: none; background: #e8e1d0; }
.dinfo { min-width: 0; flex: 1; }
.dtitle { font: 700 17px var(--serif); color: var(--green); }
.dsub { font-size: 13px; color: var(--muted); margin: 1px 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.streak { display: flex; align-items: center; gap: 4px; font-weight: 700; color: var(--gold3); font-size: 14px; }
.streak svg { width: 18px; height: 18px; }
.week { display: flex; gap: 4px; margin-top: 4px; }
.week i { width: 22px; height: 22px; border-radius: 4px; background: var(--paper2); color: #8a8670; font: 700 11px/22px var(--font);
  text-align: center; font-style: normal; }
.week i.ok { background: var(--green); color: var(--gold2); }
.week i.today { box-shadow: 0 0 0 2px var(--gold); }
.btns { display: flex; flex-direction: column; }
.big { display: block; width: 100%; border: 0; border-radius: 10px; padding: 13px 10px; margin: 8px 0 0; cursor: pointer;
  font: 700 21px var(--font); color: var(--bar); background: linear-gradient(#e2bf6a, #c9a24a); box-shadow: 0 4px 0 var(--gold3); transition: transform .08s; }
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold3); }
.big.alt { background: var(--green); color: #f6efdc; box-shadow: 0 4px 0 var(--green2); font-size: 18px; padding: 11px 10px; }
#bCont { background: linear-gradient(#cf5866, #b23a48); color: #fff; box-shadow: 0 4px 0 #7d2230; }
.ctrl { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.ctrl svg { width: 16px; height: 16px; }
.key { display: inline-block; border: 1px solid #b9ae8e; border-bottom-width: 3px; border-radius: 5px; padding: 0 5px; font-weight: 700; font-size: 11px; background: #fff; }

/* gallery */
.gp { width: min(860px, 100%); display: flex; flex-direction: column; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); padding-bottom: 12px; }
.close { position: absolute; right: 10px; top: 8px; width: 40px; height: 40px; border: 0; border-radius: 8px; background: var(--green);
  color: #f6efdc; font: 700 26px/1 var(--font); cursor: pointer; }
.album { font-weight: 600; color: var(--gold3); font-size: 14px; margin-bottom: 8px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; flex: none; scrollbar-width: none; }
.tabs button { flex: none; border: 1px solid #d9c9a0; border-radius: 6px; padding: 7px 13px; font: 600 14px var(--font); background: #fff; color: var(--green); cursor: pointer; }
.tabs button.sel { background: var(--green); color: #f6efdc; border-color: var(--green); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; overflow-y: auto; padding: 8px 2px; flex: 1 1 auto; min-height: 120px;
  touch-action: pan-y; grid-auto-rows: max-content; align-content: start; }
@media (max-width: 500px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 6px; } }
.th { position: relative; border: 3px solid #fff; border-radius: 6px; padding: 0; background: #fff; cursor: pointer; overflow: hidden; aspect-ratio: 3/2;
  box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.th.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--green); }
.th .nm { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(10,24,19,.85)); color: #fff;
  font: 600 11.5px var(--font); padding: 10px 4px 3px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th .ok { position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--gold); color: var(--bar);
  font: 900 13px/22px var(--font); text-align: center; box-shadow: 0 2px 3px rgba(0,0,0,.3); }
.foto { padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1 1 auto; }
.foto p { margin: 0; font-size: 14px; color: #3f4f47; }
.filebtn { width: auto; padding: 12px 22px; display: inline-block; }
.filebtn input { display: none; }
#fotoPrev { width: 240px; height: 160px; border-radius: 6px; background: var(--paper2); border: 2px dashed #b9ae8e; }
.opts { flex: none; border-top: 1px solid #e3d6b5; margin-top: 6px; padding-top: 8px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 14px; }
.lbl { font: 700 15px var(--serif); color: var(--green2); }
.counts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.counts button { border: 1px solid #d9c9a0; border-radius: 6px; min-width: 50px; padding: 7px 8px; font: 700 16px var(--font); background: #fff; color: var(--green); cursor: pointer; }
.counts button.sel { background: var(--gold); border-color: var(--gold3); color: var(--bar); }
.tog { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; color: var(--green2); cursor: pointer; font-size: 14.5px; }
.tog small { font-weight: 400; color: var(--muted); }
.tog input { display: none; }
.sw { width: 42px; height: 24px; border-radius: 12px; background: #d6ccb4; position: relative; transition: background .2s; flex: none; }
.sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.tog input:checked + .sw { background: var(--green); }
.tog input:checked + .sw::after { left: 21px; }
#gPlay { flex: none; }

/* win */
.wp { width: min(440px, 100%); }
.wlogo svg { width: 60px; height: 60px; animation: pop .6s ease-out; }
@keyframes pop { 0% { transform: scale(.3) rotate(-30deg); } 70% { transform: scale(1.15); } }
.wimg { width: 200px; height: 133px; object-fit: cover; border: 4px solid #fff; border-radius: 4px; box-shadow: 0 3px 10px rgba(0,0,0,.25); display: block; margin: 4px auto 6px; }
#wText { font-size: 19px; font-weight: 700; margin: 4px 0; color: var(--green2); }
.rec { color: var(--berry); font-weight: 800; font-size: 17px; margin: 4px 0; }
.rec:empty, .best:empty, .wstreak:empty { display: none; }
.best { margin: 2px 0; color: var(--muted); }
.wstreak { margin: 6px 0 2px; font-weight: 700; color: var(--gold3); font-size: 15px; }
.row { display: flex; gap: 10px; }
.row .big { flex: 1; font-size: 18px; }

@media (max-height: 640px) { h1 { font-size: 32px; } .intro { font-size: 13px; margin: 4px 0 8px; } .big { padding: 10px; } .logo svg { width: 42px; height: 42px; } }

/* small store frame (794x447, 640x360) */
@media (max-height: 560px) {
  .ov { padding: 8px; }
  .panel { padding: 10px 14px 10px; }
  .sp { width: min(680px, 100%); }
  .sp .logo { display: none; }
  h1 { font-size: 28px; } h1 span { font-size: 15px; margin-top: 2px; }
  .intro { font-size: 12.5px; margin: 4px 4px 8px; }
  .cols { flex-direction: row; gap: 10px; align-items: stretch; }
  .cols .daily { flex: 1.15; }
  .cols .btns { flex: 1; justify-content: center; }
  .daily { padding: 6px; }
  .daily img { width: 96px; height: 64px; }
  .big { padding: 8px 10px; margin-top: 6px; font-size: 19px; }
  .btns .big:first-child { margin-top: 0; }
  .big.alt { padding: 8px 10px; font-size: 16px; }
  .ctrl { margin-top: 8px; }
  .gp { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); padding: 8px 12px 8px; }
  .gp h2 { font-size: 21px; margin: 0 40px 2px; }
  .close { width: 34px; height: 34px; font-size: 22px; top: 6px; }
  .album { font-size: 12.5px; margin-bottom: 4px; }
  .tabs button { padding: 5px 10px; font-size: 13px; }
  .grid { min-height: 60px; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); padding: 6px 2px; gap: 6px; }
  .opts { margin-top: 4px; padding-top: 6px; gap: 4px 10px; }
  .counts button { min-width: 40px; padding: 5px 6px; font-size: 14px; }
  .tog { font-size: 13px; }
  #gPlay { font-size: 18px; padding: 8px 10px; }
  .foto { padding: 4px; gap: 4px; } #fotoPrev { width: 150px; height: 100px; }
  .wlogo { display: none; }
  .wp h2 { font-size: 24px; margin-bottom: 2px; }
  .wimg { width: 150px; height: 100px; }
  #wText { font-size: 17px; margin: 2px 0; }
}
@media (max-height: 420px) {
  .sp .ctrl { display: none; }
  .intro { font-size: 12px; margin: 2px 2px 6px; }
  h1 { font-size: 25px; } h1 span { display: inline; font-size: 14px; margin-left: 6px; }
  .wimg { width: 120px; height: 80px; }
  .tog small { display: none; }
}
@media (max-height: 380px) { .sp .intro { display: none; } }
@media (max-width: 520px) and (max-height: 560px) { .cols { flex-direction: column; } }
