:root {
  --bg: #ececec;
  --surface: #ffffff;
  --line: #e6e6e6;
  --line-soft: #f0f0f0;
  --text: #1a1a1a;
  --text-2: #7a7a7a;
  --text-3: #b3b3b3;
  --hover: #f5f5f5;
  --accent: #0d99ff;
  --accent-soft: #e5f4ff;
  --topbar-h: 44px;
  --panel-w: 232px;
  --radius: 6px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .06), 0 0 0 1px rgba(0, 0, 0, .04);
  --shadow-2: 0 8px 28px rgba(0, 0, 0, .10), 0 1px 3px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 12px/1.5 "Inter", ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

/* -------------------------------------------------------------- topbar --- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}

.brand {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -.015em;
}

.brand-dot { color: var(--accent); }

.brand-sub {
  color: var(--text-3);
  font-size: 12px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.spacer { flex: 1; }

.icon-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex: none;
}

.icon-btn:hover { background: var(--hover); }
.icon-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }

.toggle-text { display: none; }

/* ---------------------------------------------------------- panel head --- */

.panel-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
}

.close-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.close-btn:active { background: var(--hover); }
.close-btn svg { width: 14px; height: 14px; }

/* --------------------------------------------------------------- scrim --- */

.scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, .32);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

body:not(.panel-hidden) .scrim { opacity: 1; pointer-events: auto; }
@media (min-width: 761px) { .scrim { display: none !important; } }

.avatars { display: flex; }

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  margin-left: -7px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  flex: none;
}

.avatar:first-child { margin-left: 0; }
.avatar.more { background: #d9d9d9; color: var(--text-2); }

.online-label { color: var(--text-3); font-size: 11.5px; padding-left: 4px; }

/* --------------------------------------------------------------- panel --- */

.panel {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 30;
  transition: transform .18s cubic-bezier(.4, 0, .2, 1);
}

body.panel-hidden .panel { transform: translateX(-100%); }

.block {
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
}

.block-head .value { color: var(--text-3); font-weight: 400; }

/* --------------------------------------------------- segmented control --- */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  background: var(--hover);
  border-radius: 7px;
}

.seg {
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.seg:hover { color: var(--text); }

.seg[aria-checked="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-1);
}

.seg .dot { display: block; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------------------- palette --- */

.palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.swatch {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .09);
}

.swatch::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 6px;
  border: 1.5px solid transparent;
}

.swatch[aria-checked="true"]::after { border-color: var(--accent); }

.swatch.is-paper {
  background-image: linear-gradient(135deg, transparent 45%, #d92d20 45%, #d92d20 55%, transparent 55%);
  background-color: #f4f1ea;
}

/* ------------------------------------------------------------ controls --- */

.btn {
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: background .12s, border-color .12s;
}

.btn:hover { background: var(--hover); }
.btn[hidden] { display: none; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: #0b8ae8; border-color: #0b8ae8; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn .ico { width: 14px; height: 14px; }

.btn-row { display: flex; gap: 6px; }

.speeds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }

.speed {
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.speed:hover { background: var(--hover); }

.speed[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.scrub {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

.scrub::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}

.scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid #cfcfcf;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .16);
}

.scrub::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
.scrub::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 1px solid #cfcfcf;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .16);
}

.scrub:disabled { opacity: .5; cursor: default; }

.note { margin: 0; font-size: 11px; color: var(--text-2); }

.panel-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.support {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background .12s, border-color .12s;
}

.support svg { width: 15px; height: 15px; color: #b8860b; }

.support:hover {
  background: #fffbeb;
  border-color: #f5d76e;
}

.foot-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
}

.foot-row b { color: var(--text-2); font-weight: 500; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- stage --- */

.stage {
  position: fixed;
  inset: var(--topbar-h) 0 0 var(--panel-w);
  display: grid;
  place-items: center;
  padding: 20px;
  transition: inset .18s cubic-bezier(.4, 0, .2, 1);
}

body.panel-hidden .stage { inset: var(--topbar-h) 0 0 0; }

.frame-wrap { display: flex; flex-direction: column; gap: 6px; }

.frame-label {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: .01em;
  user-select: none;
}

body.is-playing .frame-label { color: var(--accent); }

.frame {
  position: relative;
  line-height: 0;
  background: #fff;
  border-radius: 2px;
  box-shadow: var(--shadow-2);
}

#canvas, .overlay {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  border-radius: 2px;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  image-rendering: auto;
}

body.is-playing #canvas { cursor: default; }
body:not(.is-playing) #canvas { cursor: crosshair; }

/* -------------------------------------------------------------- status --- */

.status {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 28, 30, .92);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 11.5px;
  z-index: 50;
  pointer-events: none;
  box-shadow: var(--shadow-2);
}

/* ------------------------------------------------------------- welcome --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 20, 22, .45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade .2s ease;
}

.modal-backdrop[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .28), 0 2px 8px rgba(0, 0, 0, .10);
  animation: rise .24s cubic-bezier(.2, .8, .3, 1);
}

.modal-mark { display: flex; gap: 4px; margin-bottom: 16px; }
.modal-mark span { width: 14px; height: 14px; border-radius: 3px; }

.modal h2 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.015em;
}

.modal p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}

.modal-close-line {
  color: var(--text) !important;
  font-weight: 500;
  margin-bottom: 20px !important;
}

.modal .btn { height: 36px; font-size: 12.5px; }

/* -------------------------------------------------------------- mobile --- */

@media (max-width: 760px) {
  .stage { inset: var(--topbar-h) 0 0 0; padding: 12px; }
  .brand-sub { display: none; }
  .panel-head { display: flex; }
  .panel {
    width: min(80vw, 288px);
    box-shadow: var(--shadow-2);
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
  .icon-btn {
    width: auto;
    height: 30px;
    gap: 6px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
  }
  .icon-btn[aria-expanded="true"] { border-color: transparent; }
  .toggle-text { display: inline; font-size: 12px; font-weight: 500; }
  .modal { padding: 22px; }
  .seg { height: 32px; }
  .btn { height: 34px; }
  .speed { height: 28px; }
  .palette { gap: 5px; }
  .scrub { height: 24px; }
  .scrub::-webkit-slider-thumb { width: 16px; height: 16px; margin-top: -6px; }
}
