:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --ink: #18202b;
  --muted: #687484;
  --line: #dce3e8;
  --blue: #2563eb;
  --cyan: #06b6d4;
  --green: #16a34a;
  --coral: #ef5b45;
  --shadow: 0 18px 60px rgba(24, 32, 43, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(239, 91, 69, 0.09), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sketch-app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
  padding: 16px;
}

.app-topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: var(--radius);
  box-shadow: 0 10px 35px rgba(24, 32, 43, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 38%, #ffffff 38% 48%, transparent 48%),
    linear-gradient(135deg, #2563eb, #06b6d4 48%, #ef5b45);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5), 0 10px 22px rgba(37, 99, 235, 0.18);
}

.brand-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.brand-text strong {
  font-size: 18px;
  line-height: 1.1;
}

.brand-text span {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.recording-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.icon-button,
.tool-toggle,
.replay-button,
.record-button {
  position: relative;
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, color 140ms ease;
}

.icon-button:hover,
.tool-toggle:hover,
.replay-button:hover,
.record-button:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px #c8d2da, 0 8px 20px rgba(24, 32, 43, 0.08);
}

.icon-button:active,
.tool-toggle:active,
.replay-button:active,
.record-button:active {
  transform: translateY(0);
}

.icon-button:focus-visible,
.tool-toggle:focus-visible,
.replay-button:focus-visible,
.record-button:focus-visible,
.panel-button:focus-visible,
.mini-button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.28);
  outline-offset: 2px;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: -34px;
  z-index: 20;
  transform: translateX(-50%) translateY(-3px);
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(24, 32, 43, 0.92);
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.record-button {
  color: var(--coral);
  background: var(--panel);
}

.record-button .record-icon circle {
  fill: currentColor;
  stroke: none;
}

.record-button .stop-icon {
  display: none;
}

.is-recording .record-button {
  color: #fff;
  background: var(--coral);
  box-shadow: 0 12px 28px rgba(239, 91, 69, 0.24);
}

.is-recording .record-button .record-icon {
  display: none;
}

.is-recording .record-button .stop-icon {
  display: block;
}

.mic-button.is-muted {
  color: var(--muted);
  background: #eef3f6;
}

.recording-status {
  min-width: 82px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.record-dot {
  width: 8px;
  height: 8px;
  display: none;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 0 rgba(239, 91, 69, 0.32);
}

.is-recording .recording-status {
  color: var(--ink);
  background: #fff8f6;
}

.is-recording .record-dot {
  display: block;
  animation: recordPulse 1100ms ease-in-out infinite;
}

@keyframes recordPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 91, 69, 0.32);
  }

  50% {
    box-shadow: 0 0 0 7px rgba(239, 91, 69, 0);
  }
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 16px;
}

.tool-panel,
.stage-shell {
  min-width: 0;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.tool-panel {
  align-self: start;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.panel-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.compact-tools {
  grid-template-columns: repeat(2, 1fr);
}

.compact-tools .tool-toggle {
  width: 100%;
}

.tool-toggle.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.control-label output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.color-section {
  grid-template-columns: 1fr auto;
  align-items: start;
}

.color-section .control-label {
  grid-column: 1 / -1;
}

.color-input {
  width: 42px;
  height: 42px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 28px);
  gap: 7px;
  justify-content: end;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(24, 32, 43, 0.18), 0 5px 12px rgba(24, 32, 43, 0.08);
  cursor: pointer;
}

.swatch.is-active {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.34), 0 5px 12px rgba(24, 32, 43, 0.08);
}

.panel-button,
.mini-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.panel-button:hover,
.mini-button:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px #c8d2da, 0 8px 18px rgba(24, 32, 43, 0.08);
}

.panel-button svg {
  width: 18px;
  height: 18px;
}

.stencil-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-button {
  min-height: 34px;
  font-size: 12px;
}

.mini-button.danger {
  color: var(--coral);
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.stage-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 12px;
}

.stage-info {
  min-height: 34px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.canvas-stage {
  position: relative;
  width: 100%;
  max-width: 1280px;
  aspect-ratio: 16 / 9;
  align-self: center;
  justify-self: center;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(24, 32, 43, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(24, 32, 43, 0.045) 1px, transparent 1px),
    #ffffff;
  background-size: 32px 32px;
  box-shadow:
    inset 0 0 0 1px rgba(24, 32, 43, 0.1),
    0 18px 60px rgba(24, 32, 43, 0.16);
  touch-action: none;
}

.stencil-layer,
.draw-canvas,
.cursor-preview,
.drop-target {
  position: absolute;
}

.stencil-layer {
  inset: 0;
  z-index: 1;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0;
  pointer-events: none;
}

.draw-canvas {
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.cursor-preview {
  z-index: 3;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(24, 32, 43, 0.65);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: multiply;
}

.cursor-preview.is-visible {
  opacity: 1;
}

.drop-target {
  inset: 12px;
  z-index: 5;
  display: none;
  place-items: center;
  border: 2px dashed rgba(37, 99, 235, 0.5);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--blue);
  font-weight: 800;
  text-transform: uppercase;
}

.canvas-stage.is-dragging .drop-target {
  display: grid;
}

.replay-bar {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 82px;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
}

.replay-button {
  color: #fff;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  box-shadow: 0 12px 28px rgba(6, 182, 212, 0.2);
}

.replay-button .pause-icon,
.is-replaying .replay-button .play-icon {
  display: none;
}

.is-replaying .replay-button .pause-icon {
  display: block;
}

#replayRange {
  accent-color: var(--coral);
}

#replaySpeed {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  background: #fff;
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  transform: translateX(-50%) translateY(16px);
  max-width: min(90vw, 460px);
  padding: 11px 14px;
  border-radius: 8px;
  background: rgba(24, 32, 43, 0.92);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .sketch-app {
    padding: 10px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .tool-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-self: auto;
  }

  .compact-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-shell {
    min-height: 55vh;
  }
}

@media (max-width: 640px) {
  .app-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .recording-strip {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .tool-panel {
    grid-template-columns: 1fr;
  }

  .canvas-stage {
    aspect-ratio: 4 / 3;
  }

  .replay-bar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  #replaySpeed {
    grid-column: 1 / -1;
  }
}
