/* Sprite Studio layout. Colours come from style.css tokens. */

:root {
  --code-bg: #fbfaff;
  --code-text: #1d1530;
  --code-gutter: #9c95ad;
  --tk-comment: #6f7f8f;
  --tk-string: #2f8a4f;
  --tk-number: #b4500a;
  --tk-keyword: #7b3fd1;
  --tk-pen: #1767b5;
  --mark-error: rgba(224, 69, 123, 0.18);
  --mark-linked: rgba(255, 122, 0, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root {
    --code-bg: #17141f;
    --code-text: #e6e1f2;
    --code-gutter: #6c6680;
    --tk-comment: #8a96a3;
    --tk-string: #8fd6a2;
    --tk-number: #ffb46b;
    --tk-keyword: #c29bff;
    --tk-pen: #7cc3ff;
    --mark-error: rgba(255, 99, 150, 0.22);
    --mark-linked: rgba(255, 150, 60, 0.22);
  }
}

body.studio {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.bar h1 {
  font-size: 18px;
  margin: 0 6px 0 0;
}

.file-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.name-pick {
  display: flex;
  align-items: center;
  gap: 6px;
}

.name-pick input {
  width: 11em;
  min-width: 0;
}

/* A long character name shrinks the picker rather than widening a phone's page. */
.file-pick select {
  min-width: 0;
  max-width: 100%;
}

.studio-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 12px 16px;
}

.pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- editor ---- */

.editor {
  flex: 1;
  min-height: 240px;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  font: 13px/20px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  tab-size: 2;
}

.editor .gutter {
  margin: 0;
  padding: 10px 8px 10px 10px;
  min-width: 3.2em;
  text-align: right;
  color: var(--code-gutter);
  user-select: none;
  font: inherit;
  border-right: 1px solid var(--border);
}

.editor .code {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.editor .hl,
.editor .input {
  margin: 0;
  padding: 10px 12px;
  font: inherit;
  white-space: pre;
  tab-size: inherit;
  letter-spacing: 0;
}

.editor .hl {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  color: var(--code-text);
  pointer-events: none;
}

.editor .marks {
  position: absolute;
  inset: 0 0 auto 0;
  pointer-events: none;
}

.editor .mark {
  position: absolute;
  left: 0;
  right: 0;
}

.editor .mark.error {
  background: var(--mark-error);
  box-shadow: inset 3px 0 0 #e0457b;
}

.editor .mark.linked {
  background: var(--mark-linked);
}

.editor .input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: var(--code-text);
  overflow: auto;
}

.editor .input::selection {
  background: rgba(123, 92, 255, 0.3);
  color: transparent;
}

.editor:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tk-comment {
  color: var(--tk-comment);
  font-style: italic;
}
.tk-string {
  color: var(--tk-string);
}
.tk-number {
  color: var(--tk-number);
}
.tk-keyword {
  color: var(--tk-keyword);
}
.tk-pen {
  color: var(--tk-pen);
  font-weight: 600;
}

/* The drawing checks, a moment after each edit: ready for the game, or what to fix. */
.checks {
  max-height: 30%;
  overflow: auto;
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.checks.good {
  color: var(--muted);
}

/* An edit's new check is coming: the last one fades a little. */
.checks.pending {
  opacity: 0.55;
}

.checks.bad {
  border-color: #e0b020;
  background: #fff6d6;
  color: #5c4500;
}

.checks p {
  margin: 0;
}

.checks ul {
  margin: 4px 0 0;
  padding-left: 18px;
  font: 12px/1.45 ui-monospace, monospace;
}

.problems {
  max-height: 30%;
  overflow: auto;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-text);
  font: 13px/1.45 ui-monospace, monospace;
  white-space: pre-wrap;
}

/* ---- view ---- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.toggles label,
.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#view {
  flex: 1;
  min-height: 260px;
  width: 100%;
  border-radius: 10px;
  background: var(--stage);
  cursor: crosshair;
}

/*
 * The picture takes the column's free height, so nothing under it may change
 * height as you use it: the readout is always 2 lines, whatever it says (a
 * click on a shape once made the picture jump under the pointer).
 */
.readout {
  margin: 0;
  height: calc(2 * 1.45em);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font: 12px/1.45 ui-monospace, monospace;
  white-space: pre-wrap;
}

/* The time line under the slider: room for 2 lines, so frame 9 → 10 or "plays once" never moves the picture. */
#tinfo {
  min-height: calc(2 * 1.45em);
}

.timeline {
  display: grid;
  gap: 6px;
}

/* "Animation settings": a short card of frames, fps, loop and t, with links into the reference. */
.anim-notes {
  margin-top: 6px;
}

.anim-notes summary {
  cursor: pointer;
  font-weight: 600;
}

.anim-table-wrap {
  overflow-x: auto;
}

.anim-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.anim-table th,
.anim-table td {
  padding: 4px 6px;
  border-top: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

/* ---- the first-open card ---- */

.welcome {
  width: min(640px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 18px 20px;
}

.welcome::backdrop {
  background: rgba(20, 15, 35, 0.55);
}

.welcome h2 {
  margin: 0 0 6px;
}

/* Three big choices: each a whole button, easy to hit on a tablet. */
.welcome-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.welcome-choice {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
  padding: 12px 14px;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.welcome-choice b {
  font-size: 17px;
  color: var(--accent);
}

.welcome-choice:hover,
.welcome-choice:focus-visible {
  background: var(--accent);
  color: var(--accent-text);
}

.welcome-choice:hover b,
.welcome-choice:focus-visible b {
  color: inherit;
}

.welcome-foot {
  justify-content: flex-end;
}

/* Play, the step buttons, the t slider and Snap wrap when the row is narrow. */
.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.transport input[type='range'] {
  flex: 1;
  min-width: 80px;
}

#play {
  min-width: 86px;
}

.timeline .info {
  margin: 0;
}

.watches {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 12px;
  margin: 0;
  font: 12px/1.4 ui-monospace, monospace;
}

.watches dt {
  color: var(--muted);
}

.watches dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  body.studio {
    height: auto;
  }
  .studio-main {
    grid-template-columns: minmax(0, 1fr);
  }
  /* One column (phones, tablets upright): the character comes first, then the blocks and the code. */
  .view-pane {
    order: -1;
  }
  /* One column: the code scrolls inside a box, as on a wide screen, so the picture is not pushed pages down. */
  .editor {
    flex: none;
    height: 60vh;
    min-height: 280px;
  }
}
