:root {
  --felt: #1d3b2f; --felt2: #152c23; --crema: #f7f0e1; --carta: #efe4cc; --terra: #c4553a; --terra2: #8f3524;
  --oliva: #5f7036; --oliva2: #3f4c22; --ocra: #e0a63a; --ink: #2d2a20; --soft: #6c6450;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", "Palatino Linotype", 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: cream paper with terracotta line */
#bar { position: fixed; left: 0; right: 0; top: 0; height: 50px; display: flex; align-items: center; gap: 6px; padding: 0 6px;
  background: var(--crema); color: var(--ink); z-index: 5; border-bottom: 3px solid var(--terra); box-shadow: 0 3px 10px rgba(0,0,0,.25); }
#info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
#pname { font: italic 13px var(--serif); color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#nums { display: flex; gap: 12px; font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
#time.off { display: none; }
#prog { color: var(--terra); }
.grp { display: flex; gap: 4px; }
.ib { height: 40px; min-width: 40px; padding: 0 9px; border: 0; border-radius: 10px; background: var(--carta); color: var(--ink);
  display: flex; align-items: center; gap: 5px; cursor: pointer; font: 700 13px var(--font); }
.ib svg { width: 21px; height: 21px; flex: none; }
.ib:hover { background: #e6d8ba; }
.ib.on { background: var(--oliva); color: #fff; }
.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: 900px) { .ib .t { display: none; } .ib { padding: 0; } }
@media (max-width: 400px) { .ib { min-width: 35px; height: 38px; } .grp { gap: 3px; } #bar { gap: 4px; padding: 0 4px; } #nums { font-size: 15px; gap: 8px; } }

#hint { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 4; pointer-events: none;
  background: rgba(247,240,225,.92); color: var(--ink); font-weight: 700; font-size: 13px; padding: 5px 14px; border-radius: 8px;
  border-left: 4px solid var(--terra); 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; left: 10px; bottom: 10px; }
.zb { width: 42px; height: 42px; border-radius: 10px; border: 2px solid var(--crema); background: rgba(21,44,35,.85); color: var(--crema); font: 800 24px/1 var(--font);
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.zb svg { width: 20px; height: 20px; }
.rotb { position: fixed; z-index: 4; right: 12px; bottom: 12px; width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--crema);
  background: var(--terra); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; box-shadow: 0 4px 0 var(--terra2); }
.rotb svg { width: 28px; height: 28px; }
.rotb.dis { opacity: .45; }
#toast { position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%) scale(.92); z-index: 9; pointer-events: none; opacity: 0;
  background: var(--crema); color: var(--ink); border: 2px solid var(--terra); font: 700 19px var(--serif); padding: 10px 22px;
  border-radius: 10px; transition: opacity .25s, transform .25s; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.35); max-width: 90vw; }
#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: 14px;
  background: rgba(14,30,23,.72); }
.panel { position: relative; background: var(--crema); border-radius: 14px; padding: 20px; text-align: center; margin: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,.45); border-top: 6px solid var(--terra); width: min(520px, 100%); max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); }
.logo { width: 46px; height: 46px; margin: 0 auto 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; transform: rotate(-8deg); }
.logo i { display: block; border-radius: 4px; background: var(--terra); }
.logo i:nth-child(2) { background: var(--ocra); } .logo i:nth-child(3) { background: var(--oliva); } .logo i:nth-child(4) { background: #3d7f9c; }
h1 { margin: 0 0 6px; font: 700 40px/1.05 var(--serif); color: var(--terra2); }
h1 span { display: block; font: italic 21px var(--serif); color: var(--oliva2); margin-top: 4px; }
h2 { margin: 0 0 6px; font: 700 28px var(--serif); color: var(--terra2); }
.intro { margin: 8px 4px 10px; font-size: 14.5px; line-height: 1.4; color: #4b4535; }
.ctrl { margin: 6px 0 0; font-size: 12.5px; color: var(--soft); line-height: 2; }
.key { display: inline-block; border: 1.5px solid #b9ab88; border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; font-weight: 700; font-size: 11.5px; line-height: 18px; background: #fff; color: var(--ink); }
.sp { width: min(540px, 100%); }
.card { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid #e0d3b4; border-radius: 12px; padding: 8px; text-align: left; cursor: pointer; margin-bottom: 8px; }
.card:hover { border-color: var(--ocra); }
.card img { width: 108px; height: 72px; border-radius: 6px; object-fit: cover; flex: none; background: #ddd; }
.ci { min-width: 0; flex: 1; }
.ct { font: 700 17px var(--serif); color: var(--terra2); }
.cs { font-size: 13px; color: var(--soft); margin: 1px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar2 { height: 7px; border-radius: 4px; background: #eadfc6; overflow: hidden; } .bar2 b { display: block; height: 100%; background: var(--oliva); width: 0; }
.streak { font-weight: 800; color: var(--oliva2); font-size: 13.5px; }
.big { display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 10px; margin: 8px 0 0; cursor: pointer;
  font: 700 21px var(--serif); color: #fff; background: var(--terra); box-shadow: 0 4px 0 var(--terra2); transition: transform .08s; }
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--terra2); }
.big.alt { background: var(--oliva); box-shadow: 0 4px 0 var(--oliva2); font-size: 18px; padding: 11px 10px; }
#bPlay { font-size: 24px; }

/* gallery */
.gp { width: min(860px, 100%); display: flex; flex-direction: column; padding-bottom: 14px; }
.close { position: absolute; right: 10px; top: 10px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--carta);
  color: var(--ink); font: 700 26px/1 var(--font); cursor: pointer; }
.album { font-size: 13px; color: var(--soft); margin-bottom: 8px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; flex: none; scrollbar-width: none; justify-content: center; }
.tabs button { flex: none; border: 0; border-radius: 8px; padding: 8px 14px; font: 700 14px var(--font); background: var(--carta); color: var(--ink); cursor: pointer; }
.tabs button.sel { background: var(--terra); color: #fff; }
.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: 80px;
  touch-action: pan-y; grid-auto-rows: max-content; align-content: start; }
@media (max-width: 500px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 6px; } }
.th { position: relative; border: 3px solid transparent; border-radius: 8px; padding: 0; background: #fff; cursor: pointer; overflow: hidden; aspect-ratio: 3/2; }
.th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.th.sel { border-color: var(--terra); box-shadow: 0 0 0 2px var(--ocra); }
.th .nm { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(20,20,10,.8)); color: #fff;
  font: 600 11.5px var(--font); padding: 10px 5px 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(--oliva); color: #fff;
  font: 800 13px/22px var(--font); text-align: center; }
.opts { flex: none; border-top: 1px solid #e0d3b4; margin-top: 6px; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.orow { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 14px; }
.lbl { font-weight: 800; color: var(--ink); font-size: 14px; }
.counts { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.counts button { border: 0; border-radius: 8px; min-width: 46px; padding: 7px 7px; font: 800 15px var(--font); background: var(--carta); color: var(--ink); cursor: pointer; }
.counts button.sel { background: var(--ocra); color: var(--ink); box-shadow: 0 2px 0 #a8741c; }
.tg { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); cursor: pointer; font-size: 14.5px; }
.tg input { display: none; }
.sw { width: 42px; height: 24px; border-radius: 12px; background: #d6c9a8; 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); }
.tg input:checked + .sw { background: var(--oliva); }
.tg input:checked + .sw::after { left: 21px; }
#gPlay { flex: none; }

/* win */
.wp { width: min(440px, 100%); }
.big4 { width: 56px; height: 56px; animation: spin 2.4s ease-in-out infinite; }
@keyframes spin { 50% { transform: rotate(8deg) scale(1.08); } }
#wText { font-size: 19px; font-weight: 700; margin: 4px 0; }
.rec { color: var(--terra); font-weight: 800; font-size: 17px; margin: 4px 0; }
.rec:empty, .best:empty, .wstreak:empty { display: none; }
.best { margin: 2px 0; color: var(--soft); }
.wstreak { margin: 6px 0 2px; font-weight: 800; color: var(--oliva2); font-size: 15px; }
.row { display: flex; gap: 10px; }
.row .big { flex: 1; font-size: 18px; }

/* wide screens: start panel in two columns */
@media (min-width: 700px) {
  .sp { width: min(820px, 100%); display: flex; gap: 22px; align-items: center; text-align: left; padding: 22px 24px; }
  .sp .sl { flex: 1.1; } .sp .sr { flex: 1; } .sp .logo { margin-left: 0; }
}
@media (min-width: 1300px) and (min-height: 700px) {
  .sp { width: 900px; } h1 { font-size: 50px; } h1 span { font-size: 25px; } .intro { font-size: 16px; }
}
/* short frames (store page 794x447, 640x360) */
@media (max-height: 560px) {
  #bar { height: 44px; } .ib { height: 34px; min-width: 34px; } #nums { font-size: 15px; } #pname { font-size: 12px; }
  #hint { top: 52px; font-size: 12px; }
  .ov { padding: 8px; }
  .panel { padding: 12px 14px; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .sp { padding: 14px 18px; gap: 16px; }
  .logo { width: 34px; height: 34px; margin-bottom: 4px; }
  h1 { font-size: 30px; } h1 span { font-size: 17px; margin-top: 2px; }
  .intro { font-size: 13px; margin: 4px 0 4px; }
  .card { padding: 6px; margin-bottom: 6px; } .card img { width: 84px; height: 56px; }
  .ct { font-size: 15px; }
  .big { padding: 9px 10px; margin-top: 6px; font-size: 18px; } #bPlay { font-size: 20px; } .big.alt { padding: 8px 10px; font-size: 16px; }
  .gp h2 { font-size: 21px; margin: 0 44px 2px; }
  .close { width: 34px; height: 34px; font-size: 22px; top: 6px; right: 8px; }
  .album { font-size: 12px; margin-bottom: 4px; }
  .tabs button { padding: 5px 11px; font-size: 13px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); padding: 5px 2px; min-height: 50px; }
  .opts { margin-top: 4px; padding-top: 5px; gap: 4px; }
  .counts button { min-width: 38px; padding: 5px 5px; font-size: 13px; }
  .tg { font-size: 13px; }
  .gp .big { margin-top: 5px; }
  .wp h2 { font-size: 24px; } .big4 { width: 40px; height: 40px; }
  .zb { width: 36px; height: 36px; } .rotb { width: 48px; height: 48px; }
}
@media (max-height: 420px) {
  .ctrl { display: none; }
  .intro { font-size: 12px; line-height: 1.3; }
  h1 { font-size: 26px; }
  .sp .logo { display: none; }
  .gp .album { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  #wText { font-size: 16px; }
  .wp .big4 { display: none; }
}
