/* Keep the complete play screen inside the browser's available viewport. */
html{height:100%}
body{height:100vh;height:100dvh;min-height:0;display:flex;flex-direction:column;padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px)}
.topbar{flex:none;width:calc(100% - 24px);max-width:1080px;margin:0 auto;padding:7px 0;min-height:46px}
.topbar nav{gap:10px}.nav-button{font-size:11px;padding:7px 0}.icon-button{width:32px;height:32px}
main{flex:1;min-height:0;width:100%;padding:6px 10px 8px;display:flex;justify-content:center}
.game-layout{width:100%;max-width:500px;min-height:0;margin:0;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto auto minmax(0,1fr);gap:5px;align-items:stretch}
.left-column{grid-column:1;grid-row:1;display:block;width:auto;margin:0;padding:0;min-width:0}
.score-card{display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto auto;gap:2px 8px;padding:7px 10px;box-shadow:none;border-radius:8px;align-items:center}
.score-main{grid-area:1/1;gap:8px}.score-card h2{font-size:14px}.score-value strong{font-size:28px;line-height:1.15}.score-value>span{font-size:12px}
.best-row{grid-area:2/1;gap:2px 7px;margin:0;font-size:14px;justify-content:flex-start;color:var(--ink)}.best-row b{font-size:18px}
.restart-button{grid-column:2;grid-row:1/3;align-self:center;min-height:44px;padding:8px;font-size:14px;margin:0}
.instruction-panel{grid-column:1;grid-row:2;min-width:0;padding:1px 3px 0}
.bread-guide{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:9px}
.guide-item{position:relative;line-height:1.35}.guide-item canvas{width:40px;height:33.333px}.guide-item>span{font-size:12px;color:#71583b}.guide-item strong{font-size:13px;line-height:1.5}
.guide-item:not(:last-child)::after{content:'›';position:absolute;right:-8px;top:17px;color:#9a7b4e;font-size:23px;line-height:1}
.guide-goal strong{color:#a94f31}.burn-note{display:flex;justify-content:flex-end;align-items:center;gap:3px;margin-top:1px;color:#71583b;font-size:11px;line-height:1.4}.burn-note canvas{width:20px;height:20px}
.play-column{grid-column:1;grid-row:3;width:100%;min-height:0;min-width:0;display:flex;flex-direction:column;order:initial}
.board-top{flex:none;padding:0 3px 2px;min-height:20px;gap:8px;letter-spacing:0}.board-label{font-size:12px;color:#71583b;white-space:nowrap}.bag-record{font-size:12px;padding:0;margin:0;border:0;white-space:nowrap}.bag-record b{font-size:14px;margin:0 2px}
.stage-area{position:relative;flex:1;min-height:0;display:flex;justify-content:center;align-items:flex-start}
.canvas-wrap{flex:none;aspect-ratio:640/820;width:100%;height:auto;max-width:none;max-height:100%;margin:0}
#gameCanvas{width:100%;height:100%}
.bag-deadline,.bag-fullness{top:2px;width:29%;max-width:130px;padding:5px 3px;border-radius:8px;background:#fffaf0ed}
.bag-deadline{left:1%}.bag-fullness{right:1%}
.bag-deadline>span,.bag-fullness>span{font-size:12px;line-height:1.4}
.bag-deadline>strong{font-size:13px;margin-top:2px}.bag-deadline b{font-size:27px;line-height:1.2;vertical-align:-1px}
.bag-fullness b{font-size:26px}.bag-fullness small{font-size:11px}.bag-fullness>strong{margin:2px 0 3px}.bag-progress{height:8px;margin:0 2px 3px}#deadlineClear{font-size:22px;padding:2px 0}
.start-overlay,.pause-overlay{left:10%;right:10%;top:45%;padding:13px 8px;transform:translateY(-25%);border-radius:10px}
.start-overlay h2,.pause-overlay h2{font-size:16px;margin:0 0 8px;line-height:1.5;letter-spacing:0}.start-overlay p,.pause-overlay p{font-size:12px;line-height:1.5;margin:0 0 10px}.start-overlay .primary-button,.pause-overlay .primary-button{font-size:14px;min-height:44px;padding:9px 12px;width:100%}.pause-overlay .eyebrow{display:none}
.toast{font-size:12px;max-width:96%;white-space:normal;text-align:center;border-radius:12px;padding:8px 10px;bottom:8%}
.dough-card{display:block;padding:0 3px 2px;border-radius:8px;background:#f5eddd}
.card-heading{justify-content:center;line-height:1.35}.card-heading h2{font-size:12px;font-weight:500;margin:1px 0 0}
.dough-queue{display:flex;flex-direction:row;flex-wrap:nowrap;gap:5px;margin:0}
.dough-slot{display:flex;flex-direction:column;align-items:center;flex:none;width:46px;padding:0;border-radius:6px}.dough-slot canvas{width:36px;height:36px}.dough-slot small{display:block;font-size:11px;line-height:1.4;color:#71583b}.dough-slot.next{border-color:#9d7542;background:#f3dfb9}.dough-slot.next small{font-weight:700}
@media(max-width:360px){
  main{padding:4px 8px 5px}.game-layout{gap:4px}.topbar{min-height:42px;padding:5px 0}.topbar nav{gap:5px}.nav-button{font-size:10px}.icon-button{width:28px;height:28px}
  .score-card{padding:6px 8px}.score-main{gap:5px}.score-value strong{font-size:26px}.best-row{gap:1px 5px}.best-row b{font-size:17px}.restart-button{font-size:13px;padding:7px}
  .bread-guide{gap:7px}.guide-item strong{font-size:12px}.guide-item>span{font-size:11px}.guide-item:not(:last-child)::after{right:-6px}.dough-queue{gap:3px}.dough-slot{width:43px}
}
@media(min-width:900px){
  .topbar{min-height:60px}.game-layout{max-width:900px;grid-template-columns:190px minmax(0,600px);grid-template-rows:auto minmax(0,1fr);column-gap:20px;justify-content:center}
  .instruction-panel{grid-column:1/-1;grid-row:1;max-width:600px;width:100%;justify-self:center}.guide-item canvas{width:48px;height:40px}
  .left-column{grid-column:1;grid-row:2;align-self:start}.score-card{display:flex;gap:14px;padding:16px 12px}.score-main{align-self:flex-start}.best-row{flex-wrap:wrap;justify-content:space-between}.restart-button{order:3;width:100%}
  .play-column{grid-column:2;grid-row:2}.dough-slot{width:52px}.dough-slot canvas{width:40px;height:40px}
}
@media(max-height:620px){
  .topbar{padding-top:3px;padding-bottom:3px;min-height:38px}.game-layout{gap:3px}.score-card{padding-top:4px;padding-bottom:4px}
  .guide-item canvas{width:34px;height:28.333px}.guide-item>span{font-size:11px}.guide-item strong{font-size:12px;line-height:1.3}.burn-note{font-size:11px;margin-top:0}.burn-note canvas{width:16px;height:16px}
  .bag-deadline,.bag-fullness{padding:3px 2px}.bag-deadline>span,.bag-fullness>span{font-size:11px}.bag-deadline b{font-size:23px}.bag-fullness b{font-size:23px}
  .dough-slot canvas{width:30px;height:30px}.start-overlay,.pause-overlay{padding:8px 6px;top:40%;left:5%;right:5%}.start-overlay h2,.pause-overlay h2{font-size:14px;margin-bottom:5px}.start-overlay p,.pause-overlay p{font-size:11px;margin-bottom:7px}
}
@media(min-width:600px) and (max-height:500px){
  .game-layout{max-width:1000px;grid-template-columns:240px minmax(0,1fr);grid-template-rows:auto minmax(0,1fr);gap:4px 16px}
  .left-column{grid-column:1;grid-row:1}.score-card{display:grid;padding:5px 7px;gap:1px 5px}.score-main{grid-area:1/1}.best-row{grid-area:2/1;font-size:14px}.best-row b{font-size:17px}.restart-button{grid-column:2;grid-row:1/3;width:auto;font-size:12px;padding:7px}
  .instruction-panel{grid-column:1;grid-row:2;align-self:center;padding:0}.bread-guide{grid-template-columns:repeat(2,minmax(0,1fr));gap:2px 12px}.guide-item:nth-child(2)::after{content:none}.guide-item:nth-child(3)::after{content:'›'}
  .burn-note{justify-content:center;text-align:center;line-height:1.2;gap:2px}.burn-note canvas{flex:none}
  .play-column{grid-column:2;grid-row:1/3}.dough-slot{width:43px}.dough-slot canvas{width:30px;height:30px}
}
/* fitBoard selects this from usable width/height after safe-area padding.
   Keep the existing layout on taller phones and desktop; free vertical space
   before shrinking the canvas. Restart and pause buttons retain their 44px targets. */
html.compact-play .topbar{min-height:38px;padding-top:3px;padding-bottom:3px}
html.compact-play main{padding:4px 8px}
html.compact-play .game-layout{gap:3px}
html.compact-play .score-card{padding:4px 8px}
html.compact-play .best-row{line-height:1.25}
html.compact-play .instruction-panel{padding-top:0}
html.compact-play .guide-item canvas{width:28px;height:23.333px}
html.compact-play .guide-item>span{font-size:11px;line-height:1.2}
html.compact-play .guide-item strong{font-size:12px;line-height:1.2}
html.compact-play .guide-item:not(:last-child)::after{top:12px}
html.compact-play .burn-note{margin-top:0;line-height:1.3}
html.compact-play .burn-note canvas{width:16px;height:16px}
html.compact-play .card-heading{line-height:1.2}
html.compact-play .dough-slot canvas{width:30px;height:30px}
html.compact-play .dough-slot small{line-height:1.2}

/* Controls share the bag's side spaces; the pan gets the former footer height. */
.stage-left,.stage-right{position:absolute;top:2px;width:29%;max-width:130px;display:flex;flex-direction:column;gap:4px;z-index:2}
.stage-left{left:1%}.stage-right{right:1%}
.stage-left .bag-deadline,.stage-right .bag-fullness{position:static;width:100%;max-width:none}
.stage-left #deadlineLabel{font-size:clamp(10px,2.7vw,12px);white-space:nowrap}
.stage-left .dough-card{width:100%;padding:1px 2px 2px}
.stage-left .card-heading h2{font-size:11px;line-height:1.25}
.stage-left .dough-queue{gap:2px;width:100%}
.stage-left .dough-slot{flex:1;min-width:0;width:0}
.stage-left .dough-slot canvas{width:min(100%,30px);height:auto;aspect-ratio:1}
.stage-left .dough-slot small{font-size:10px;line-height:1.3;white-space:nowrap}
.stage-right .undo-button{position:static;align-self:center;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;width:44px;height:44px;min-width:44px;padding:2px;font-size:18px;line-height:1}
.stage-right .undo-button small{display:block;font-size:9px;line-height:1.2}
.canvas-wrap{overflow:hidden;aspect-ratio:auto}
#gameCanvas{position:absolute;top:0;max-width:none}
#timeReadout{position:absolute;bottom:2px;transform:translateX(-50%);font-size:10px;line-height:1.2;color:#71583b;white-space:nowrap;pointer-events:none;user-select:none}
#timeReadout b{font-size:12px;font-weight:600}
.stage-result{flex:none;width:100%;min-height:40px;padding:7px;margin:3px 0 0;font-size:14px;box-shadow:none}

/* Replay actions remain easy to tap on small screens. */
.replay-heading{margin:0 0 9px;font-size:12px;color:#71583b;text-align:left}
#restartDialog .primary-button,#restartDialog .secondary-button,#resultDialog .primary-button,#resultDialog .secondary-button{min-height:48px;font-size:14px;padding:12px 8px;letter-spacing:0}
#restartDialog .text-button,#resultDialog .text-button{min-height:44px;font-size:12px;color:#71583b;margin-top:8px}
#restartDialog .dialog-heading{margin-bottom:16px}
#resultDialog .result-icon{font-size:24px;margin-bottom:3px}
#resultDialog .eyebrow{margin-bottom:6px}
#resultDialog .result-score{margin:10px 0 7px}
#resultDialog .result-score strong{font-size:52px}
#resultDialog #bestMessage{margin:10px 0 14px}
.start-overlay{z-index:3}
@media(max-width:360px){
  #restartDialog,#resultDialog{padding:20px 16px 12px}
  #restartDialog .dialog-heading h2{font-size:17px}
  #restartDialog .primary-button,#restartDialog .secondary-button,#resultDialog .primary-button,#resultDialog .secondary-button{font-size:13px}
}
/* An explicit home link uses the existing header height. On phones it takes
   the bread icon's place, keeping both the title type size and play area. */
.brand-group{display:flex;align-items:center;gap:12px;min-width:0}
.brand-group .brand{flex:none}
.home-button{position:relative;flex:none;display:inline-flex;align-items:center;justify-content:center;gap:5px;height:32px;padding:0 9px;border:1px solid var(--line);border-radius:7px;background:#fffaf0;color:#7e6953;font-size:12px;line-height:1.3;white-space:nowrap}
.home-button::before{content:'';position:absolute;inset:-6px -2px}
.home-button svg{flex:none;width:12px;height:14px}
.home-button:hover{background:#f1e8d7}
.home-button:focus-visible{outline-offset:2px}
@media(max-width:700px){
  .brand-group{gap:7px}.brand-group .brand>svg{display:none}
  .home-button{width:54px;padding:2px;gap:2px;font-size:11px;line-height:12px}
  .home-button svg{width:10px;height:12px}.home-label>span{display:block}
}
@media(max-width:360px){.brand-group{gap:4px}.home-button{width:46px;font-size:10px}.home-button svg{width:8px}}
@media(max-width:340px){.topbar{width:calc(100% - 16px)}}
