[hidden] { display: none !important; }
:root {
  --ai: #22315e; --ai2: #2f4580; --ai3: #3d5aa3;
  --washi: #f8f1e1; --washi2: #efe3c8; --sumi: #33241c; --shu: #d9432c; --shu2: #b8331f;
  --kin: #e8b14a; --matsu: #3f8a5a; --sakura: #f3a9b9;
  --bar: 46px;
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  --maru: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "YuGothic", "Meiryo", "Noto Sans JP", "Noto Sans CJK JP", 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(--maru); color: var(--sumi); user-select: none; -webkit-user-select: none; touch-action: manipulation;
  background-color: var(--ai);
  background-image:
    radial-gradient(circle at 50% 100%, transparent 38%, rgba(255,255,255,.10) 39%, rgba(255,255,255,.10) 44%, transparent 45%, transparent 56%, rgba(255,255,255,.08) 57%, rgba(255,255,255,.08) 62%, transparent 63%, transparent 74%, rgba(255,255,255,.06) 75%, rgba(255,255,255,.06) 80%, transparent 81%),
    radial-gradient(circle at 50% 100%, transparent 38%, rgba(255,255,255,.10) 39%, rgba(255,255,255,.10) 44%, transparent 45%, transparent 56%, rgba(255,255,255,.08) 57%, rgba(255,255,255,.08) 62%, transparent 63%, transparent 74%, rgba(255,255,255,.06) 75%, rgba(255,255,255,.06) 80%, transparent 81%);
  background-size: 64px 32px; background-position: 0 0, 32px 16px;
}
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; }

/* top bar */
#bar { height: var(--bar); flex: none; display: flex; align-items: center; gap: 4px; padding: 0 6px; background: linear-gradient(#1a2649, #22315e); color: #fff; border-bottom: 3px solid var(--shu); box-shadow: 0 2px 8px rgba(0,0,0,.25); z-index: 5; }
.ib { width: calc(var(--bar) - 8px); height: calc(var(--bar) - 8px); border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; transition: background .15s, transform .1s; }
.ib:hover { background: rgba(255,255,255,.12); }
.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-family: var(--mincho); font-weight: 700; font-size: 1.15rem; white-space: nowrap; overflow: hidden; min-width: 0; letter-spacing: .04em; }
#barText { overflow: hidden; text-overflow: ellipsis; }
#barText b { color: #ffd98a; font-size: 1.2em; }
.seal-mini { width: 1.7em; height: 1.7em; flex: none; display: grid; place-items: center; background: var(--shu); color: #fff; border-radius: 6px; font-size: .85em; box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); transform: rotate(-6deg); }
.sp { flex: 1; }
.bar-tools { display: flex; gap: 2px; align-items: center; }
.done-btn { width: auto; padding: 0 14px; background: var(--shu); font-weight: 800; font-size: 1rem; border-bottom: 3px solid var(--shu2); }
.done-btn:hover { background: #e8573f; }
#timer { position: relative; width: calc(var(--bar) - 6px); height: calc(var(--bar) - 6px); 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,.2); }
.tr-fg { stroke: var(--kin); 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: #ff6a52; } #timer.low b { color: #ffb4a6; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.15); } }

#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: 2rem; background: var(--washi); border-radius: 22px; padding: 1.6rem 2.2rem 1.4rem 1.6rem; max-width: 900px; width: 100%;
  box-shadow: 0 0 0 4px #fff8, 0 0 0 8px var(--shu), 0 14px 40px rgba(0,0,0,.35);
  background-image: radial-gradient(rgba(180,150,100,.08) 1px, transparent 1.5px), radial-gradient(rgba(180,150,100,.06) 1px, transparent 1.5px); background-size: 9px 9px, 13px 13px; background-position: 0 0, 4px 6px; }
.mike { width: min(30vw, 260px); height: auto; flex: none; filter: drop-shadow(0 6px 6px rgba(0,0,0,.18)); }
.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: .8rem; min-width: 0; }
.logo { margin: 0; font-family: var(--mincho); font-weight: 800; line-height: 1; display: flex; align-items: baseline; gap: .2em; flex-wrap: wrap; justify-content: center; }
.logo .l1 { font-size: 2.9rem; color: var(--sumi); letter-spacing: .05em; }
.logo .l2 { font-size: 2rem; color: #fff; background: var(--shu); padding: .12em .35em; border-radius: 8px; transform: rotate(-3deg); box-shadow: inset 0 0 0 3px rgba(255,255,255,.6); }
.intro { margin: 0; font-size: .95rem; line-height: 1.6; max-width: 32em; color: #4a3a2e; }
.big, .mid { border-radius: 16px; font-weight: 800; 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: .9; margin-top: 2px; }
.big { font-size: 1.5rem; padding: .7rem 2.6rem; min-width: 15em; }
.primary { background: var(--shu); color: #fff; border-bottom: 5px solid var(--shu2); box-shadow: 0 6px 14px rgba(185,50,30,.35); }
.big:active, .mid:active { transform: translateY(3px) scale(.98); }
.big:hover, .mid:hover { filter: brightness(1.06); }
.home-row { display: flex; gap: .8rem; width: 100%; justify-content: center; }
.mid { font-size: 1.1rem; padding: .55rem 1rem; flex: 1; max-width: 13em; }
.alt { background: var(--ai2); color: #fff; border-bottom: 4px solid #17224a; }
.alt2 { background: #fff; color: var(--ai); border: 2px solid var(--ai2); border-bottom-width: 4px; }
.keys-hint { margin: 0; font-size: .78rem; color: #7a6a58; }
.kb { display: inline-block; border: 1.5px solid #b9a789; 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: 6px; min-width: 0; min-height: 0; }
#board.port { flex-direction: column; gap: 6px; }
#paperWrap { position: relative; flex: none; width: var(--ps, 300px); height: var(--ps, 300px); }
#paper { position: absolute; inset: 0; border-radius: 6px; overflow: hidden; background: #fffdf8; box-shadow: 0 0 0 3px #e6d6b5, 0 0 0 6px var(--sumi), 0 10px 26px rgba(0,0,0,.4); 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(51,36,28,.82); color: #fff; padding: .3rem .9rem; border-radius: 99px; font-size: .85rem; pointer-events: none; white-space: nowrap; transition: opacity .4s; }
.hint.gone { opacity: 0; }

#tools { flex: none; display: grid; grid-auto-flow: row; gap: 5px; background: var(--washi); padding: 6px; border-radius: 14px; box-shadow: 0 0 0 3px var(--sumi), 0 6px 16px rgba(0,0,0,.3); }
#board.port #tools { grid-auto-flow: column; grid-template-rows: auto; }
.tool { width: var(--tb, 44px); height: var(--tb, 44px); border-radius: 10px; display: grid; place-items: center; position: relative; background: #fff; border: 2px solid #d9c7a5; transition: transform .1s, background .15s; }
.tool svg { width: 74%; height: 74%; }
.tool.on { background: var(--shu); border-color: var(--shu2); color: #fff; transform: translateY(-1px); box-shadow: 0 3px 0 var(--shu2); }
.tool:active { transform: scale(.92); }
.tool .tl { position: absolute; bottom: -1px; left: 0; right: 0; font-size: 9px; line-height: 1; font-weight: 700; display: none; }
.tool .badge { position: absolute; top: -5px; right: -5px; background: var(--ai); color: #fff; font-size: 10px; font-weight: 800; border-radius: 99px; padding: 1px 4px; border: 1.5px solid #fff; }

#side { flex: none; width: var(--sw, 260px); display: flex; flex-direction: column; gap: 8px; background: var(--washi); padding: 8px; border-radius: 14px; box-shadow: 0 0 0 3px var(--sumi), 0 6px 16px rgba(0,0,0,.3); max-height: 100%; }
#board.port #side { width: var(--ps); gap: 5px; padding: 6px; }
.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: 50%; border: 2px solid rgba(0,0,0,.18); position: relative; transition: transform .1s; }
.sw.on { transform: scale(1.12); box-shadow: 0 0 0 2.5px #fff, 0 0 0 5px var(--sumi); 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: 700; flex: none; }
#size { flex: 1; min-width: 0; accent-color: var(--shu); height: 26px; }
.sz-dot { width: 34px; height: 34px; flex: none; display: grid; place-items: center; background: #fff; border-radius: 8px; border: 1.5px solid #d9c7a5; }
.sz-dot i { display: block; border-radius: 50%; background: var(--sumi); }
.stamps { display: grid; grid-template-columns: repeat(var(--sc, 6), 1fr); gap: 4px; width: 100%; }
.st { aspect-ratio: 1; background: #fff; border-radius: 9px; border: 2px solid #d9c7a5; display: grid; place-items: center; padding: 2px; }
.st canvas { width: 100%; height: 100%; }
.st.on { border-color: var(--shu); background: #ffe9e3; box-shadow: 0 0 0 2px var(--shu); }
.now-sec { font-size: .78rem; color: #6b5a48; justify-content: center; font-weight: 700; flex-wrap: wrap; }
#board.port .now-sec { display: none; }

/* overlay */
#ov { position: absolute; inset: 0; background: rgba(15,22,45,.6); display: grid; place-items: center; z-index: 20; padding: 10px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.panel { background: var(--washi); border-radius: 20px; padding: 1.1rem 1.3rem; max-width: min(640px, 100%); width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: .7rem; box-shadow: 0 0 0 4px #fff8, 0 0 0 8px var(--ai2), 0 20px 50px rgba(0,0,0,.5); animation: pop .25s cubic-bezier(.3,1.5,.5,1); text-align: center; }
.panel.wide { max-width: min(820px, 100%); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.panel h2 { margin: 0; font-family: var(--mincho); font-size: 1.5rem; }
.panel p { margin: 0; line-height: 1.5; font-size: .92rem; }
.scroll { overflow-y: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }
.btns { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; flex: none; }
.btn { font-weight: 800; font-size: 1.05rem; padding: .55rem 1.3rem; border-radius: 12px; background: #fff; color: var(--ai); border: 2px solid var(--ai2); border-bottom-width: 4px; }
.btn.p { background: var(--shu); color: #fff; border-color: var(--shu2); }
.btn.b { background: var(--ai2); color: #fff; border-color: #17224a; }
.btn:active { transform: translateY(2px); }
.guard .btn, .guard a.btn { pointer-events: none; opacity: .75; }
a.btn { text-decoration: none; display: inline-block; }

.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.lv { border-radius: 14px; padding: .7rem .4rem; background: #fff; border: 2px solid #d9c7a5; border-bottom-width: 5px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 800; font-size: 1.15rem; }
.lv small { font-weight: 600; font-size: .72rem; color: #7a6a58; }
.lv .best { color: var(--shu); font-size: .78rem; }
.lv:hover { border-color: var(--shu); }
.lv:active { transform: translateY(2px); }

.odai-card { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .4rem 0; }
.odai-no { font-size: .9rem; font-weight: 700; color: #7a6a58; }
.odai-word { font-family: var(--mincho); font-size: 2.8rem; font-weight: 800; line-height: 1.15; padding: .1em .5em; border-bottom: 4px double var(--shu); word-break: keep-all; overflow-wrap: anywhere; }

.result { display: flex; gap: 1rem; align-items: stretch; justify-content: center; }
.res-card { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; background: #fff; border-radius: 14px; padding: .6rem; border: 2px solid #e6d6b5; position: relative; }
.res-card .lbl { font-size: .78rem; font-weight: 700; color: #7a6a58; }
.res-card .odai-word { font-size: 2rem; }
.res-pic { width: min(34vh, 260px); aspect-ratio: 1; border-radius: 8px; box-shadow: 0 0 0 2px #e6d6b5; background: #fffdf8; }
.res-mike { width: min(16vh, 110px); height: auto; }
.hanko { position: absolute; right: -6px; top: -10px; width: 5.2rem; height: 5.2rem; transform: rotate(-12deg) scale(.3); opacity: 0; animation: hanko .45s .35s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes hanko { to { transform: rotate(-12deg) scale(1); opacity: .92; } }
.pts { font-size: .82rem; color: #5a4a3a; line-height: 1.5; }
.pts b { color: var(--shu); font-size: 1.15em; }
.note { font-size: .72rem !important; color: #8a7a68; }

.gal { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
.gal button { min-width: 0; width: 100%; background: #fff; border-radius: 10px; padding: 4px; border: 2px solid #e6d6b5; display: flex; flex-direction: column; gap: 2px; font-size: .72rem; font-weight: 700; color: #6b5a48; }
.gal button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gal img { flex: none; width: 100%; aspect-ratio: 1; border-radius: 6px; display: block; }
.gal .empty { aspect-ratio: 1; border: 2px dashed #d9c7a5; border-radius: 10px; display: grid; place-items: center; color: #b3a283; font-size: .8rem; }
.big-pic { width: min(56vh, 420px, 100%); aspect-ratio: 1; margin: 0 auto; border-radius: 10px; box-shadow: 0 0 0 3px #e6d6b5; display: block; }
.words { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.words span { background: #fff; border: 1.5px solid #e6d6b5; border-radius: 8px; padding: 3px 8px; font-size: .82rem; color: #a89878; }
.words span.got { color: var(--sumi); border-color: var(--shu); background: #fff3ef; font-weight: 700; }
.words span.got::before { content: "◎ "; color: var(--shu); }
.words h4 { width: 100%; margin: .4rem 0 0; font-size: .85rem; text-align: left; }

#toast { position: absolute; left: 50%; top: calc(var(--bar) + 12px); transform: translateX(-50%); background: var(--sumi); color: #fff; padding: .45rem 1rem; border-radius: 99px; font-size: .9rem; z-index: 30; pointer-events: none; box-shadow: 0 6px 16px rgba(0,0,0,.3); white-space: nowrap; }
.confetti { position: absolute; pointer-events: none; z-index: 25; font-size: 1.2rem; animation: fall 1.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(70vh) rotate(540deg); opacity: 0; } }

/* short windows (store frame 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  :root { --bar: 38px; }
  .home { padding: .9rem 1.4rem .9rem 1rem; gap: 1.2rem; }
  .mike { width: min(26vw, 30vh + 40px, 200px); }
  .logo .l1 { font-size: 2.3rem; } .logo .l2 { font-size: 1.6rem; }
  .home-main { gap: .55rem; }
  .intro { font-size: .85rem; line-height: 1.45; }
  .big { font-size: 1.3rem; padding: .5rem 2rem; }
  .panel { padding: .8rem 1rem; gap: .5rem; border-radius: 16px; }
  .panel h2 { font-size: 1.25rem; }
  .odai-word { font-size: 2.2rem; }
  .res-pic { width: min(44vh, 220px); }
  .hanko { width: 4.2rem; height: 4.2rem; }
  .gal { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-height: 420px) {
  :root { --bar: 34px; }
  .intro { display: none; }
  .keys-hint { display: none; }
  .mike { width: min(24vw, 160px); }
  .res-mike { display: none; }
  .big-pic { width: min(52vh, 300px); }
}
/* phone portrait */
@media (max-aspect-ratio: 4/5) {
  :root { font-size: clamp(12px, 3.3vw + 2px, 18px); }
  .home { flex-direction: column; gap: .6rem; padding: 1rem; }
  .mike { width: min(40vw, 22vh, 170px); }
  .logo .l1 { font-size: 2.2rem; } .logo .l2 { font-size: 1.5rem; }
  .big { min-width: 0; width: 100%; padding: .6rem 1rem; }
  .home-row { flex-direction: row; }
  .mid { max-width: none; font-size: 1rem; }
  .result { flex-direction: column; align-items: center; }
  .res-card { width: 100%; flex: none; }
  .res-pic { width: min(56vw, 30vh); }
  .res-mike { display: none; }
  .levels { grid-template-columns: 1fr; }
  .lv { flex-direction: row; justify-content: space-between; padding: .6rem 1rem; }
  .gal { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .done-btn { padding: 0 8px; font-size: .9rem; }
}

#bgFx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
#app { z-index: 1; }
