* { box-sizing: border-box; }
:root { font-family: system-ui, sans-serif; color: #473b48; background: #f5efe6; }
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: 14px 20px 8px; gap: 12px; }
small { font-size: 10px; letter-spacing: .18em; color: #806b60; }
h1 { margin: 3px 0; font-size: clamp(19px, 5vw, 26px); font-weight: 650; }
#clock { border: 1px solid #d2bca5; border-radius: 50%; min-width: 48px; height: 48px; 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: #887967; }
#veil { position: absolute; inset: 0; background: #f5efe6df; display: grid; place-content: center; text-align: center; }
#veil[hidden] { display: none; }
footer { padding: 8px 16px max(12px, env(safe-area-inset-bottom)); background: #fffaf1; border-top: 1px solid #e5d8c9; }
#message { margin: 0 0 10px; 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; color: #796d65; }
button { min-height: 44px; padding: 8px 12px; border: 1px solid #b99a79; border-radius: 14px; background: #fff9ec; color: #59422d; font: inherit; font-size: 12px; cursor: pointer; }
button:focus-visible, #stage:focus-visible { outline: 2px solid #8e592b; }
@media (max-width: 350px) { header { padding: 8px 12px; } footer { padding: 8px 10px; } .controls { gap: 5px; } button { padding: 8px; } }
@media (max-height: 450px) { header { position: absolute; z-index: 1; padding: 10px 16px; pointer-events: none; width: 100%; } body { grid-template-rows: minmax(0, 1fr) auto; } h1 { font-size: 18px; } header small, .label { display: none; } #clock { height: 40px; min-width: 40px; } footer { padding: 5px 16px; } #message { min-height: 0; margin-bottom: 3px; font-size: 11px; } .controls span br { display: none; } }

/* Production controls retain a clear, unobstructed stage on small phones. */
body[data-production] header { gap: 8px; padding: 10px 12px; }
body[data-production] header > div { flex: 1; min-width: 0; }
body[data-production] h1 { font-size: clamp(17px, 4.8vw, 23px); }
.back { flex: 0 0 44px; min-height: 44px; display: grid; place-items: center; color: #59422d; text-decoration: none; border-radius: 12px; border: 1px solid #b99a79; }
#chapter { position: absolute; top: 7px; width: 100%; text-align: center; font-size: 11px; color: #766276; 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; }
body[data-production] #message { min-height: 48px; margin-bottom: 5px; }
#sound { grid-column: span 1; }
#motion { grid-column: span 2; }
#save-status { display: block; font-size: 10px; min-height: 26px; padding-top: 5px; color: #766276; }
dialog { color: #473b48; background: #fffaf1; border: 1px solid #b99a79; border-radius: 20px; width: min(340px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 18px; }
dialog::backdrop { background: #33263588; }
dialog h2 { font-size: 20px; margin: 0 0 10px; }
dialog p { font-size: 13px; line-height: 1.5; }
#flock-preview { width: 100%; height: 110px; background: #eee7f0; border-radius: 12px; }
@media (max-height: 450px) {
  body[data-production] { grid-template-columns: 196px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  body[data-production] header { position: static; width: auto; pointer-events: auto; flex-wrap: wrap; padding: 6px 8px; }
  body[data-production] header > div { flex-basis: 110px; }
  body[data-production] #clock { min-height: 30px; height: 30px; min-width: 44px; border-radius: 10px; }
  body[data-production] #stage { grid-column: 2; grid-row: 1 / 3; }
  body[data-production] footer { grid-column: 1; grid-row: 2; padding: 4px 8px; }
  body[data-production] #message { min-height: 54px; font-size: 11px; }
  body[data-production] .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body[data-production] #motion { grid-column: span 2; }
  #flock-preview { height: 65px; }
  dialog { padding: 14px; }
}
