/* The ema rack (view #ema, js/ema.js; the drawings in js/ema-art.js). */
:root { --hand: 'Patrick Hand', 'Klee One', 'Hiragino Maru Gothic ProN', 'Comic Sans MS', cursive; --brush: 'Yuji Boku', 'Klee One', 'Hiragino Mincho ProN', 'Yu Mincho', serif; }

/* the drawing keeps its proportions and stands on the scene's floor (as the temizu) */
.em-wrap {
  position: absolute; left: 50%; bottom: 0; translate: -50% 0;
  width: min(100cqw - 4px, 76.9cqh, 440px); aspect-ratio: 400 / 520;
}
.em-art { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.em-rack { position: absolute; inset: 0; }
.em-tray-hit { position: absolute; left: 24%; top: 61%; width: 34%; height: 15%; padding: 0; border: 0; background: none; border-radius: 22px; cursor: pointer; }
.view-ema:not([data-state="idle"]) .em-tray-hit { pointer-events: none; }

/* ---------- the plaque (js/ema-art.js plaqueSVG) ---------- */
.pq { display: block; width: 100%; height: 100%; overflow: visible; }
.pq-body { fill: #fbe6cc; }
.pq-roof { fill: #f5d6b6; }
.pq-edge { fill: none; stroke: #e3b892; stroke-width: 2.4; stroke-linejoin: round; }
.pq-grain { fill: none; stroke: #f3d6bb; stroke-width: 1.6; stroke-linecap: round; }
.pq-hole { fill: #e2b58f; }
.pq-cord { fill: none; stroke: #f0a797; stroke-width: 3.6; stroke-linecap: round; }
.pq-cord-twist { fill: none; stroke: #fff; stroke-width: 1.5; stroke-dasharray: 3 4; stroke-linecap: round; }
.pq-shadow { fill: rgba(150, 110, 80, .12); }
/* your own plaques on the rack: a small lilac ribbon on the cord */
.rb { fill: #e2d9ff; stroke: #b3a5f2; stroke-width: 1.8; stroke-linejoin: round; }
.rb-tail { fill: none; stroke: #b3a5f2; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.rb-knot { fill: #cfc4ff; stroke: #b3a5f2; stroke-width: 1.6; }
/* the sheep */
.sh-wool { fill: #fffdf8; stroke: #e0d3c3; stroke-width: 2.2; stroke-linejoin: round; }
.sh-face, .sh-ear { fill: #ffe6d6; stroke: #e9c0a6; stroke-width: 2; }
.sh-ear-in { fill: #ffc9c4; }
.sh-leg { fill: #ecd0b8; stroke: #d9b296; stroke-width: 1.6; }
.dz-eye { fill: none; stroke: #6e5a6a; stroke-width: 2.4; stroke-linecap: round; }
.dz-blush { fill: #ffc4c4; opacity: .85; }
.dz-mouth { fill: none; stroke: #c98476; stroke-width: 1.8; stroke-linecap: round; }
.dz-grass { fill: none; stroke: #a9d8a6; stroke-width: 2.2; stroke-linecap: round; }
.dz-seal { fill: #ffd8ce; stroke: #eaa08c; stroke-width: 1.8; }
.dz-seal-t { font-family: var(--kanji); font-weight: 600; font-size: 14px; fill: var(--coral-ink); }
/* the daruma */
.dm-body { fill: #ffb4a8; stroke: #ea9184; stroke-width: 2.4; }
.dm-shade { fill: none; stroke: #f59d90; stroke-width: 5; stroke-linecap: round; opacity: .55; }
.dm-shine { fill: #fff; opacity: .55; }
.dm-face { fill: #fff8ef; stroke: #f0c3b6; stroke-width: 2; }
.dm-brow { fill: none; stroke: #8a7080; stroke-width: 3.6; stroke-linecap: round; }
.dm-eye { fill: #fff; stroke: #e2c2b8; stroke-width: 1.6; }
.dm-pupil { fill: #5f4d5d; }
.dm-ring { fill: none; stroke: #7d6370; stroke-width: 2; }
.dm-spark { fill: #f6cf63; }
.dm-hi { fill: #fff; }
.dm-smile { fill: none; stroke: #c97a6e; stroke-width: 2.2; stroke-linecap: round; }
.dm-belly { fill: #ffe9ad; stroke: #e5c070; stroke-width: 2; }
.dm-belly-t { font-family: var(--kanji); font-weight: 600; font-size: 17px; fill: #c48a2e; }
.dm-gold { fill: none; stroke: #f3cd6e; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* a tumbler doll: where the designs are shown large it rocks a little and rights itself */
.dm-wob { transform-box: view-box; transform-origin: 100px 157px; }
.em-pick .dm-wob, .em-read .dm-wob, .em-card .dm-wob { animation: dmWobble 2.8s ease-in-out infinite; }
@keyframes dmWobble { 0%, 100% { transform: rotate(0); } 12% { transform: rotate(-6deg); } 28% { transform: rotate(4.5deg); } 42% { transform: rotate(-2.4deg); } 54% { transform: rotate(1deg); } 64% { transform: rotate(0); } }
/* Fuji at sunrise */
.fj-sun { fill: #ffe7a6; stroke: #f1c86a; stroke-width: 2; }
.fj-ray { fill: none; stroke: #f6d27a; stroke-width: 3.4; stroke-linecap: round; }
.fj-mt { fill: #cfd8fb; stroke: #a9b4ea; stroke-width: 2.2; stroke-linejoin: round; }
.fj-snow { fill: #fff; stroke: #d4daf3; stroke-width: 1.8; stroke-linejoin: round; }
.fj-cloud { fill: #fffdfd; stroke: #e0d8f2; stroke-width: 1.8; stroke-linejoin: round; }
.fj-hill { fill: #dcf2e4; }
/* the season's design (blossom / hydrangea / maple / camellia: the hanachozu drawings, css/temizu.css) */
.mp-breeze { fill: none; stroke: #f3d2b4; stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 10 8; }
.sb-branch { fill: none; stroke: #dbb595; stroke-width: 5.5; stroke-linecap: round; }
.sb-branch.thin { stroke-width: 3.4; }
.sb-bud { fill: #ffc9d6; stroke: #f0a9bb; stroke-width: 1.4; }
.em-s { display: none; }
[data-season="spring"] .em-s.spring, [data-season="summer"] .em-s.summer,
[data-season="autumn"] .em-s.autumn, [data-season="winter"] .em-s.winter { display: inline; }

/* ---------- the rack ---------- */
.em-peg { fill: none; stroke: #e5c070; stroke-width: 2.6; stroke-linecap: round; }
.em-tray-box { fill: #f3cfae; stroke: #e2b58f; stroke-width: 2; }
.em-tray-front { fill: #f8dcc0; stroke: #e2b58f; stroke-width: 2; }
.mk-body { fill: #dcd3ff; stroke: #b3a5f2; stroke-width: 1.8; }
.mk-cap { fill: #ffc8ba; stroke: #f0a797; stroke-width: 1.8; }
.mk-tip { fill: #8b7fd0; }
.mk-shine { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; opacity: .8; }
/* idle: the tray of blank plaques glows a little (tap it, or "Write a wish") */
.view-ema[data-state="idle"] .em-tray { animation: trayCall 1.6s ease-in-out infinite; }
@keyframes trayCall { 0%, 100% { filter: none; } 50% { filter: drop-shadow(0 0 5px #fff) drop-shadow(0 0 7px #f6cf63); } }

/* the hooks: where a plaque can go; while hanging, the free ones call */
.em-hook { position: absolute; width: 0; height: 0; pointer-events: none; }
.em-hook.call::after {
  content: ''; position: absolute; left: -16px; top: -13px; width: 32px; height: 32px; border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, .95); box-shadow: 0 0 0 4px rgba(246, 207, 99, .55);
  animation: ropeCall 1.3s ease-in-out infinite;
}
/* no hook free: the hooks with room call over the plaques already there (a new one hangs in front) */
.em-hook.stack { z-index: 5; }
.em-hook.call.near::after { box-shadow: 0 0 0 7px rgba(246, 207, 99, .95); background: rgba(255, 240, 186, .7); animation: none; transform: scale(1.3); }

/* the plaques on the rack: each a button, tilted a little and swaying */
.em-plq {
  position: absolute; padding: 0; margin: 0; border: 0; background: none; cursor: pointer;
  aspect-ratio: 200 / 170; transform: rotate(var(--tilt, 0deg)); transform-origin: 50% 4%;
  filter: drop-shadow(0 3px 2px rgba(120, 90, 70, .16));
}
.em-sway { display: block; width: 100%; height: 100%; transform-origin: 50% 4%; animation: emSway 3.4s ease-in-out infinite; animation-delay: var(--delay, 0s); }
@keyframes emSway { 0%, 100% { transform: rotate(-2.6deg); } 50% { transform: rotate(2.6deg); } }
.em-plq.just { animation: justHung 1.2s ease-in-out 3; }
/* one hung in front of another on the same hook: a slightly deeper shadow on the one behind */
.em-plq.stacked { filter: drop-shadow(0 4px 3px rgba(120, 90, 70, .22)); }
.em-plq.stacked::before {
  content: ''; position: absolute; left: calc(50% - 1.5px); bottom: var(--str-b); width: 3px; height: var(--str-h);
  border-radius: 2px; background: #f0a797; transform-origin: 50% 100%; rotate: var(--str-a); pointer-events: none;
}
@keyframes justHung { 0%, 100% { filter: drop-shadow(0 3px 2px rgba(120, 90, 70, .16)); } 50% { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 10px #f6cf63); } }
.em-plq .pq-edge { vector-effect: non-scaling-stroke; stroke-width: 1.6; }
.em-plq .pq-cord { stroke-width: 6; }
.em-plq .pq-cord-twist { display: none; }
.em-plq:focus-visible { outline-offset: 1px; border-radius: 8px; }
.view-ema:not([data-state="idle"]) .em-plq { pointer-events: none; }

/* ---------- the controls ---------- */
body[data-view="ema"] { --sb-bottom: 14px; }
@media (max-height: 620px) { body[data-view="ema"] { --sb-bottom: 8px; } }
.em-controls { height: calc(var(--ctl) + 18px + env(safe-area-inset-bottom)); gap: 6px; padding-top: 8px; }
.em-controls .hint, .em-controls .steps, .em-controls .quiet { position: relative; z-index: 3; }
.em-actions { display: flex; gap: 10px; justify-content: center; min-height: 50px; margin-top: 4px; }
.em-actions .btn { min-width: 150px; }
.em-status { min-height: 18px; margin: 0; }
.em-status:empty { display: none; }

/* ---------- 1. choose: the four designs, large ---------- */
.em-choose {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center;
  background: radial-gradient(closest-side, rgba(255, 252, 247, .9), rgba(255, 249, 244, .72));
}
.em-grid { display: grid; grid-template-columns: repeat(2, auto); gap: 12px 14px; }
.em-pick {
  width: min(44cqw, calc((100cqh - 74px) / 1.72), 200px);
  padding: 8px 8px 6px; border: 2.5px solid #f3d6c7; border-radius: 22px; background: #fffaf3;
  box-shadow: 0 4px 0 #f3d6c7, 0 8px 16px rgba(110, 95, 170, .1); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.em-pick:active { transform: translateY(3px); box-shadow: 0 1px 0 #f3d6c7; }
.em-pick-pq { display: block; width: 100%; aspect-ratio: 200 / 170; }
.em-pick-name { font-size: 14px; font-weight: 600; color: var(--coral-ink); line-height: 1.2; }

/* ---------- 2. write: over the view, fitted to the visual viewport (js/ema.js fitWrite) ---------- */
.em-write {
  position: fixed; z-index: 26; left: 0; right: 0; top: 0; height: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + var(--head) + 8px) 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #f8f4ff, #fff6ee);
}
.em-write .steps, .em-write .hint { flex: none; }
.em-slot { flex: 1 1 auto; min-height: 110px; width: min(100% - 24px, 360px); }
/* ten chips, money and work first: two rows that scroll sideways (column by column, so the first
   columns are the money / work ones), with a soft fade at the edge that has more */
.em-chips {
  flex: none; display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, auto); gap: 8px; justify-content: start;
  width: min(100%, 460px); padding: 2px 16px 5px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  --fl: 0px; --fr: 0px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
}
.em-chips::-webkit-scrollbar { display: none; }
.em-chips.fade-l { --fl: 34px; } .em-chips.fade-r { --fr: 44px; }
.em-chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 2px solid #f3d6c7; background: #fffaf3; color: var(--coral-ink); font-size: 15px; font-weight: 600;
  box-shadow: 0 3px 0 #f3d6c7;
}
.em-chip:active { transform: translateY(2px); box-shadow: 0 1px 0 #f3d6c7; }
.em-write.short .em-chips { grid-template-rows: auto; }
.em-write.short { gap: 6px; }
.em-local { flex: none; margin: 0; }
.em-write.tiny .em-local { display: none; }
#emDone { flex: none; min-width: 160px; }
#emDone:disabled { opacity: .45; cursor: default; box-shadow: 0 4px 0 var(--lilac-deep); transform: none; }

/* the plaque in hand: placed on the screen by js/ema.js; it turns over in 3D */
.em-card { position: fixed; z-index: 27; left: 0; top: 0; width: 200px; aspect-ratio: 200 / 170; perspective: 900px; --k: 1; }
.em-flip { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }
.em-card.back .em-flip, .em-read-card.back .em-flip { transform: rotateY(180deg); }
.em-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.em-back { transform: rotateY(180deg); }
.em-card .pq, .em-read-card .pq { filter: drop-shadow(0 8px 10px rgba(120, 90, 70, .2)); }
/* while writing there is no 3D: the back is shown flat (typing in a turned element is unreliable) */
.em-card.flat .em-flip { transform: none; }
.em-card.flat .em-front { display: none; }
.em-card.flat .em-back { transform: none; }
/* the wish field: three lines of marker handwriting, centred on the board */
.em-text-area { position: absolute; left: 14%; width: 72%; top: calc(64% - var(--k) * 41.25px); height: calc(var(--k) * 82.5px); }
.em-text-area textarea, .em-measure {
  font-family: var(--hand); font-size: calc(var(--k) * 22px); line-height: 1.25; text-align: center;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; letter-spacing: .01em;
}
.em-text-area textarea {
  display: block; width: 100%; height: 100%; box-sizing: border-box; margin: 0; padding: 0;
  border: 0; border-radius: 10px; background: transparent; resize: none; overflow: hidden;
  color: #5a4a66; caret-color: #e8958a; outline: none; -webkit-user-select: text; user-select: text;
}
.em-text-area textarea::placeholder { color: #c9a98f; opacity: 1; }
.em-text-area textarea:focus { background: rgba(255, 255, 255, .28); box-shadow: 0 0 0 2px rgba(232, 149, 138, .35); }
.em-measure { position: absolute; left: 0; top: 0; width: 100%; visibility: hidden; pointer-events: none; }
/* 3. waiting on the table to be hung: it glows; it can be dragged */
.em-card.held { cursor: grab; touch-action: none; animation: heldCall 1.5s ease-in-out infinite; }
@keyframes heldCall { 0%, 100% { filter: none; } 50% { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 9px #f6cf63); } }
.em-card.dragging { cursor: grabbing; animation: none; scale: 1.08; filter: drop-shadow(0 12px 14px rgba(110, 95, 170, .28)); }

/* ---------- reading a plaque from the rack ---------- */
.em-read { position: fixed; inset: 0; z-index: 28; cursor: pointer; }
.em-read-back { position: absolute; inset: 0; background: rgba(74, 69, 96, .34); }
.em-read-card { position: absolute; left: 50%; top: 46%; translate: -50% -50%; aspect-ratio: 200 / 170; perspective: 900px; --k: 1; outline: none; }
.em-read-text {
  position: absolute; left: 13%; width: 74%; top: 34%; height: 54%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: calc(var(--k) * 8px);
}
.em-wish { font-family: var(--hand); font-size: calc(var(--k) * 22px); line-height: 1.25; color: #5a4a66; overflow-wrap: anywhere; }
.em-by { font-size: calc(var(--k) * 13.5px); font-weight: 600; color: #a2826b; }
.em-read-actions { position: absolute; left: 0; right: 0; top: calc(46% + min(140px, 30vh)); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.em-read-note { margin: 0; padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, .85); font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.em-read-status { margin: 0; color: #fff; }
.em-read-status:empty { display: none; }

/* out of the way while writing (the panel covers the view; the season button comes back after) and
   under a plaque being read */
body[data-view="ema"]:has(#viewEma[data-state="write"]) .season-btn,
body:has(#emRead:not([hidden])) .season-btn { visibility: hidden; opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .em-sway, .em-tray, .em-hook.call::after, .em-card.held, .em-plq.just, .dm-wob { animation: none !important; }
}
