:root {
  --accent: #e8336b;
  --lime: #c6e636;
  --ink: #1d1d1f;
  --muted: #6b6b75;
  --line: #e3e3e8;
  --bg: #f6f6f8;
  --frame: 150px; /* base frame width, multiplied by --scale */
  --scale: 1;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, select, input, textarea { font: inherit; }
button, .filebtn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer;
  font-size: 13px; white-space: nowrap; display: inline-block;
}
button:hover, .filebtn:hover { border-color: #bbb; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: #b00020; }
button:disabled { opacity: .45; cursor: default; }

#app { display: flex; height: 100vh; }

/* Library */
#library { width: 230px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { font-weight: 800; font-size: 18px; padding: 16px 14px 10px; }
.lib-actions, .lib-footer { display: flex; gap: 6px; padding: 0 14px 10px; }
.lib-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
#choreo-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
#choreo-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
#choreo-list li:hover { background: var(--bg); }
#choreo-list li.active { background: #fde7ee; }
#choreo-list .t { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#choreo-list .m { font-size: 11px; color: var(--muted); }

/* Editor */
#editor { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#empty-state { margin: auto; text-align: center; color: var(--muted); }
#editor-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); }
#title { font-size: 20px; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; min-width: 220px; flex: 1; }
#title:hover, #title:focus { border-color: var(--line); outline: none; }
.group { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.group label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.group select { padding: 5px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
#scale { width: 110px; }
#scale-label { width: 38px; color: var(--muted); }

.workspace { display: flex; flex: 1; min-height: 0; }
#timeline-wrap { flex: 1; overflow: auto; padding: 14px 16px 40px; }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.cursor-chip { color: var(--accent); font-weight: 800; }

/* Timeline */
#timeline { display: flex; flex-wrap: wrap; align-items: stretch; }
.cell { display: flex; align-items: stretch; }
.slot {
  width: 16px; align-self: stretch; min-height: calc(var(--frame) * var(--scale)); display: flex; justify-content: center; cursor: pointer;
  position: relative;
}
.slot::before { content: ""; width: 3px; border-radius: 3px; background: transparent; transition: background .1s; }
.slot:hover::before { background: #f4b6c8; }
.slot.active::before { background: var(--accent); }
.slot.drop::before { background: var(--lime); width: 6px; }
.slot.end { flex: 1; min-width: 60px; justify-content: flex-start; padding-left: 6px; }
.slot.end .empty-msg { position: absolute; left: 24px; top: 30%; color: var(--muted); font-size: 14px; white-space: nowrap; }

.frame {
  width: calc(var(--frame) * var(--scale)); background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; position: relative; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.frame.dragging { opacity: .35; }
.frame img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; pointer-events: none; user-select: none; }
.frame .num {
  position: absolute; top: 4px; left: 4px; background: var(--accent); color: #fff; font-weight: 700; font-size: 11px;
  border-radius: 10px; min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 5px;
}
.frame .tools { position: absolute; top: 3px; right: 3px; display: none; gap: 2px; }
.frame:hover .tools, .frame:focus-within .tools { display: flex; }
.frame .tools button { padding: 1px 6px; font-size: 12px; border-radius: 6px; }
.frame textarea {
  width: 100%; resize: vertical; border: 1px dashed var(--line); border-radius: 6px; padding: 4px; margin-top: 4px;
  font-size: calc(12px * max(var(--scale), .85)); min-height: 2.4em; color: var(--ink); background: #fffdf3;
}
.frame textarea:placeholder-shown { background: transparent; }
.frame[draggable="true"] { cursor: grab; }

/* Palette */
#palette { width: 300px; border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; }
#search { margin: 12px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; }
#palette-list { overflow-y: auto; padding: 0 12px 20px; }
.cat { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 6px; }
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.move {
  border: 1px solid var(--line); border-radius: 8px; padding: 3px; background: #fff; cursor: pointer;
}
.move:hover { border-color: var(--accent); box-shadow: 0 0 0 2px #fde7ee; }
.move img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; pointer-events: none; }

/* Print */
#print-area { display: none; }
@media print {
  body { background: #fff; }
  #app { display: none !important; }
  #print-area { display: block; }
  .p-title { font-size: 18pt; font-weight: 800; margin: 0 0 2pt; }
  .p-sub { font-size: 9pt; color: #555; margin-bottom: 10pt; }
  .p-grid { display: flex; flex-wrap: wrap; gap: 8pt; }
  .p-frame { width: calc(1.5in * var(--scale)); break-inside: avoid; page-break-inside: avoid; border: 0.75pt solid #ccc; border-radius: 6pt; padding: 3pt; position: relative; }
  .p-frame img { width: 100%; display: block; }
  .p-num { position: absolute; top: 2pt; left: 2pt; font-size: 8pt; font-weight: 700; background: #e8336b; color: #fff; border-radius: 6pt; padding: 0 4pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-note { font-size: calc(8pt * max(var(--scale), .85)); margin-top: 2pt; white-space: pre-wrap; word-wrap: break-word; }
}

/* Narrow screens / tablets */
@media screen and (max-width: 900px) {
  #app { flex-direction: column; height: auto; min-height: 100vh; }
  #library { width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  #choreo-list { max-height: 140px; }
  .lib-footer { margin-top: 0; }
  #editor-body { height: auto; }
  .workspace { flex-direction: column-reverse; }
  #palette { width: auto; border-left: 0; border-bottom: 1px solid var(--line); }
  #palette-list { max-height: 260px; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
  #title { min-width: 0; flex: 1 1 100%; }
}

/* ---------- Account (account.js): the zosha.net account, as on the Language Quiz ---------- */
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 8px; }
.brand-row .brand { padding: 0; font-size: 17px; }
#account { position: relative; flex: none; }
#save-status { margin: 0 14px 10px; padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; color: var(--muted); background: var(--bg); }
#save-status.warn { background: #fff6df; color: #6b4e00; border: 1px solid #f1d79a; }
#save-status.error { background: #fdecee; color: #8a1023; border: 1px solid #f3b8c2; }
#save-status .z-link { font-size: 12px; padding: 0; }

.z-primary, .z-ghost, .z-danger { border-radius: 9px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
.z-primary { background: var(--accent); border: 1px solid var(--accent); color: #fff; }
.z-primary:hover:not(:disabled) { filter: brightness(.93); border-color: var(--accent); }
.z-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.z-ghost:hover { border-color: var(--accent); }
.z-danger { background: #b00020; border: 1px solid #b00020; color: #fff; }
.z-danger:hover:not(:disabled) { background: #900019; border-color: #900019; }
.z-small { padding: 5px 12px; font-size: 13px; }
.z-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 4px 0; font-weight: 600; }
.z-link:hover { text-decoration: underline; border: none; }

.z-account-button { display: flex; align-items: center; gap: 6px; background: none; border: 1px solid transparent; border-radius: 100px; padding: 3px 8px 3px 3px; }
.z-account-button:hover, .z-account-button[aria-expanded="true"] { border-color: var(--line); background: var(--bg); }
.z-avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--accent); color: #fff; }
.z-account-name { max-width: 80px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.z-account-menu { position: absolute; left: 0; top: calc(100% + 6px); min-width: 210px; padding: 6px; border-radius: 12px; background: #fff; border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(0,0,0,.14); z-index: 20; }
.z-account-menu[hidden] { display: none; }
.z-account-who { margin: 6px 10px 8px; font-size: 13px; color: var(--muted); }
.z-account-who b { color: var(--ink); }
.z-account-menu button { display: block; width: 100%; text-align: left; background: none; border: none; border-radius: 8px; padding: 9px 10px; font-size: 14px; }
.z-account-menu button:hover { background: var(--bg); }

.z-overlay { position: fixed; inset: 0; background: rgba(29,29,31,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.z-dialog { width: 100%; max-width: 380px; max-height: calc(100vh - 32px); overflow-y: auto; background: #fff; border-radius: 16px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.z-dialog h2 { margin: 0 0 8px; font-size: 21px; }
.z-dialog h3 { margin: 18px 0 6px; font-size: 16px; }
.z-dialog p { font-size: 14px; line-height: 1.5; }
.z-dialog a { color: var(--accent); }
.z-privacy { max-width: 480px; }
.z-muted { color: var(--muted); font-size: 13px !important; margin: 0 0 16px; }
.z-center { text-align: center; margin: 10px 0 0; }
.z-error { background: #fdecee; border: 1px solid #e58a99; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.z-error[hidden] { display: none; }
.z-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.z-field input { font-size: 16px; padding: 10px 12px; border-radius: 9px; border: 1px solid #cfcfd6; color: var(--ink); }
.z-field input:focus { outline: none; border-color: var(--accent); }
.z-code-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; }
.z-forgot { margin-top: -4px; }
.z-actions { display: flex; gap: 10px; justify-content: flex-end; margin: 18px 0 6px; }
.z-recovery-code { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px dashed #cfcfd6; }
.z-recovery-code code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 16px; letter-spacing: .02em; }
.z-toggle { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }
.z-deleted { color: #2d6a2d; font-weight: 600; }
.z-deleted[hidden] { display: none; }
@media print { .z-overlay { display: none !important; } }
