:root {
  --wall: #cfe0d4;
  --wall-dark: #b7cfbf;
  --counter: #c8a77c;
  --counter-dark: #a8865c;
  --desk: #e6d3b3;
  --paper: #fffdf6;
  --ink: #2c4a8a;
  --ink-soft: rgba(44, 74, 138, .85);
  --text: #23262b;
  --muted: #5d6670;
  --bubble: #ffffff;
  --red: #b3261e;
  --green: #3f8f5a;
  --shadow: 0 2px 0 rgba(0,0,0,.12), 0 6px 18px rgba(0,0,0,.10);
  --radius: 14px;
  --mono: "Courier New", ui-monospace, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: #9fb8a7;
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.35;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app {
  max-width: 480px; min-height: 100dvh; margin: 0 auto;
  background: var(--wall);
  display: flex; flex-direction: column;
  position: relative; overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,.18);
}
#app.shake { animation: shake .35s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translate(-1px, 1px); }
  20%, 80% { transform: translate(3px, -2px); }
  30%, 50%, 70% { transform: translate(-5px, 3px); }
  40%, 60% { transform: translate(5px, -1px); }
}

/* Door */
.door {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 14px; background: #2f3d35; color: #e8efe9; font-size: 13px;
}
.door-sign { letter-spacing: .06em; font-family: var(--mono); }
.door-stats { opacity: .85; margin-left: auto; font-variant-numeric: tabular-nums; }
.icon-btn { background: none; border: 0; padding: 2px 4px; font-size: 16px; }

.pending-bar {
  background: #fff3c4; color: #5b4a10; font-size: 14px; padding: 7px 14px;
  border-bottom: 1px solid #e9d78a; cursor: pointer;
}

/* Decree banners */
.banners { display: flex; flex-direction: column; gap: 6px; padding: 0 10px; }
.banners:not(:empty) { padding-top: 6px; padding-bottom: 2px; }
.banner {
  border: 3px double var(--red); color: var(--red); background: #fff8f6;
  font-family: var(--mono); font-size: 13px; line-height: 1.3; padding: 7px 10px;
  transform: rotate(-.6deg); box-shadow: var(--shadow); cursor: pointer;
}
.banner b { display: block; letter-spacing: .05em; }
.banner span { display: block; margin-top: 5px; }
.banner.collapsed span { display: none; }
.banner.new { animation: slam .45s ease-out; }
@keyframes slam { 0% { transform: scale(1.4) rotate(-4deg); opacity: 0; } 70% { transform: scale(.97) rotate(-.6deg); opacity: 1; } 100% { transform: rotate(-.6deg); } }

/* Scene */
.scene { position: relative; }
.wall { position: relative; height: 186px; background: linear-gradient(var(--wall), var(--wall-dark)); }
.glass {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 210px; height: 150px; border: 6px solid #8a9a90; border-bottom: 0;
  border-radius: 10px 10px 0 0; background: #e9f1ec; overflow: hidden;
}
.glass-shine { position: absolute; inset: 0; background: linear-gradient(115deg, rgba(255,255,255,.55) 0 18%, transparent 18% 30%, rgba(255,255,255,.25) 30% 34%, transparent 34%); pointer-events: none; }
.hole { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 90px; height: 16px; background: #8a9a90; border-radius: 50px 50px 0 0; }
.clerk { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: 150px; height: 146px; }
.clerk svg { width: 100%; height: 100%; display: block; }
.clerk .mouth { display: none; }
.clerk[data-mood="neutral"] .m-neutral, .clerk[data-mood="smile"] .m-smile,
.clerk[data-mood="sigh"] .m-sigh, .clerk[data-mood="talk"] .m-talk { display: inline; }
.clerk[data-mood="talk"] .m-talk { animation: talk .25s steps(2) infinite; }
@keyframes talk { 50% { transform: scaleY(.4); } }
.clerk .m-talk { transform-box: fill-box; transform-origin: center; }

.calendar {
  position: absolute; left: 10px; top: 92px; width: 68px; background: #fff; box-shadow: var(--shadow);
  border-radius: 4px; text-align: center; transform: rotate(-3deg); font-size: 12px; z-index: 1;
}
.calendar.pulse { animation: pulse 1.2s ease-in-out 2; }
@keyframes pulse { 50% { transform: rotate(-3deg) scale(1.15); } }
.cal-top { height: 12px; background: var(--red); border-radius: 4px 4px 0 0; }
.cal-body { padding: 4px 4px 6px; }
.cal-body small { display: block; color: var(--muted); font-size: 10px; }
.cal-body b { font-size: 13px; }
.clock { position: absolute; right: 18px; top: 100px; width: 42px; height: 42px; border-radius: 50%; background: #fff; border: 3px solid #5d6670; }
.clock .hand { position: absolute; left: 50%; bottom: 50%; width: 2px; background: #333; transform-origin: bottom center; }
.clock .h { height: 11px; transform: translateX(-50%) rotate(300deg); }
.clock .m { height: 15px; transform: translateX(-50%) rotate(170deg); animation: tick 60s steps(60) infinite; }
@keyframes tick { to { transform: translateX(-50%) rotate(530deg); } }

/* Speech bubble */
.bubble {
  position: absolute; left: 10px; right: 10px; top: 8px; z-index: 3;
  background: var(--bubble); border-radius: var(--radius); padding: 10px 14px;
  box-shadow: var(--shadow); font-size: 18px; font-weight: 600; min-height: 46px;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -10px; border: 10px solid transparent; border-top-color: var(--bubble); border-bottom: 0; }
.bubble.pop { animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.92); opacity: .4; } }
.bubble.baka-say { background: #fff6e8; border: 1px solid #e7cfa4; }
.bubble.baka-say::after { left: 22px; border-top-color: #fff6e8; }
.bubble .who { display: block; font-size: 12px; font-weight: 700; color: #8a5a1c; }
.bubble-sub { font-size: 14px; font-weight: 400; color: var(--muted); }
.bubble-sub:empty { display: none; }
.share-line { margin-top: 6px; background: none; border: 0; padding: 0; color: var(--ink); font-size: 13px; font-weight: 600; text-decoration: underline; }

.distant { position: absolute; inset: 0; pointer-events: none; }
.tup-far {
  position: absolute; font-family: var(--mono); font-weight: 800; color: var(--ink-soft); font-size: 14px;
  animation: far 1.8s ease-out forwards; white-space: nowrap;
}
.tup-far small { display: block; font-weight: 400; font-size: 10px; color: var(--muted); }
@keyframes far { 0% { opacity: 0; transform: scale(1.6); } 15% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: translateY(-14px); } }

/* Counter + desk */
.counter { background: var(--counter); border-top: 8px solid var(--counter-dark); padding: 8px 12px 10px; position: relative; }
.sign {
  display: flex; gap: 10px; align-items: center;
  background: #fffef8; border: 2px solid #444; border-radius: 6px; padding: 6px 12px;
  font-family: var(--mono); font-weight: 700; font-size: 15px; box-shadow: var(--shadow);
  margin-bottom: 8px; min-height: 52px;
}
.sign.flip { animation: flip .35s ease-out; }
@keyframes flip { from { transform: rotateX(80deg); } }
#signIcon { font-size: 22px; }
.sign small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.desk { display: flex; gap: 10px; align-items: flex-end; justify-content: center; background: var(--desk); border-radius: 10px; padding: 8px 10px; position: relative; height: 150px; }
.rail { position: relative; width: 64px; height: 134px; }
.notches { position: absolute; left: 2px; top: 8px; bottom: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.notches i { display: block; width: 12px; height: 2px; background: #8a7350; }
.stamp { position: absolute; left: 16px; width: 50px; top: 0; transition: top .45s cubic-bezier(.3,1.6,.5,1), left .2s ease-in; z-index: 4; }
.stamp.drop { transition: left .18s ease-in, top .16s cubic-bezier(.7,0,1,1) .18s; }
.stamp-handle { width: 22px; height: 30px; margin: 0 auto; background: #6b3b2a; border-radius: 11px 11px 4px 4px; }
.stamp-base { width: 50px; height: 14px; background: #3a3a3a; border-radius: 3px; border-bottom: 4px solid var(--ink); }
.stamp-shadow { position: absolute; left: 14px; bottom: 6px; width: 58px; height: 8px; border-radius: 50%; background: rgba(0,0,0,.25); transition: transform .4s, opacity .4s; }
.paper {
  position: relative; width: 190px; height: 128px; background: var(--paper);
  box-shadow: var(--shadow); padding: 10px 12px; transform: rotate(1.2deg); font-family: var(--mono);
}
.paper-head { font-weight: 700; letter-spacing: .2em; font-size: 12px; color: var(--muted); }
.paper-case { font-size: 13px; margin-top: 4px; min-height: 36px; }
.paper-lines i { display: block; height: 1px; background: #d8d1bf; margin: 10px 0; }
.ink {
  position: absolute; right: 8px; bottom: 6px; width: 84px; height: 84px; border-radius: 50%;
  border: 4px double var(--ink); color: var(--ink); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 9px; text-align: center; transform: rotate(-14deg);
  opacity: .88; font-family: var(--mono);
}
.ink b { font-size: 13px; letter-spacing: .05em; }
.ink.splat { animation: splat .3s ease-out; }
@keyframes splat { from { transform: rotate(-14deg) scale(1.4); opacity: 0; } }

/* Play area */
.play { padding: 10px 12px 8px; flex: 1; }
.meter-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.meter { font-weight: 700; font-size: 16px; }
.meter .dots { letter-spacing: 2px; color: var(--ink); }
.meter .warn { color: var(--red); font-weight: 600; font-size: 13px; display: block; }
.strip { display: flex; gap: 5px; }
.tok {
  width: 34px; height: 34px; border-radius: 8px; background: #fffef8; border: 2px solid #b5a98f;
  display: grid; place-items: center; font-size: 17px; position: relative;
}
.tok.cur { border-color: #222; transform: translateY(-3px); box-shadow: var(--shadow); }
.tok.done { opacity: .35; }
.tok.hidden-tok { background: #d9cdb3; color: #7a6c50; font-weight: 700; font-size: 15px; }
.hint { text-align: center; color: var(--muted); margin: 6px 0 0; font-weight: 600; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

.hand { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.card {
  position: relative; text-align: left; background: #fff; border: 0; border-radius: 12px;
  padding: 8px 10px 9px 15px; box-shadow: var(--shadow); min-height: 60px; overflow: hidden;
  font-size: 15px; font-weight: 600; transition: transform .1s, opacity .2s;
}
.hand.first .card { font-size: 16px; min-height: 66px; }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; background: var(--fam, #999); }
.card:active:not(:disabled) { transform: scale(.97); }
.card .fam { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--fam); text-transform: uppercase; margin-bottom: 2px; }
.card:disabled { cursor: default; }
.card.used { opacity: .45; box-shadow: none; }
.card .res { position: absolute; right: 8px; bottom: 5px; font-size: 12px; font-weight: 700; background: rgba(255,255,255,.9); padding: 0 3px; border-radius: 4px; }
.card.r-works .res, .card.r-zinger .res { color: var(--green); }
.card.r-backfire .res, .card.r-decree .res { color: var(--red); }
.card.r-neutral .res { color: var(--muted); }
.card .overprint {
  position: absolute; inset: auto 6px 6px auto; color: var(--red); border: 2px solid var(--red);
  font-family: var(--mono); font-size: 10px; padding: 1px 4px; transform: rotate(-6deg); background: rgba(255,255,255,.85);
}
.card.decreed { background: repeating-linear-gradient(-45deg, #fff, #fff 8px, #fff1ef 8px, #fff1ef 16px); }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.btn {
  border: 0; border-radius: 12px; padding: 14px 16px; font-weight: 700; font-size: 17px;
  background: #2f3d35; color: #fff; box-shadow: var(--shadow);
}
.btn.primary { background: var(--ink); }
.btn.ghost { background: transparent; color: var(--text); box-shadow: none; text-decoration: underline; font-weight: 600; padding: 6px; }
.small-note { font-size: 13px; color: var(--muted); text-align: center; }

.ticket {
  display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; padding: 8px 12px 14px;
  font-family: var(--mono); font-size: 13px; color: var(--muted); border-top: 1px dashed var(--wall-dark);
}
.ticket-note { font-style: italic; }

/* Baka */
.baka { position: absolute; left: 8px; right: 8px; bottom: 54px; display: flex; gap: 8px; align-items: flex-end; z-index: 5; cursor: pointer; animation: up .3s ease-out; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.baka-face { font-size: 34px; }
.baka-bubble { background: #fff6e8; border: 1px solid #e7cfa4; border-radius: var(--radius); padding: 8px 12px; font-size: 15px; box-shadow: var(--shadow); }
.baka-bubble b { display: block; font-size: 12px; color: #8a5a1c; }

/* Toast */
.toast {
  position: absolute; left: 12px; right: 12px; top: 54px; z-index: 40; background: #2f3d35; color: #fff;
  border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 15px; animation: up .25s ease-out;
}
.toast button { margin-left: 8px; background: #fff; color: #2f3d35; border: 0; border-radius: 8px; padding: 4px 10px; font-weight: 700; }

/* Overlay sheets */
.overlay { position: absolute; inset: 0; background: rgba(20,30,25,.55); z-index: 30; display: flex; align-items: flex-end; }
.sheet {
  background: var(--wall); width: 100%; max-height: 92%; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 18px 16px 22px; animation: up .3s ease-out;
}
.sheet h2 { margin: 0 0 6px; font-size: 20px; }
.sheet p { margin: 6px 0; }
.sheet .clerk-say { background: #fff; border-radius: var(--radius); padding: 10px 14px; font-weight: 600; box-shadow: var(--shadow); margin: 10px 0; }
.sheet .statements { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.sheet .statements .btn { background: #fff; color: var(--text); text-align: left; font-weight: 600; }
.sheet input {
  width: 100%; font: inherit; padding: 12px; border-radius: 10px; border: 2px solid #8a9a90; background: #fff; margin: 8px 0;
}
.err { color: var(--red); font-size: 14px; min-height: 18px; }

/* Certificate */
.cert {
  background: var(--paper); font-family: var(--mono); padding: 16px 16px 18px; position: relative;
  box-shadow: var(--shadow); border: 1px solid #e3dccb; margin: 8px 0 14px; font-size: 14px;
}
.cert h3 { margin: 0 0 8px; letter-spacing: .08em; font-size: 16px; }
.cert p { margin: 6px 0; }
.cert .witness { border-left: 3px solid var(--ink); padding-left: 8px; font-style: italic; }
.cert .seal { display: inline-block; border: 3px double var(--red); color: var(--red); padding: 3px 8px; transform: rotate(-4deg); font-weight: 800; letter-spacing: .06em; }
.cert .ink { position: absolute; right: 10px; bottom: 10px; width: 78px; height: 78px; }
.cert .foot { margin-top: 10px; color: var(--muted); padding-right: 84px; }
.witness-intro { background: #fff3c4; border-radius: 10px; padding: 10px 12px; font-size: 15px; }

@media (min-width: 481px) { body { padding: 0; } }
/* Result of one tap, stamped across the paper */
.verdict {
  position: absolute; inset: -4px -6px; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 3px; background: rgba(255,253,244,.94); border: 4px solid currentColor; border-radius: 8px;
  transform: rotate(-4deg); font-family: var(--sans, system-ui), sans-serif; padding: 4px 6px;
}
.verdict.hidden { display: none; }
.verdict.in { animation: verdictIn .28s cubic-bezier(.2,1.6,.5,1); }
.verdict b { font-size: 30px; line-height: 1; letter-spacing: .04em; }
.verdict span { font-size: 12.5px; font-weight: 700; color: #333; line-height: 1.2; }
.verdict span:last-child { font-size: 14px; color: currentColor; }
.verdict.good { color: var(--green); }
.verdict.bad { color: var(--red); }
.verdict.meh { color: #6b6b6b; }
@keyframes verdictIn { from { transform: rotate(-4deg) scale(1.8); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }

.meter .count { font-size: 13px; color: var(--muted); font-weight: 600; }
.meter.flash-good { animation: flashGood .9s; }
.meter.flash-bad { animation: flashBad .9s; }
@keyframes flashGood { 0%, 40% { background: #cfe9d6; } 100% { background: transparent; } }
@keyframes flashBad { 0%, 40% { background: #f4cdc4; } 100% { background: transparent; } }
.meter { border-radius: 8px; padding: 2px 6px; margin-left: -6px; }
.stamp.hop .stamp-handle { animation: hop .45s; }
@keyframes hop { 30% { transform: translateY(-6px) rotate(-6deg); } 60% { transform: translateY(2px); } }

/* First visit: the argument type that fits the sign glows */
.card.teach { box-shadow: 0 0 0 3px var(--fam), var(--shadow); }
.card.teach .fam { animation: teachPulse 1.1s ease-in-out infinite; }
@keyframes teachPulse { 50% { transform: scale(1.08); transform-origin: left center; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
