[hidden] { display: none !important; }
:root {
  --red: #c8102e; --red2: #9c0b22; --pink: #ff8fb1; --pink2: #ffd0de; --mint: #5fc9b5; --mint2: #d6f2ea; --green: #1d6b45;
  --cream: #fff8ec; --ink: #3a2a2a; --gold: #ffb81c; --blue: #2f74d0;
  --bar: 44px;
  --font: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", "Heiti TC", "Source Han Sans TC", sans-serif;
  font-size: clamp(11px, min(2.2vh, 1.7vw) + 4px, 19px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none;
  background-color: #e5f6f1;
  /* 花磚 (retro Taiwanese floor tile) pattern */
  background-image:
    radial-gradient(circle at 50% 50%, #ffffff 0 7%, transparent 7.5%),
    radial-gradient(circle at 50% 50%, transparent 0 20%, rgba(95,201,181,.55) 20.5% 24%, transparent 24.5%),
    radial-gradient(circle at 0 0, rgba(255,143,177,.5) 0 16%, transparent 16.5%),
    radial-gradient(circle at 100% 0, rgba(255,143,177,.5) 0 16%, transparent 16.5%),
    radial-gradient(circle at 0 100%, rgba(255,143,177,.5) 0 16%, transparent 16.5%),
    radial-gradient(circle at 100% 100%, rgba(255,143,177,.5) 0 16%, transparent 16.5%),
    linear-gradient(45deg, transparent 47%, rgba(29,107,69,.12) 47% 53%, transparent 53%),
    linear-gradient(-45deg, transparent 47%, rgba(29,107,69,.12) 47% 53%, transparent 53%);
  background-size: 64px 64px;
}
#bgFx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; z-index: 1; }

/* top bar */
#bar { height: var(--bar); flex: none; display: flex; align-items: center; gap: 4px; padding: 0 6px; background: var(--red); color: #fff; border-bottom: 4px solid var(--pink); box-shadow: 0 2px 8px rgba(0,0,0,.25); z-index: 5;
  background-image: radial-gradient(circle at 10px 10px, rgba(255,255,255,.12) 0 3px, transparent 3.5px); background-size: 22px 22px; }
.ib { width: calc(var(--bar) - 6px); height: calc(var(--bar) - 6px); border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; transition: background .15s, transform .1s; }
.ib:hover { background: rgba(255,255,255,.16); }
.ib:active { transform: scale(.92); }
.ib svg { width: 62%; height: 62%; }
.ib[disabled] { opacity: .35; pointer-events: none; }
.ib .slash { display: none; }
.ib.off .slash { display: block; } .ib.off .wave { display: none; } .ib.off { opacity: .6; }
.bar-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.12rem; white-space: nowrap; overflow: hidden; min-width: 0; letter-spacing: .05em; }
#barText { overflow: hidden; text-overflow: ellipsis; }
#barText b { color: #ffe94d; font-size: 1.15em; }
.flower-mini { width: 1.5em; height: 1.5em; flex: none; border-radius: 50%;
  background: radial-gradient(circle, #ffd23f 0 22%, transparent 23%), conic-gradient(from 0deg, var(--pink) 0 20%, #fff 0 40%, var(--pink) 0 60%, #fff 0 80%, var(--pink) 0); box-shadow: 0 0 0 2px #fff; }
.sp { flex: 1; }
.bar-tools { display: flex; gap: 2px; align-items: center; }
.done-btn { width: auto; padding: 0 16px; background: var(--gold); color: var(--ink); font-weight: 900; font-size: 1rem; border-bottom: 3px solid #c98a00; }
.done-btn:hover { background: #ffc94a; }
#timer { position: relative; width: calc(var(--bar) - 4px); height: calc(var(--bar) - 4px); flex: none; margin-left: 4px; }
#timer svg { position: absolute; inset: 0; transform: rotate(-90deg); }
#timer circle { fill: none; stroke-width: 4; }
.tr-bg { stroke: rgba(255,255,255,.25); }
.tr-fg { stroke: #ffe94d; stroke-dasharray: 94.25; stroke-dashoffset: 0; stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
#timer b { position: absolute; inset: 0; display: grid; place-items: center; font-size: .95rem; }
#timer.low .tr-fg { stroke: #fff; } #timer.low b { animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.18); } }

#screens { position: relative; flex: 1; min-height: 0; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }

/* home */
#s-home { align-items: center; justify-content: center; padding: 12px; }
.home { position: relative; display: flex; align-items: center; gap: 1.6rem; background: var(--cream); border-radius: 26px; padding: 1.4rem 2rem 1.3rem 1.4rem; max-width: 900px; width: 100%;
  border: 4px dashed var(--mint); box-shadow: 0 0 0 6px var(--cream), 0 0 0 10px var(--green), 0 16px 40px rgba(60,0,10,.45); }
.bear { width: min(28vw, 250px); height: auto; flex: none; filter: drop-shadow(0 6px 6px rgba(0,0,0,.2)); }
.bob { animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(2deg); } }
.home-main { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .75rem; min-width: 0; }
.logo { margin: 0; font-weight: 900; line-height: 1; display: flex; align-items: center; gap: .35em; flex-wrap: wrap; justify-content: center; }
.logo .l1 { font-size: 3.4rem; color: var(--red); letter-spacing: .08em; text-shadow: 3px 3px 0 var(--pink2), 5px 5px 0 var(--mint); }
.logo .l2 { font-size: 1.3rem; color: #fff; background: var(--green); padding: .3em .6em; border-radius: 99px; transform: rotate(-4deg); box-shadow: 0 3px 0 #10462c; }
.intro { margin: 0; font-size: .95rem; line-height: 1.6; max-width: 30em; color: #5a4444; }
.big, .mid { border-radius: 18px; font-weight: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; transition: transform .1s, filter .15s; }
.big small, .mid small { font-weight: 600; font-size: .72em; opacity: .92; margin-top: 2px; }
.big { font-size: 1.5rem; padding: .65rem 2.6rem; min-width: 14em; }
.primary { background: var(--red); color: #fff; border-bottom: 5px solid var(--red2); box-shadow: 0 6px 14px rgba(160,10,30,.35); }
.big:active, .mid:active { transform: translateY(3px) scale(.98); }
.big:hover, .mid:hover { filter: brightness(1.07); }
.home-row { display: flex; gap: .8rem; width: 100%; justify-content: center; }
.mid { font-size: 1.1rem; padding: .5rem 1rem; flex: 1; max-width: 12em; }
.alt { background: var(--gold); color: var(--ink); border-bottom: 4px solid #c98a00; }
.alt2 { background: #fff; color: var(--green); border: 2px solid var(--mint); border-bottom-width: 4px; }
.keys-hint { margin: 0; font-size: .78rem; color: #8a7070; }
.kb { display: inline-block; border: 1.5px solid #c9b0b0; border-bottom-width: 3px; border-radius: 5px; padding: 0 .35em; font-size: .9em; background: #fff; }

/* board */
#s-board { align-items: stretch; justify-content: center; }
#board { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 7px; min-width: 0; min-height: 0; }
#board.port { flex-direction: column; gap: 8px; justify-content: center; }
#paperWrap { position: relative; flex: none; width: var(--pw, 400px); height: var(--ph, 300px); }
#paper { position: absolute; inset: 0; border-radius: 8px; overflow: hidden; background: #fffef9; box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--red), 0 10px 24px rgba(0,0,0,.3); touch-action: none; }
#paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#cGuide { pointer-events: none; }
#cLive { cursor: crosshair; }
.hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); background: rgba(29,107,69,.9); color: #fff; padding: .3rem .9rem; border-radius: 99px; font-size: .82rem; pointer-events: none; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; transition: opacity .4s; }
.hint.gone { opacity: 0; }

#tools { flex: none; display: grid; grid-auto-flow: row; gap: 5px; background: var(--cream); padding: 6px; border-radius: 16px; box-shadow: 0 0 0 3px var(--green), 0 6px 14px rgba(0,0,0,.2); }
#board.port #tools { grid-auto-flow: row; }
.tool { width: var(--tb, 44px); height: var(--tb, 44px); border-radius: 12px; display: grid; place-items: center; position: relative; background: #fff; border: 2px solid var(--mint2); transition: transform .1s, background .15s; }
.tool svg { width: 72%; height: 72%; }
.tool.on { background: var(--mint); border-color: var(--green); color: #fff; transform: translateY(-1px); box-shadow: 0 3px 0 var(--green); }
.tool.on svg [fill="#fff"] { fill: #fff; }
.tool:active { transform: scale(.92); }
.tool .tl { position: absolute; bottom: 0; left: 0; right: 0; font-size: 9px; line-height: 1; font-weight: 700; display: none; }
.tool .badge { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; font-size: 10px; font-weight: 900; border-radius: 99px; padding: 1px 5px; border: 1.5px solid #fff; }

#side { flex: none; width: var(--sw, 220px); display: flex; flex-direction: column; gap: 7px; background: var(--cream); padding: 8px; border-radius: 16px; box-shadow: 0 0 0 3px var(--green), 0 6px 14px rgba(0,0,0,.2); max-height: var(--swH, 100%); overflow: hidden; }
#board.port #side { gap: 5px; padding: 6px; max-height: none; }
.sec { display: flex; align-items: center; gap: 6px; }
.colors { display: grid; grid-template-columns: repeat(var(--cc, 6), 1fr); gap: 4px; width: 100%; }
.sw { aspect-ratio: 1; border-radius: 8px; border: 2px solid rgba(0,0,0,.16); position: relative; transition: transform .1s; }
.sw.on { transform: scale(1.12); box-shadow: 0 0 0 2.5px #fff, 0 0 0 5px var(--red); z-index: 1; }
.sw.custom { background: conic-gradient(#f44, #fd4, #4d6, #4cf, #64f, #f4c, #f44); overflow: hidden; }
.sw.custom input { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); opacity: 0; cursor: pointer; border: 0; padding: 0; }
.sw.custom::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 900; text-shadow: 0 1px 2px #000; pointer-events: none; }
.size-sec { gap: 8px; }
.sz-lbl { font-size: .8rem; font-weight: 800; flex: none; color: var(--green); }
#size { flex: 1; min-width: 0; accent-color: var(--red); height: 26px; touch-action: none; }
.sz-dot { width: 32px; height: 32px; flex: none; display: grid; place-items: center; background: #fff; border-radius: 50%; border: 2px solid var(--mint2); }
.sz-dot i { display: block; border-radius: 50%; background: var(--ink); }
.stamps { display: grid; grid-template-columns: repeat(var(--sc, 6), 1fr); gap: 4px; width: 100%; }
.st { aspect-ratio: 1; background: #fff; border-radius: 10px; border: 2px solid var(--mint2); display: grid; place-items: center; padding: 2px; }
.st canvas { width: 100%; height: 100%; }
.st.on { border-color: var(--red); background: #ffe8ee; box-shadow: 0 0 0 2px var(--red); }
.now-sec { font-size: .76rem; color: #7a5a5a; justify-content: center; font-weight: 700; flex-wrap: wrap; }
#board.port .now-sec { display: none; }

/* overlay */
#ov { position: fixed; inset: 0; z-index: 20; background: rgba(60,10,20,.5); display: grid; place-items: center; padding: 10px; }
.panel { background: var(--cream); border-radius: 22px; padding: 1rem 1.3rem; width: min(560px, 100%); max-height: 94vh; display: flex; flex-direction: column; gap: .55rem; align-items: center; text-align: center;
  border: 3px dashed var(--mint); box-shadow: 0 0 0 5px var(--cream), 0 0 0 9px var(--red), 0 18px 40px rgba(0,0,0,.4); animation: pop .22s ease-out; }
.panel.wide { width: min(760px, 100%); }
.panel.guard .btn { pointer-events: none; opacity: .75; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.panel h2 { margin: 0; font-size: 1.4rem; color: var(--red); font-weight: 900; }
.panel p { margin: 0; font-size: .9rem; line-height: 1.5; }
.panel .note { font-size: .76rem; color: #8a7070; }
.btns { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; flex: none; }
.btn { padding: .55rem 1.3rem; border-radius: 14px; font-weight: 800; font-size: 1rem; background: #fff; color: var(--ink); border: 2px solid #e4cfcf; border-bottom-width: 4px; text-decoration: none; }
.btn.p { background: var(--red); color: #fff; border-color: var(--red2); }
.btn.b { background: var(--mint); color: #fff; border-color: var(--green); }
.btn:active { transform: translateY(2px); }
.scroll { overflow-y: auto; min-height: 0; flex: 1 1 auto; width: 100%; touch-action: pan-y; }
.levels { display: flex; gap: .6rem; width: 100%; }
.lv { flex: 1; border-radius: 16px; padding: .7rem .4rem; font-size: 1.25rem; font-weight: 900; color: #fff; display: flex; flex-direction: column; gap: 2px; border-bottom: 5px solid rgba(0,0,0,.22); }
.lv small { font-size: .62em; font-weight: 600; opacity: .95; }
.lv .best { font-size: .6em; background: rgba(255,255,255,.25); border-radius: 99px; padding: 1px 6px; align-self: center; }
.lv-easy { background: #3fa34d; } .lv-normal { background: #ff8a1f; } .lv-hard { background: var(--red); }
.words { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.words h4 { width: 100%; margin: .3rem 0 0; color: var(--green); }
.words span { background: #fff; border: 1.5px solid #e4cfcf; border-radius: 99px; padding: 2px 10px; font-size: .82rem; color: #a08888; }
.words span.got { color: var(--ink); border-color: var(--mint); background: var(--mint2); }
.words span.got::before { content: "✓ "; color: var(--green); }

/* prompt card flip */
.flip { perspective: 900px; width: min(300px, 70vw); height: min(180px, 34vh); flex: none; }
.card-in { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; animation: flip .7s .15s ease-out both; }
@keyframes flip { from { transform: rotateY(180deg); } to { transform: rotateY(0); } }
.card-back, .card-front { position: absolute; inset: 0; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.card-back { transform: rotateY(180deg); background: var(--red); color: #fff; font-size: 3rem; font-weight: 900; box-shadow: inset 0 0 0 6px var(--pink); }
.card-front { background: #fff; box-shadow: inset 0 0 0 4px var(--mint), 0 6px 14px rgba(0,0,0,.2); padding: 8px; }
.tm-no { font-size: .78rem; color: #8a7070; font-weight: 700; }
.tm-word { font-size: 2.2rem; font-weight: 900; color: var(--ink); line-height: 1.15; }
.mission { font-size: .85rem; font-weight: 800; color: #fff; background: var(--green); border-radius: 99px; padding: 3px 12px; }
.result { display: flex; gap: .8rem; width: 100%; justify-content: center; min-height: 0; }
.res-card { background: #fff; border-radius: 16px; padding: .5rem; flex: 1; max-width: 330px; display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; box-shadow: inset 0 0 0 3px var(--mint2); min-width: 0; }
.res-card .tm-word { font-size: 1.6rem; }
.lbl { font-size: .78rem; font-weight: 800; color: var(--green); }
.res-bear { height: min(120px, 22vh); width: auto; }
.res-pic { width: 100%; max-height: min(190px, 30vh); object-fit: contain; border-radius: 8px; border: 2px solid #eee; }
.stars { font-size: 1.5rem; letter-spacing: 2px; } .stars i { font-style: normal; color: #ddd; } .stars i.on { color: var(--gold); text-shadow: 0 2px 0 #c98a00; }
.big-stars { font-size: 1.6rem !important; font-weight: 900; color: var(--gold); }
.newbest { color: var(--red); font-weight: 900; }
.pts b.ok { color: var(--green); } .pts b.no { color: #b09090; }
.gal { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gal button, .gal .empty { background: #fff; border-radius: 12px; padding: 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 2px solid var(--mint2); font-size: .72rem; min-width: 0; }
.gal img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; }
.gal span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.gal .empty { aspect-ratio: 4/3; justify-content: center; color: #c0a8a8; border-style: dashed; }
.big-pic { max-width: 100%; max-height: min(52vh, 420px); border-radius: 10px; border: 3px solid #fff; box-shadow: 0 4px 12px rgba(0,0,0,.2); min-height: 0; object-fit: contain; -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; pointer-events: auto; }

#toast { position: fixed; left: 50%; top: calc(var(--bar) + 12px); transform: translateX(-50%); background: var(--green); color: #fff; padding: .4rem 1rem; border-radius: 99px; font-weight: 800; z-index: 30; font-size: .9rem; pointer-events: none; }
.confetti { position: fixed; z-index: 40; font-size: 22px; pointer-events: none; animation: fall 1.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(85vh) rotate(540deg); opacity: 0; } }

/* short windows (store frame 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  :root { --bar: 38px; }
  .home { padding: .8rem 1.2rem .8rem .8rem; gap: 1rem; }
  .bear { width: min(24vw, 34vh, 200px); }
  .logo .l1 { font-size: 2.6rem; }
  .big { font-size: 1.25rem; padding: .45rem 2rem; }
  .mid { font-size: 1rem; padding: .35rem .8rem; }
  .home-main { gap: .5rem; }
  .panel { padding: .6rem 1rem; gap: .4rem; }
  .panel h2 { font-size: 1.15rem; }
  .flip { height: min(150px, 34vh); }
  .tm-word { font-size: 1.8rem; }
  .res-bear { height: min(90px, 18vh); }
  .res-pic { max-height: 26vh; }
  .big-pic { max-height: 50vh; }
}
@media (max-height: 420px) {
  .now-sec { display: none !important; }
  .intro { display: none; }
  .bear { width: min(22vw, 44vh, 170px); }
  .logo .l1 { font-size: 2.2rem; }
  .res-bear { display: none; }
  .panel .note { font-size: .7rem; }
  .big-pic { max-height: 44vh; }
}
@media (max-width: 600px) {
  .home { flex-direction: column; padding: 1rem .9rem; gap: .5rem; }
  .bear { width: min(42vw, 26vh, 180px); }
  .big { min-width: 0; width: 100%; }
  .levels { flex-direction: column; }
  .lv { flex-direction: row; justify-content: space-between; align-items: center; font-size: 1.1rem; padding: .5rem .8rem; }
  .result { flex-direction: column; align-items: center; }
  .res-card { width: 100%; }
  .res-bear { display: none; }
  .gal { grid-template-columns: repeat(2, 1fr); }
  .bar-title { font-size: .95rem; }
}
.gal { width: min(100%, calc((94vh - 170px) * 1.8)); margin: 0 auto; }
@media (max-width: 600px) { .gal { width: 100%; } }
@media (min-height: 900px) and (min-width: 1200px) { :root { --bar: 54px; } .tool .tl { font-size: 11px; } }
