* { box-sizing: border-box; }
:root { font-family: system-ui, sans-serif; color: #594339; background: #f8edda; }
body { margin: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; gap: 8px; }
small { font-size: 10px; letter-spacing: .16em; color: #93705c; }
h1 { margin: 3px 0; font-size: clamp(17px, 4.7vw, 24px); font-weight: 650; }
#clock { border: 1px solid #c99c5b; border-radius: 50%; min-width: 44px; height: 44px; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
#stage { position: relative; min-height: 0; touch-action: none; overflow: hidden; outline-offset: -3px; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.label { position: absolute; top: 10px; width: 100%; text-align: center; font-size: 9px; letter-spacing: .17em; pointer-events: none; color: #876c54; }
#veil { position: absolute; inset: 0; background: #f8eddae8; display: grid; place-content: center; text-align: center; }
#veil[hidden] { display: none; }
footer { padding: 8px 12px max(12px, env(safe-area-inset-bottom)); background: #fff6e8; border-top: 1px solid #e2cfb3; }
#message { margin: 0 0 8px; font-size: 13px; min-height: 32px; }
.controls { display: flex; align-items: center; gap: 6px; }
.controls span { flex: 1; font-size: 10px; line-height: 1.5; }
button { min-height: 44px; min-width: 44px; padding: 8px; border: 1px solid #c2a079; border-radius: 14px; background: #fffaf0; color: #594339; font: inherit; font-size: 12px; cursor: pointer; }
button:focus-visible, #stage:focus-visible { outline: 2px solid #9f5787; }
@media (max-width: 350px) { header { padding: 8px 10px; } footer { padding: 8px; } .controls { flex-wrap: wrap; } .controls span { flex-basis: 100%; } }
@media (max-height: 450px) {
  body { grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  header { flex-wrap: wrap; padding: 8px; } h1 { font-size: 18px; }
  #stage { grid-column: 2; grid-row: 1 / 3; } footer { padding: 8px; }
  .controls { flex-wrap: wrap; } .controls span { flex-basis: 100%; } .label { display: none; }
}
body[data-production] header { padding: 8px 10px; }
body[data-production] header > div { flex: 1; min-width: 0; }
body[data-production] h1 { font-size: clamp(16px, 4.4vw, 22px); }
.back { flex: 0 0 44px; height: 44px; display: grid; place-items: center; border: 1px solid #c2a079; border-radius: 14px; text-decoration: none; color: #594339; }
#chapter { position: absolute; top: 8px; width: 100%; text-align: center; font-size: 11px; pointer-events: none; }
#flick-target { position: absolute; width: 52px; height: 52px; border: 1px dashed #a77a48; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
body[data-production] .controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
#motion { grid-column: span 2; }
.storage { display: flex; align-items: center; gap: 5px; min-height: 30px; padding-top: 4px; }
#save-status { flex: 1; font-size: 10px; }
#save-retry { flex: 0 0 auto; }
dialog { width: min(340px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 16px; border: 1px solid #c2a079; border-radius: 20px; background: #fff6e8; color: #594339; }
dialog::backdrop { background: #42312a88; }
dialog h2 { font-size: 20px; margin: 0 0 8px; }
dialog p { font-size: 13px; line-height: 1.4; margin: 8px 0; }
#pangolin-preview { display: block; width: 100%; height: 115px; background: #f1e2ca; border-radius: 14px; }
button[hidden], #flick-target[hidden] { display: none; }
#veil { gap: 6px; }
.back:focus-visible { outline: 2px solid #9f5787; }
@media (max-height: 450px) {
  body[data-production] { grid-template-columns: 210px minmax(0, 1fr); }
  body[data-production] header { gap: 5px; padding: 6px 8px; }
  body[data-production] header > div { flex-basis: 130px; }
  body[data-production] header small { display: none; }
  body[data-production] .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body[data-production] #message { font-size: 11px; margin-bottom: 5px; min-height: 32px; }
  body[data-production] footer { padding: 4px 8px; }
  #pangolin-preview { height: 65px; }
  dialog { padding: 12px; }
}
