/* Flower shop, chapter 1 — layout works on desktop and phones (landscape and portrait). */
:root {
  --ink: #2E2A26; --muted: #7A6F64; --cream: #FFF9EE; --paper: #FBF4E6; --line: rgba(70,42,32,.85);
  --wood: #C9935F; --wood-dark: #8A5A30; --green: #4CA35E; --amber: #F2A65A; --rose: #D9708A;
  --cell: 64px; --fs: clamp(14px, 1.55vw, 19px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif; color: var(--ink); font-size: var(--fs);
  background: linear-gradient(#F4EFE3, #E9DFCB); overflow: hidden; touch-action: manipulation;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; cursor: pointer; border: 2px solid var(--wood-dark); border-radius: 10px; background: var(--cream); color: var(--ink);
  padding: .35em .9em; min-height: 44px; box-shadow: 0 3px 0 var(--wood-dark); }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-dark); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--amber); }
.hidden { display: none !important; }

#app { height: 100%; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: minmax(220px, 27%) 1fr; grid-template-rows: auto 1fr auto;
  grid-template-areas: "top top" "orders work" "tip tip"; }
#top { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 4px 6px; }
#top .title { font-weight: bold; font-size: 1.15em; }
#top .title small { font-weight: normal; color: var(--muted); margin-left: .4em; }
#money { margin-left: auto; font-weight: bold; white-space: nowrap; }
#top .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#menu-btn { white-space: nowrap; }

/* orders */
#orders { grid-area: orders; display: flex; flex-direction: column; gap: 10px; overflow: auto; padding: 2px; }
.order { background: var(--paper); border: 2px solid #E2D3B8; border-radius: 14px; padding: 10px 12px; box-shadow: 0 2px 8px rgba(80,60,30,.10); }
.order.ready { border-color: var(--green); box-shadow: 0 0 0 3px rgba(76,163,94,.25); }
.order.done { opacity: .75; }
.order .who { font-weight: bold; }
.order .who small { font-weight: normal; color: var(--muted); margin-left: .3em; font-size: .82em; }
.order .what { margin: 2px 0 6px; }
.order .needs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.need { display: flex; align-items: center; gap: 3px; background: #fff; border-radius: 10px; padding: 2px 6px 2px 2px; border: 1px solid #EADFC9; font-size: .9em; }
.need img { width: 34px; height: 34px; }
.need.ok { border-color: var(--green); color: #2E7D32; }
.need .cnt { font-weight: bold; min-width: 2.2em; text-align: center; }
.order .act { margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.order .reward { color: var(--muted); font-size: .9em; }
.order .badge { color: #2E7D32; font-weight: bold; }
.order.flash { animation: flash .8s ease; }
@keyframes flash { 0% { background: #E4F6E2; } 100% { background: var(--paper); } }

/* work area: generators + board on the workbench */
#work { grid-area: work; display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 0; min-width: 0; }
#gens { display: flex; flex-direction: column; gap: 12px; }
.gen { width: calc(var(--cell) * 1.35); height: calc(var(--cell) * 1.35); min-width: 64px; min-height: 64px; padding: 4px; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; background: #FFF7E8; }
.gen img { width: 72%; height: 72%; pointer-events: none; }
.gen span { font-size: .8em; line-height: 1.1; }
.gen.bump { animation: bump .25s ease; }
@keyframes bump { 50% { transform: scale(1.08); } }
#bench { background: linear-gradient(#D7A46F, #C08754); padding: 10px; border-radius: 16px; box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 4px 0 #8A5A30, 0 8px 16px rgba(80,50,20,.25); }
#board { display: grid; grid-template-columns: repeat(7, var(--cell)); grid-template-rows: repeat(5, var(--cell)); gap: 4px; touch-action: none; }
.cell { width: var(--cell); height: var(--cell); border-radius: 10px; background: rgba(255,248,232,.55); border: 1px solid rgba(138,90,48,.25);
  position: relative; display: flex; align-items: center; justify-content: center; user-select: none; }
.cell img { width: 92%; height: 92%; pointer-events: none; -webkit-user-drag: none; }
.cell.sel { outline: 3px solid var(--amber); outline-offset: -3px; background: #FFF3D6; }
.cell.match { box-shadow: inset 0 0 0 3px rgba(76,163,94,.55); }
.cell.over { background: #FFF0C2; }
.cell.dim img { opacity: .3; }
.cell.pop img { animation: pop .3s ease; }
.cell.merged img { animation: merged .45s ease; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes merged { 0% { transform: scale(1.35); filter: brightness(1.3); } 100% { transform: scale(1); filter: none; } }
.lvl { position: absolute; right: 4px; bottom: 2px; font-size: 11px; color: var(--wood-dark); font-weight: bold; }

#ghost { position: fixed; pointer-events: none; z-index: 30; width: var(--cell); height: var(--cell); transform: translate(-50%, -50%) scale(1.1); filter: drop-shadow(0 6px 8px rgba(0,0,0,.25)); }
#ghost img { width: 100%; height: 100%; }

/* 小满's tip bar */
#tip { grid-area: tip; background: rgba(46,42,38,.9); color: #FFF6E2; border-radius: 12px; padding: 8px 14px; min-height: 44px; display: flex; align-items: center; gap: .5em; }
#tip b { color: #FFD9A0; white-space: nowrap; }

/* dialogs */
#modal { position: fixed; inset: 0; background: rgba(30,25,20,.45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.box { background: var(--cream); border-radius: 16px; padding: 18px 20px; max-width: 520px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.box h2 { margin: 0 0 8px; font-size: 1.2em; }
.box p { margin: 6px 0; line-height: 1.6; }
.box .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; justify-content: flex-end; }
.ribbons { display: flex; gap: 12px; justify-content: center; margin-top: 10px; }
.ribbons button { display: flex; flex-direction: column; align-items: center; padding: 6px 10px; }
.ribbons img { width: 56px; height: 56px; }
#toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(46,42,38,.92); color: #FFF6E2; padding: 8px 16px; border-radius: 12px; z-index: 50; }

/* phones held upright: orders on top (scroll sideways), generators in a row, board full width */
@media (max-aspect-ratio: 1/1) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; grid-template-areas: "top" "orders" "work" "tip"; }
  #orders { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
  .order { min-width: 230px; flex: 0 0 auto; }
  #work { flex-direction: column; justify-content: flex-start; }
  #gens { flex-direction: row; }
  #top { gap: 10px; }
  #top .title small { display: none; }
}
/* short landscape screens (phones on their side): tighter spacing */
@media (max-height: 480px) and (min-aspect-ratio: 1/1) {
  #app { gap: 6px; padding: 6px; grid-template-columns: minmax(200px, 30%) 1fr; }
  .order { padding: 6px 8px; }
  .order .what { display: none; }
  .need img { width: 28px; height: 28px; }
  #tip { padding: 4px 10px; }
}

/* ---------- step 2: dialogue, 阿婆's note, the card ---------- */
.soft { color: var(--muted); }
.order.held { border-style: dashed; border-color: #C9A27A; }
.badge.held { color: var(--wood-dark); font-weight: normal; }
.card-need .card-ico { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--wood-dark); }
.card-need .cnt { min-width: 0; font-weight: normal; font-size: .9em; }

#story { position: fixed; inset: 0; z-index: 35; display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  background: rgba(30,25,20,.38); cursor: pointer; user-select: none;
  padding: 12px calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); }
#story[data-kind="note"] { justify-content: center; }
#story[data-kind="note"] .st-box, #story:not([data-kind="note"]) .st-note { display: none; }
.st-box { width: 100%; max-width: 860px; display: flex; gap: 16px; align-items: stretch; background: var(--cream); border: 2px solid var(--wood-dark);
  border-radius: 18px; padding: 12px 16px; box-shadow: 0 4px 0 var(--wood-dark), 0 12px 30px rgba(0,0,0,.3); animation: rise .25s ease; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
#st-face { width: 136px; height: 136px; flex: none; border-radius: 14px; border: 2px solid #E2D3B8;
  background: radial-gradient(circle at 30% 25%, #FFF8E6 0%, #EEF1E4 45%, #DCE2CE 100%); }
#story.noface #st-face { display: none; }
.st-words { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#st-name { font-weight: bold; color: var(--wood-dark); font-size: 1.05em; min-height: 1.3em; }
#st-text { font-size: max(16px, var(--fs)); line-height: 1.7; min-height: 3.4em; flex: 1; }
#story[data-kind="narr"] #st-text { color: #5E5248; font-style: italic; }
.st-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; min-height: 44px; }
#st-next { color: var(--muted); font-size: .85em; animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { opacity: .45; } }
.st-paper { position: relative; max-width: 460px; background: repeating-linear-gradient(#FFFBF0 0 31px, #EADFC9 31px 32px); color: #3E3328;
  font-family: "KaiTi", "STKaiti", "Kaiti SC", serif; font-size: max(20px, 1.5em); line-height: 32px; padding: 32px 32px 22px;
  border-radius: 4px; transform: rotate(-1.5deg); box-shadow: 0 2px 0 #D9CAAE, 0 14px 30px rgba(0,0,0,.35); animation: rise .3s ease; }
.st-paper i { display: block; text-align: right; font-style: normal; color: var(--muted); margin-top: 6px; font-size: .85em; }

/* the card window */
#modal.top { align-items: flex-start; padding-top: calc(12px + env(safe-area-inset-top)); }
.card-box { max-height: calc(100vh - 32px); overflow: auto; }
.ways { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.way { text-align: left; display: flex; flex-direction: column; gap: 2px; width: 100%; padding: .5em .9em; }
.way span { color: var(--muted); font-size: .9em; }
.write-box textarea { width: 100%; font: inherit; font-size: 18px; line-height: 1.5; padding: 10px 12px; border: 2px solid var(--wood); border-radius: 10px;
  background: #FFFDF6; color: var(--ink); resize: none; }
.write-box textarea:focus { outline: 3px solid rgba(242,166,90,.5); }
.w-info { display: flex; justify-content: space-between; gap: 10px; font-size: .88em; margin-top: 6px; min-height: 1.4em; }
#w-count { white-space: nowrap; color: var(--muted); }
#w-count.over { color: #C62828; font-weight: bold; }

@media (max-aspect-ratio: 1/1) {
  .st-box { gap: 10px; padding: 10px 12px; }
  #st-face { width: 92px; height: 92px; }
}
@media (max-height: 480px) and (min-aspect-ratio: 1/1) {
  #story { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .st-box { padding: 8px 12px; }
  #st-face { width: 104px; height: 104px; }
  #st-text { min-height: 2.6em; line-height: 1.55; }
  .st-paper { font-size: 18px; line-height: 28px; background: repeating-linear-gradient(#FFFBF0 0 27px, #EADFC9 27px 28px); padding: 18px 24px 14px; }
  .way { padding: .3em .8em; }
  .ways { gap: 6px; }
}

/* ---------- step 3: the street (delivery cart) ---------- */
#street { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: #E4F2EC;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.sv-stage { flex: 1; min-height: 0; position: relative; }
#sv-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.sv-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: rgba(46,42,38,.92); color: #FFF6E2; }
#sv-tip { flex: 1; min-width: 0; line-height: 1.5; font-size: max(15px, var(--fs)); }
#sv-push, #sv-back { min-height: 56px; min-width: 132px; font-weight: bold; font-size: 1.05em; touch-action: none; user-select: none; -webkit-user-select: none; }
#sv-push.holding { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-dark); background: #F7BD7E; }
.order .go-cart { margin-right: auto; }
@media (max-aspect-ratio: 1/1) {
  .sv-bar { flex-wrap: wrap; }
  #sv-tip { flex-basis: 100%; }
  #sv-push, #sv-back { flex: 1; }
}
@media (max-height: 480px) and (min-aspect-ratio: 1/1) {
  .sv-bar { padding: 6px 12px; }
  #sv-push, #sv-back { min-height: 48px; }
}

/* ---------- step 4: walking, window flowers ---------- */
#street-btn { white-space: nowrap; }
#sv-canvas { cursor: pointer; }
.windows button { min-width: 96px; }
.windows small { color: var(--muted); }
@media (max-aspect-ratio: 1/1) { #top { gap: 6px; } #street-btn, #menu-btn { padding: .35em .6em; } .windows { gap: 8px; } .windows button { min-width: 0; flex: 1; } .windows img { width: 48px; height: 48px; } }

/* step 6: the play notes box */
#modal textarea.notes { width: 100%; font: inherit; font-size: max(14px, .9em); line-height: 1.6; border: 1px solid #E2D3B8; border-radius: 10px; padding: 8px 10px; background: #FFFDF7; color: var(--ink, #3A2E26); resize: none; }
.chapter-end h2 { margin-top: 2px; }

/* street zoom buttons */
.sv-zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.sv-zoom button { width: 40px; height: 40px; padding: 0; border-radius: 10px; font-size: 22px; line-height: 1; background: rgba(255,250,240,.9); border: 1px solid #D9C7A6; color: #5A4636; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
#sv-canvas.dragging { cursor: grabbing; }

/* closed shops: the owner's notice */
.notice-box h2 { text-align: center; }
.notice-paper { background: #FFFDF4; border: 1px solid #E6DCC4; border-radius: 4px; padding: 12px 16px 10px; margin: 6px 4px 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.10); transform: rotate(-1deg); position: relative; font-size: 1.05em; line-height: 1.8; }
.notice-paper::before { content: ""; position: absolute; left: 50%; top: -7px; width: 46px; height: 14px; margin-left: -23px; background: rgba(240,210,120,.75); }
.notice-paper p { margin: 0; }
.notice-paper .sign { text-align: right; margin-top: 4px; color: #6A5A4A; }

/* grandma's drawer and sketch */
#drawer-btn { white-space: nowrap; }
.sketch-box { max-width: 720px; background: #FBF6EA; background-image: repeating-linear-gradient(0deg, rgba(120,100,70,.05) 0 1px, transparent 1px 22px); }
.sketch-box h2 { text-align: center; margin-bottom: 2px; }
.sketch-title { text-align: center; margin: 0 0 8px; font-style: italic; color: #6A5440; letter-spacing: .05em; }
.sketch-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.sketch-box { max-height: 94vh; overflow-y: auto; }
.sketch-grid figure { margin: 0; text-align: center; min-width: 0; }
.sketch-grid canvas { width: 100%; aspect-ratio: 1 / 1.05; display: block; border-radius: 6px; background: rgba(255,255,255,.55); border: 1px dashed #CDBB9A; }
.sketch-grid canvas.pencil { filter: grayscale(1) contrast(.55) brightness(1.3); opacity: .8; }
.sketch-grid .is-done canvas { border: 2px solid #E39BB0; background: #FFF; }
.sketch-grid .is-next canvas { border: 2px dashed #E0B84A; }
.sketch-grid figcaption { font-size: max(12px, .82em); line-height: 1.5; margin-top: 4px; color: #5A4636; }
.sketch-grid figcaption b { display: inline-block; width: 1.4em; height: 1.4em; line-height: 1.4em; border-radius: 50%; background: #E9DCC4; font-size: .85em; }
.sketch-grid .done { color: #C2557A; font-weight: bold; }
.sketch-grid .next { color: #B07A1A; font-weight: bold; }
.sketch-grid .later { color: #9A8A78; }
@media (max-width: 560px) { .sketch-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.drawer-items { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 12px; }
.drawer-items button { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; text-align: left; background: #FFFDF4; border: 1px solid #E2D3B8; border-radius: 10px; }
.drawer-items button span { font-size: .85em; color: #8A7A66; }
.drawer-items button[disabled] { opacity: .5; }
#money .money-hint { font-size: .8em; color: #B07A1A; }
@media (max-width: 600px) { #money .money-hint { display: none; } }

/* the old photo */
.photo-box { max-width: 420px; }
.old-photo { background: #FFFDF6; padding: 10px 10px 26px; margin: 4px auto 10px; width: min(320px, 100%); box-shadow: 0 3px 10px rgba(0,0,0,.18); transform: rotate(-2deg); }
.old-photo canvas { width: 100%; aspect-ratio: 4 / 3; display: block; filter: sepia(.75) contrast(.9) brightness(1.02); }

/* add to home screen */
#modal ol.steps { margin: 6px 0 10px; padding-left: 1.4em; line-height: 1.9; }
