* { box-sizing: border-box; }
:root { font-family: system-ui, sans-serif; color: #484356; background: #f8eee8; }
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: #847382; }
h1 { margin: 3px 0; font-size: clamp(17px, 4.7vw, 24px); font-weight: 650; }
#clock { border: 1px solid #ccadb9; 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: 10px; letter-spacing: .2em; pointer-events: none; color: #817785; }
#veil { position: absolute; inset: 0; background: #f8eee8e8; display: grid; place-content: center; text-align: center; }
#veil[hidden] { display: none; }
footer { padding: 8px 12px max(12px, env(safe-area-inset-bottom)); background: #fff7ef; border-top: 1px solid #e4d2d7; }
#message { margin: 0 0 8px; font-size: 13px; min-height: 32px; }
.controls { display: flex; align-items: center; gap: 8px; }
.controls span { flex: 1; font-size: 10px; line-height: 1.5; }
button { min-height: 44px; padding: 8px 10px; border: 1px solid #b999a6; border-radius: 14px; background: #fffaf4; color: #584353; font: inherit; font-size: 12px; cursor: pointer; }
button:focus-visible, #stage:focus-visible { outline: 2px solid #775b91; }
@media (max-width: 350px) { header { padding: 8px 10px; } footer { padding: 8px; } .controls { gap: 5px; } }
@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 #b999a6; border-radius: 14px; text-decoration: none; color: #584353; }
#chapter { position: absolute; top: 8px; text-align: center; width: 100%; font-size: 11px; color: #66596d; pointer-events: none; }
body[data-production] .controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
body[data-production] button { min-width: 44px; min-height: 44px; padding: 6px 8px; }
#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 #b999a6; border-radius: 20px; background: #fff7ef; color: #484356; }
dialog::backdrop { background: #39304788; }
dialog h2 { font-size: 20px; margin: 0 0 8px; }
dialog p { font-size: 13px; line-height: 1.4; margin: 8px 0; }
#scarf-preview { display: block; width: 100%; height: 115px; background: #eaddE8; border-radius: 14px; }
button[hidden] { display: none; }
#veil { gap: 6px; }
.back:focus-visible { outline: 2px solid #775b91; }
@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; }
  #scarf-preview { height: 72px; }
  dialog { padding: 12px; }
}
